@Override public void unregister(ApplicationEntity appEntity) { if (environment == null) { LOG.warn("Environment is null, can not unregister"); return; } this.environment.healthChecks().unregister(appEntity.getAppId()); synchronized (lock) { appHealthChecks.remove(appEntity.getAppId()); } LOG.info("Successfully unregister health check for {}", appEntity.getAppId()); }
@Override public ApplicationEntity getByUUIDOrAppId(String uuid, String appId) { if (uuid == null && appId == null) { throw new IllegalArgumentException("uuid and appId are both null"); } else if (uuid != null) { return getByUUID(uuid); } else { Optional<ApplicationEntity> applicationEntity = applicationEntityMap.values().stream().filter((app) -> appId.equals(app.getAppId())).findAny(); if (applicationEntity.isPresent()) { return applicationEntity.get(); } else { throw new IllegalArgumentException("Application with appId: " + appId + " not found"); } } }
private void updateTopologyMetadata() { LOG.info("Update topology metadata {}", this.applicationEntity.getAppId()); OpResult result = metadataDao.addTopology(createTopologyMeta(this.applicationEntity)); if (result.code == OpResult.FAILURE) { LOG.error(result.message); throw new IllegalStateException(result.message); } try { coordinatorResource.build(); } catch (Exception e) { LOG.error(e.getMessage(), e); } }
private void removeTopologyMetadata() { LOG.info("Remove topology metadata {}", this.applicationEntity.getAppId()); OpResult result = metadataDao.removeTopology(createTopologyMeta(this.applicationEntity).getName()); if (result.code == OpResult.FAILURE) { LOG.error(result.message); throw new IllegalStateException(result.message); } }
@Override public ApplicationEntity delete(ApplicationEntity applicationEntity) { ApplicationEntity entity = getByUUIDOrAppId(applicationEntity.getUuid(), applicationEntity.getAppId()); return applicationEntityMap.remove(entity.getUuid()); }
@Override public void register(ApplicationEntity appEntity) { if (environment == null) { LOG.warn("Environment is null, can not register"); return; } ApplicationProvider<?> appProvider = applicationProviderService.getApplicationProviderByType(appEntity.getDescriptor().getType()); Optional<HealthCheck> applicationHealthCheck = appProvider.getManagedHealthCheck( ConfigFactory.parseMap(appEntity.getContext()) .withFallback(config) .withFallback(ConfigFactory.parseMap(appEntity.getConfiguration())) ); if (!applicationHealthCheck.isPresent()) { LOG.warn("Application {} does not implement HealthCheck", appEntity.getAppId()); return; } this.environment.healthChecks().register(appEntity.getAppId(), applicationHealthCheck.get()); currentInjector.injectMembers(applicationHealthCheck.get()); synchronized (lock) { if (!appHealthChecks.containsKey(appEntity.getAppId())) { appHealthChecks.put(appEntity.getAppId(), applicationHealthCheck); LOG.info("Successfully register health check for {}", appEntity.getAppId()); } } }
private Topology createTopologyMeta(ApplicationEntity applicationEntity) { return UnitTopologyRunner.buildTopologyMetadata(applicationEntity.getAppId(),ConfigFactory.parseMap(applicationEntity.getConfiguration())); } }
@Override public ApplicationEntity create(ApplicationEntity entity) { entity.ensureDefault(); if (getBySiteIdAndAppType(entity.getSite().getSiteId(), entity.getDescriptor().getType()) != null) { throw new IllegalArgumentException("Duplicated appId: " + entity.getAppId()); } List<ApplicationEntity> entities = new ArrayList<>(1); entities.add(entity); try { queryService.insert(insertSql, entities, new ApplicationEntityToRelation()); } catch (SQLException e) { LOGGER.error("Error to insert ApplicationEntity: {}", entity, e); } return entity; } }
@Override public ApplicationEntity create(ApplicationEntity entity) { entity.ensureDefault(); if (getBySiteIdAndAppType(entity.getSite().getSiteId(), entity.getDescriptor().getType()) != null) { throw new IllegalArgumentException("Duplicated appId: " + entity.getAppId()); } applicationEntityMap.put(entity.getUuid(), entity); return entity; }
@Override public ApplicationEntity delete(ApplicationEntity applicationEntity) { ApplicationEntity entity = getByUUIDOrAppId(applicationEntity.getUuid(), applicationEntity.getAppId()); entity = new ApplicationEntity(null, null, null, null, entity.getUuid(), ""); try { queryService.update(deleteSqlByUUID, entity, new ApplicationEntityToRelation()); } catch (SQLException e) { LOGGER.error("Error to delete ApplicationEntity: {}", entity, e); } return entity; }
public ApplicationExecutionConfig(ApplicationEntity metadata) { this.siteId = metadata.getSite().getSiteId(); this.mode = metadata.getMode().name(); this.appId = metadata.getAppId(); this.jarPath = metadata.getJarPath(); }
LOG.info("Application {} status changed from {} to {}", applicationEntity.getAppId(), preStatus, currentStatus);
return applicationEntityService.create(appEntity); } else { throw new ApplicationWrongStatusException("App: " + appEntity.getAppId() + " status is " + currentStatus + " start operation is not allowed"); throw e; } catch (Exception e) { LOGGER.error("Failed to start app " + appEntity.getAppId(), e); throw e; } catch (Throwable throwable) {
return applicationEntityService.create(applicationEntity); } else { throw new ApplicationWrongStatusException("App: " + applicationEntity.getAppId() + " status is " + currentStatus + ", stop operation is not allowed."); throw e; } catch (RuntimeException e) { LOGGER.error("Failed to stop app " + applicationEntity.getAppId(), e); throw e; } catch (Throwable throwable) {
updateSql += " where uuid = ?"; if (StringUtils.isNotBlank(entity.getAppId())) { updateSql += " and appid = ?";
@Override public ApplicationEntity uninstall(ApplicationOperations.UninstallOperation operation) throws ApplicationWrongStatusException { ApplicationEntity appEntity = applicationEntityService.getByUUIDOrAppId(operation.getUuid(), operation.getAppId()); ApplicationProvider<?> appProvider = applicationProviderService.getApplicationProviderByType(appEntity.getDescriptor().getType()); ApplicationAction appAction = new ApplicationAction(appProvider.getApplication(), appEntity, config, alertMetadataService); ApplicationEntity.Status currentStatus = appEntity.getStatus(); try { if (currentStatus == ApplicationEntity.Status.INITIALIZED || currentStatus == ApplicationEntity.Status.STOPPED) { // AfterUninstall Callback appAction.doUninstall(); appProvider.getApplicationListener().ifPresent((listener) -> { currentInjector.injectMembers(listener); listener.init(appEntity); listener.afterUninstall(); }); applicationHealthCheckService.unregister(appEntity); return applicationEntityService.delete(appEntity); } else { throw new ApplicationWrongStatusException("App: " + appEntity.getAppId() + " status is " + currentStatus + ", uninstall operation is not allowed"); } } catch (Throwable throwable) { LOGGER.error(throwable.getMessage(), throwable); throw throwable; } }
private void fillApplicationDesc(List<ApplicationEntity> entities) { for (ApplicationEntity entity : entities) { entity.setDescriptor(applicationProviderService.getApplicationDescByType(entity.getDescriptor().getType())); if (entity.getDescriptor().getStreams() == null) { continue; } List<StreamDesc> streamDescToInstall = entity.getDescriptor().getStreams().stream().map((streamDefinition -> { StreamDefinition copied = streamDefinition.copy(); copied.setSiteId(entity.getSite().getSiteId()); copied.setStreamId(StreamIdConversions.formatSiteStreamId(entity.getSite().getSiteId(), copied.getStreamId())); Config effectiveConfig = ConfigFactory.parseMap(new HashMap<>(entity.getConfiguration())) .withFallback(config).withFallback(ConfigFactory.parseMap(entity.getContext())); ExecutionRuntime runtime = ExecutionRuntimeManager.getInstance().getRuntime( applicationProviderService.getApplicationProviderByType(entity.getDescriptor().getType()).getApplication().getEnvironmentType(), config); StreamSinkConfig streamSinkConfig = runtime.environment() .stream().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), effectiveConfig); StreamDesc streamDesc = new StreamDesc(); streamDesc.setSchema(copied); streamDesc.setSinkConfig(streamSinkConfig); streamDesc.setStreamId(copied.getStreamId()); streamDesc.getSchema().setDataSource(entity.getAppId()); return streamDesc; })).collect(Collectors.toList()); entity.setStreams(streamDescToInstall); } }
applicationEntity.getContext().put("appId", applicationEntity.getAppId());
sd.setStreamSource(metadata.getAppId()); alertMetadataService.createStream(streamDesc.getSchema());