ApplicationLifecycleServiceImpl implements ApplicationLifecycleService { @Override public LifecycleEntity saveInstanceLogLifecycle(final String instanceId, final DateTime instanceBootTime, final String userdataPath, final String region, final String logData, final String accountId) { final Optional<TaupageYaml> taupageYaml = Optional.ofNullable(logData) .map(base64Decoder::decode) .map(String::new) .map(TaupageYamlUtil::parseTaupageYaml); final Optional<ApplicationEntity> application = taupageYaml .map(TaupageYaml::getApplicationId) .map(ApplicationEntity::new); final Optional<VersionEntity> version = taupageYaml .map(TaupageYaml::getApplicationVersion) .map(VersionEntity::new); if (application.isPresent() && version.isPresent()) { final LifecycleEntity lifecycleEntity = new LifecycleEntity(); lifecycleEntity.setInstanceBootTime(instanceBootTime); lifecycleEntity.setInstanceId(instanceId); lifecycleEntity.setAccountId(accountId); lifecycleEntity.setRegion(region); lifecycleEntity.setUserdataPath(userdataPath); return self.saveLifecycle(application.get(), version.get(), lifecycleEntity); } else { log.warn("Empty or invalid taupage yaml."); return null; } }  @Override @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 100, maxDelay = 500), include = {ObjectOptimisticLockingFailureException.class, OptimisticLockException.class, DataIntegrityViolationException.class}) @Transactional(REQUIRES_NEW) LifecycleEntity saveLifecycle(final ApplicationEntity applicationEntity, final VersionEntity versionEntity,
            final LifecycleEntity lifecycleToSave); @Override LifecycleEntity saveInstanceLogLifecycle(final String instanceId, final DateTime instanceBootTime,
            final String userdataPath, final String region, final String logData, final String accountId); @Override ApplicationEntity findAppByInstanceIds(final String accountId, final String region, final Collection<String> instanceIds); @Override Page<LifecycleEntity> findByApplicationNameAndVersion(final String name, final String version, final Pageable pageable);  }
@Test public void testSaveInstanceLogsMissingAppId() throws Exception { final String userdata = encodeToBase64( "#taupage-ami-config\n" + "application_version: '" + versionId + "'\n" + "environment:\n" + " xx: xx"); final LifecycleEntity result = applicationLifecycleServiceImpl.saveInstanceLogLifecycle("i1", now(), "path/to/the/logs", REGION, userdata, ACCOUNT_ID); assertThat(result).isNull(); }
@Test public void testSaveInstanceLogsMissingAppVersion() throws Exception { final String userdata = encodeToBase64( "#taupage-ami-config\n" + "application_id: '" + applicationId + "'\n" + "environment:\n" + " xx: xx"); final LifecycleEntity result = applicationLifecycleServiceImpl.saveInstanceLogLifecycle("i1", now(), "path/to/the/logs", REGION, userdata, ACCOUNT_ID); assertThat(result).isNull(); }