@Override public String toString() { return String.format("ApplicationDesc [type=%s, name=%s, version=%s, appClass=%s, viewPath=%s, jarpath=%s, providerClass=%s, configuration= %s properties, description=%s", getType(), getName(), getVersion(), getAppClass(), getViewPath(), getJarPath(), getProviderClass(), getConfiguration() == null ? 0 : getConfiguration().size(), getDescription()); }
@Override public ApplicationDesc getApplicationDesc() { String descriptorPath = generateXMLDescriptorPath(); ApplicationDesc applicationDesc = new ApplicationDesc(); applicationDesc.setProviderClass(this.providerClass); ApplicationProviderDescConfig descWrapperConfig = ApplicationProviderDescConfig.loadFromXML(this.getClass(), descriptorPath); applicationDesc.setType(descWrapperConfig.getType()); applicationDesc.setVersion(descWrapperConfig.getVersion()); applicationDesc.setName(descWrapperConfig.getName()); applicationDesc.setDocs(descWrapperConfig.getDocs()); applicationDesc.setJarPath(DynamicJarPathFinder.findPath(applicationClass)); if (applicationClass != null) { applicationDesc.setAppClass(applicationClass); if (!Application.class.isAssignableFrom(applicationDesc.getAppClass())) { throw new IllegalStateException(applicationDesc.getAppClass() + " is not sub-class of " + Application.class.getCanonicalName()); } } applicationDesc.setDependencies(descWrapperConfig.getDependencies()); applicationDesc.setViewPath(descWrapperConfig.getViewPath()); applicationDesc.setConfiguration(descWrapperConfig.getConfiguration()); applicationDesc.setStreams(descWrapperConfig.getStreams()); return applicationDesc; } }
@Override public String toString() { return String.format( "%s[name=%s, type=%s, version=%s, viewPath=%s, appClass=%s, configuration= %s properties]", getClass().getSimpleName(), applicationDesc.getName(), applicationDesc.getType(), applicationDesc.getVersion(), applicationDesc.getViewPath(), applicationDesc.getAppClass(), applicationDesc.getConfiguration() == null ? 0 : applicationDesc.getConfiguration().size() ); }
public ApplicationEntity(String siteId, String appType) { this.site = new SiteEntity("", siteId); ApplicationDesc applicationDesc = new ApplicationDesc(); applicationDesc.setType(appType); this.descriptor = applicationDesc; this.mode = null; this.status = null; }
protected void registerProvider(ApplicationProvider provider) { if (providers.containsKey(provider.getApplicationDesc().getType())) { throw new RuntimeException("Duplicated APPLICATION_TYPE: " + provider.getApplicationDesc().getType() + ", was already registered by provider: " + providers.get(provider.getApplicationDesc().getType())); } providers.put(provider.getApplicationDesc().getType(), provider); LOG.info("Initialized application provider: {}", provider); }
LOG.debug("Validating {}", applicationDesc.getType()); Preconditions.checkNotNull(applicationDesc.getType(), "type is null in " + applicationDesc); Preconditions.checkNotNull(applicationDesc.getVersion(), "version is null in " + applicationDesc); Preconditions.checkNotNull(applicationDesc.getName(), "name is null in " + applicationDesc); if (applicationDesc.getViewPath() != null) { if (viewPathAppDesc.containsKey(applicationDesc.getViewPath())) { throw new IllegalStateException("Duplicated view " + applicationDesc.getViewPath() + " defined in " + viewPathAppDesc.get(applicationDesc.getViewPath()).getType() + " and " + applicationDesc.getType()); } else { viewPathAppDesc.put(applicationDesc.getViewPath(), applicationDesc); LOG.debug("Validating dependency of {}", applicationDesc.getType()); List<ApplicationDependency> dependencyList = applicationDesc.getDependencies(); if (dependencyList != null) { for (ApplicationDependency dependency : dependencyList) { ApplicationDesc dependencyDesc = getApplicationDescByType(dependency.getType()); if (dependencyDesc != null && dependency.getVersion() != null) { if (dependencyDesc.getVersion().equals(dependency.getVersion())) { LOG.debug("Loaded dependency {} -> {}", applicationDesc.getType(), dependency); } else { LOG.warn("Loaded dependency {} -> {}, but the version was mismatched, expected: {}, actual: {}", applicationDesc.getType(), dependency, dependency.getVersion(), applicationDesc.getVersion()); dependency.setVersion(dependencyDesc.getVersion()); LOG.warn("Unable to load dependency {} -> {}", applicationDesc.getType(), dependency, ex);
private void loadProviderFromClassLoader(ClassLoader jarFileClassLoader, Function<ApplicationProvider, String> jarFileSupplier) { ServiceLoader<ApplicationProvider> serviceLoader = ServiceLoader.load(ApplicationProvider.class); try { for (ApplicationProvider applicationProvider : serviceLoader) { ApplicationProviderConfig providerConfig = new ApplicationProviderConfig(); providerConfig.setClassName(applicationProvider.getClass().getCanonicalName()); providerConfig.setJarPath(jarFileSupplier.apply(applicationProvider)); applicationProvider.getApplicationDesc().setExecutable(applicationProvider.getApplication().isExecutable()); registerProvider(applicationProvider); LOG.warn("Loaded {}:{} ({}) from {}", applicationProvider.getApplicationDesc().getType(), applicationProvider.getApplicationDesc().getVersion(), applicationProvider.getApplicationDesc().getName(), providerConfig.getJarPath() ); } } catch (Throwable ex) { LOG.error("Failed to register application provider", ex); throw new IllegalStateException(ex); } } }
applicationEntity.setSite(siteEntity); applicationEntity.setMode(operation.getMode()); applicationEntity.setJarPath(operation.getJarPath() == null ? appDesc.getJarPath() : operation.getJarPath()); applicationEntity.ensureDefault(); if (applicationDesc.getConfiguration() != null) { List<Property> propertyList = provider.getApplicationDesc().getConfiguration().getProperties(); for (Property p : propertyList) { appConfig.put(p.getName(), p.getValue()); ApplicationProvider<?> applicationProvider = applicationProviderService.getApplicationProviderByType(applicationEntity.getDescriptor().getType());
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); } }
private void validateDependingApplicationInstalled(ApplicationEntity applicationEntity) { if (applicationEntity.getDescriptor().getDependencies() != null) { for (ApplicationDependency dependency : applicationEntity.getDescriptor().getDependencies()) { if (dependency.isRequired() && applicationEntityService.getBySiteIdAndAppType(applicationEntity.getSite().getSiteId(), dependency.getType()) == null) { throw new IllegalStateException("Required dependency " + dependency.toString() + " of " + applicationEntity.getDescriptor().getType() + " was not installed"); } } } }
public void setType(String type) { applicationDesc.setType(type); }
private void processStreams() { if (metadata.getDescriptor().getStreams() == null) { return; List<StreamDesc> streamDescToInstall = metadata.getDescriptor().getStreams().stream().map((streamDefinition -> { StreamDefinition copied = streamDefinition.copy(); copied.setSiteId(metadata.getSite().getSiteId());
@Override public String toString() { return String.format("Application[appId=%s,siteId=%s,UUID=%s]", appId, descriptor.getType(), this.getUuid()); }
@Override public ApplicationEntity apply(ResultSet resultSet) throws SQLException { ApplicationDesc applicationDesc = new ApplicationDesc(); String appType = resultSet.getString(4); applicationDesc.setType(appType); SiteEntity siteEntity = new SiteEntity(); siteEntity.setUuid(resultSet.getString(12)); siteEntity.setSiteId(resultSet.getString(13)); siteEntity.setSiteName(resultSet.getString(14)); siteEntity.setDescription(resultSet.getString(15)); siteEntity.setCreatedTime(resultSet.getLong(16)); siteEntity.setModifiedTime(resultSet.getLong(17)); ApplicationEntity resultEntity = new ApplicationEntity(); resultEntity.setUuid(resultSet.getString(1)); resultEntity.setAppId(resultSet.getString(2)); resultEntity.setSite(siteEntity); resultEntity.setDescriptor(applicationDesc); resultEntity.setMode(ApplicationEntity.Mode.valueOf(resultSet.getString(5))); resultEntity.setJarPath(resultSet.getString(6)); resultEntity.setStatus(ApplicationEntity.Status.valueOf(resultSet.getString(7))); resultEntity.setConfiguration(parse(resultSet.getString(8))); resultEntity.setContext(parse(resultSet.getString(9))); resultEntity.setCreatedTime(resultSet.getLong(10)); resultEntity.setModifiedTime(resultSet.getLong(11)); return resultEntity; }
@Override public void start(Class<? extends ApplicationProvider> appProviderClass, Map<String, Object> appConfig) { try { ApplicationProvider applicationProvider = appProviderClass.newInstance(); start(applicationProvider.getApplicationDesc().getType(), appConfig); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e.getMessage(), e); } } }
@Override public ApplicationEntity getBySiteIdAndAppType(String siteId, String appType) { Optional<ApplicationEntity> optional = applicationEntityMap.values().stream() .filter((app) -> siteId.equals(app.getSite().getSiteId()) && appType.equals(app.getDescriptor().getType())).findAny(); if (optional.isPresent()) { return optional.get(); } else { return null; } }
@Override public StaticApplication getApplication() { return new StaticApplication(this.getApplicationDesc().getType()); }
private Collection<String> loadSites(String appType) { Set<String> sites = new HashSet<>(); Collection<ApplicationEntity> apps = applicationEntityService.findAll(); for (ApplicationEntity app : apps) { if (app.getDescriptor().getType().equalsIgnoreCase(appType) && app.getStatus().equals(ApplicationEntity.Status.RUNNING)) { sites.add(app.getSite().getSiteId()); } } LOG.info("Detected {} sites where MR_HISTORY_JOB_APP is Running: {}", sites.size(), sites); return sites; }
private void initializeProvider(ApplicationProviderConfig providerConfig) throws ClassNotFoundException, IllegalAccessException, InstantiationException { LOG.info("Loading application provider {} from {}", providerConfig.getClassName(), providerConfig.getJarPath()); String providerClassName = providerConfig.getClassName(); if (providerClassName == null) { throw new RuntimeException("provider.classname is null: " + providerConfig); } if (providerConfig.getJarPath() == null) { throw new RuntimeException("provider.jarpath is null: " + providerConfig); } Class<?> providerClass = Class.forName(providerClassName); if (!ApplicationProvider.class.isAssignableFrom(providerClass)) { throw new RuntimeException("providerClassName is not implementation of " + ApplicationProvider.class.getCanonicalName()); } ApplicationProvider provider = (ApplicationProvider) providerClass.newInstance(); Preconditions.checkNotNull(provider.getApplicationDesc(), "appDesc is null"); Preconditions.checkNotNull(provider.getApplicationDesc().getType(), "type is null"); registerProvider(provider); }
@Override public void ensureDefault() { super.ensureDefault(); Preconditions.checkNotNull(this.getSite(), "site is null"); Preconditions.checkNotNull(this.getSite().getSiteId(), "siteId is null"); Preconditions.checkNotNull(this.getDescriptor(), "descriptor is null"); Preconditions.checkNotNull(this.getDescriptor().getType(), "descriptor type is null"); if (this.appId == null) { this.appId = String.format("%s_%s", this.getDescriptor().getType(), this.getSite().getSiteId()).toUpperCase(); } if (this.status == null) { this.status = Status.INITIALIZED; } }