@Override public String toString() { return "AppRegistration{" + "name='" + this.getName() + '\'' + ", type='" + this.getType() + '\'' + ", version='" + this.getVersion() + '\'' + ", uri=" + this.getUri() + ", metadataUri=" + this.getMetadataUri() + '}'; }
@Override public int compareTo(AppRegistration that) { int i = this.getType().compareTo(that.getType()); if (i == 0) { i = this.getName().compareTo(that.getName()); } if (i == 0) { i = this.getVersion().compareTo(that.getVersion()); } return i; } }
@Override public AppRegistration save(AppRegistration app) { AppRegistration createdApp; AppRegistration appRegistration = this.appRegistrationRepository.findAppRegistrationByNameAndTypeAndVersion( app.getName(), app.getType(), app.getVersion()); if (appRegistration != null) { appRegistration.setUri(app.getUri()); appRegistration.setMetadataUri(app.getMetadataUri()); createdApp = this.appRegistrationRepository.save(appRegistration); populateAuditData(AuditActionType.UPDATE, createdApp); } else { if (getDefaultApp(app.getName(), app.getType()) == null) { app.setDefaultVersion(true); } createdApp = this.appRegistrationRepository.save(app); populateAuditData(AuditActionType.CREATE, createdApp); } return createdApp; }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> proposals) { CompletionProposal.Factory completionFactory = CompletionProposal.expanding(dsl); for (AppRegistration appRegistration : appRegistry.findAll()) { if (appRegistration.getType() == ApplicationType.processor || appRegistration.getType() == ApplicationType.sink) { proposals.add(completionFactory.withSeparateTokens(appRegistration.getName(), "Wire destination into a " + appRegistration.getType() + " app")); } } }
@Override public Resource getAppMetadataResource(AppRegistration appRegistration) { return this.appResourceCommon.getMetadataResource(appRegistration.getUri(), appRegistration.getMetadataUri()); }
@Override public void setDefaultApp(String name, ApplicationType type, String version) { AppRegistration oldDefault = this.appRegistrationRepository .findAppRegistrationByNameAndTypeAndDefaultVersionIsTrue(name, type); if (oldDefault != null) { oldDefault.setDefaultVersion(false); this.appRegistrationRepository.save(oldDefault); } AppRegistration newDefault = this.appRegistrationRepository .findAppRegistrationByNameAndTypeAndVersion(name, type, version); if (newDefault == null) { throw new NoSuchAppRegistrationException(name, type, version); } newDefault.setDefaultVersion(true); this.appRegistrationRepository.save(newDefault); this.auditRecordService.populateAndSaveAuditRecordUsingMapData(AuditOperationType.APP_REGISTRATION, AuditActionType.UPDATE, newDefault.getName(), this.auditServiceUtils.convertAppRegistrationToAuditData(newDefault)); }
private void populateAuditData(AuditActionType auditActionType, AppRegistration appRegistration) { if (appRegistration == null) { logger.error("App registration failed, app not saved into database!"); } else { this.auditRecordService.populateAndSaveAuditRecordUsingMapData(AuditOperationType.APP_REGISTRATION, auditActionType, appRegistration.getName(), this.auditServiceUtils.convertAppRegistrationToAuditData(appRegistration)); } }
@Deprecated @RequestMapping(value = "/{type}/{name}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public DetailedAppRegistrationResource info( @PathVariable("type") ApplicationType type, @PathVariable("name") String name, @RequestParam(required = false, name = "exhaustive") boolean exhaustive) { if (!this.appRegistryService.appExist(name, type)) { throw new NoSuchAppRegistrationException(name, type); } String defaultVersion = this.appRegistryService.getDefaultApp(name, type).getVersion(); return getInfo(type, name, defaultVersion, exhaustive); }
@Override public Resource getAppResource(AppRegistration appRegistration) { return this.appResourceCommon.getResource(appRegistration.getUri().toString()); }
/** * Trigger early resolution of the metadata resource of registrations that have an * explicit metadata artifact. This assumes usage of * {@link org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader}. */ private void prefetchMetadata(List<AppRegistration> appRegistrations) { forkJoinPool.execute(() -> { appRegistrations.stream().filter(r -> r.getMetadataUri() != null).parallel().forEach(r -> { logger.info("Eagerly fetching {}", r.getMetadataUri()); try { this.appRegistryService.getAppMetadataResource(r); } catch (Exception e) { logger.warn("Could not fetch " + r.getMetadataUri(), e); } }); }); }
@Override public void addProposals(String dsl, IllegalArgumentException exception, int detailLevel, List<CompletionProposal> proposals) { CompletionProposal.Factory completionFactory = CompletionProposal.expanding(dsl); for (AppRegistration app : this.registry.findAll()) { if (app.getType() == ApplicationType.source || app.getType() == ApplicationType.app) { proposals.add(completionFactory.withSeparateTokens(app.getName(), "Start with a source app or an unbounded streaming app")); } } }
protected boolean isOverwrite(AppRegistration app, boolean overwrite) { return overwrite || this.appRegistrationRepository.findAppRegistrationByNameAndTypeAndVersion(app.getName(), app.getType(), app.getVersion()) == null; }
@Deprecated @RequestMapping(value = "/{type}/{name}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) public void unregister(@PathVariable("type") ApplicationType type, @PathVariable("name") String name) { if (this.appRegistryService.find(name, type) == null) { throw new NoSuchAppRegistrationException(name, type); } AppRegistration appRegistration = this.appRegistryService.getDefaultApp(name, type); if (appRegistration == null) { throw new RuntimeException(String.format("No default version exists for the app [%s:%s]", name, type)); } this.unregister(type, name, appRegistration.getVersion()); }
appRegistration.getUri().toString(), currentApp.getName())); Resource appResource = this.appRegistry.getAppResource(appRegistration); Resource metadataResource = this.appRegistry.getAppMetadataResource(appRegistration);
public Map<String, Object> convertAppRegistrationToAuditData(AppRegistration appRegistration) { final Map<String, Object> auditData = new HashMap<>(4); auditData.put(APP_NAME, appRegistration.getName()); auditData.put(APP_TYPE, appRegistration.getType()); auditData.put(APP_VERSION, appRegistration.getVersion()); auditData.put(APP_IS_DEFAULT, appRegistration.isDefaultVersion()); auditData.put(APP_URI, appRegistration.getUri()); auditData.put(APP_META_DATA_URI, appRegistration.getMetadataUri()); return auditData; }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> proposals) { CompletionProposal.Factory completionFactory = CompletionProposal.expanding(dsl); for (AppRegistration app : this.registry.findAll()) { if (app.getType() == ApplicationType.task) { proposals.add(completionFactory.withSeparateTokens(app.getName(), "Choose a task app")); } } }
@Override public AppRegistrationResource toResource(AppRegistration registration) { return createResourceWithId(String.format("%s/%s/%s", registration.getType(), registration.getName(), registration.getVersion()), registration); }
public Map<String, Object> convertAppRegistrationToAuditData(AppRegistration appRegistration) { final Map<String, Object> auditData = new HashMap<>(4); auditData.put(APP_NAME, appRegistration.getName()); auditData.put(APP_TYPE, appRegistration.getType()); auditData.put(APP_VERSION, appRegistration.getVersion()); auditData.put(APP_IS_DEFAULT, appRegistration.isDefaultVersion()); auditData.put(APP_URI, appRegistration.getUri()); auditData.put(APP_META_DATA_URI, appRegistration.getMetadataUri()); return auditData; }
@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> collector) { StreamDefinition streamDefinition = new StreamDefinition("__dummy", exception.getExpressionStringUntilCheckpoint()); CompletionProposal.Factory proposals = CompletionProposal.expanding(dsl); // We only support full streams at the moment, so completions can only be // processor or sink for (AppRegistration appRegistration : appRegistry.findAll()) { if (appRegistration.getType() == ApplicationType.processor || appRegistration.getType() == ApplicationType.sink) { String expansion = CompletionUtils.maybeQualifyWithLabel(appRegistration.getName(), streamDefinition); collector.add(proposals.withSeparateTokens(expansion, "Continue stream definition with a " + appRegistration.getType())); } } } }