private String getLabel(IntegrationDeployment integrationDeployment) { return "Integration " + integrationDeployment.getIntegrationId().orElse("[none]"); }
private String getLabel(IntegrationDeployment integrationDeployment) { return "Integration " + integrationDeployment.getIntegrationId().orElse("[none]"); }
private Integration integrationOf(IntegrationDeployment integrationDeployment) { return dataManager.fetch(Integration.class, integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment doesn't have integration id."))); }
private Integration integrationOf(IntegrationDeployment integrationDeployment) { return dataManager.fetch(Integration.class, integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment doesn't have integration id."))); }
@Override public ListResult<IntegrationDeployment> apply(ListResult<IntegrationDeployment> list) { List<IntegrationDeployment> filtered = list.getItems().stream() .filter(i -> integrationId == null || integrationId.equals(i.getIntegrationId().orElse(null))) .collect(Collectors.toList()); return new ListResult.Builder<IntegrationDeployment>() .totalCount(filtered.size()) .addAllItems(filtered).build(); } }
/** * Counts active integrations (in DB) of the owner of the specified integration. * * @param integration The specified integration. * @return The number of integrations (excluding the current). */ private int countActiveIntegrationsOfSameUserAs(Integration integration) { String integrationId = integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration.")); String username = integration.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return (int) dataManager.fetchAll(IntegrationDeployment.class).getItems() .stream() .filter(i -> !i.getIntegrationId().get().equals(integrationId)) //The "current" integration will already be in the database. .filter(i -> IntegrationDeploymentState.Active == i.getCurrentState()) .map(i -> i.getIntegrationId().get()) .distinct() .map(i -> dataManager.fetch(Integration.class, i)) .filter(i -> i.getUserId().map(username::equals).orElse(Boolean.FALSE)) .count(); }
private void deactivatePreviousDeployments(IntegrationDeployment integrationDeployment) { dataManager.fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", integrationDeployment.getIntegrationId().get(), "currentState", "Active") .stream() .map(id -> dataManager.fetch(IntegrationDeployment.class, id)) .filter(r -> r.getVersion().orElse(0) >= integrationDeployment.getVersion().orElse(0)) .map(r -> r.withCurrentState(IntegrationDeploymentState.Undeployed)) .forEach(r -> dataManager.update(r)); }
/** * Counts active integrations (in DB) of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of integrations (excluding the current). */ private int countActiveIntegrationsOfSameUserAs(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String integrationId = integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration.")); String username = deployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return (int) dataManager.fetchAll(IntegrationDeployment.class).getItems() .stream() .filter(i -> !i.getIntegrationId().get().equals(integrationId)) //The "current" integration will already be in the database. .filter(i -> IntegrationDeploymentState.Published == i.getCurrentState()) .filter(i -> i.getUserId().map(username::equals).orElse(Boolean.FALSE)) .count(); }
private void deactivatePreviousDeployments(IntegrationDeployment integrationDeployment) { dataManager.fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", integrationDeployment.getIntegrationId().get(), "targetState", IntegrationDeploymentState.Published.name()) .stream() .map(id -> dataManager.fetch(IntegrationDeployment.class, id)) .filter(r -> r.getVersion() != integrationDeployment.getVersion()) .map(r -> r.withTargetState(IntegrationDeploymentState.Unpublished)) .forEach(r -> dataManager.update(r)); }
@Override public void configure() throws Exception { final IntegrationDeployment deployment = loadDeployment(); final List<? extends Step> steps = deployment.getSpec().getSteps(); ProcessorDefinition route = null; for (int i = 0; i< steps.size(); i++) { final Step step = steps.get(i); if (i == 0 && !"endpoint".equals(step.getStepKind())) { throw new IllegalStateException("No connector found as first step (found: " + step.getKind() + ")"); } final IntegrationStepHandler handler = findHandler(step); final Optional<ProcessorDefinition> definition = handler.handle(step, route, this); if (route == null && definition.isPresent()) { definition.filter(RouteDefinition.class::isInstance) .map(RouteDefinition.class::cast) .map(rd -> rd.getInputs().get(0)) .ifPresent(rd -> { step.getId().ifPresent(rd::id); }); route = definition.get(); deployment.getIntegrationId().ifPresent(route::setId); } else { route = definition.map(rd -> { step.getId().ifPresent(rd::id); return rd; }).orElse(route); } } }
private void setVersion(IntegrationDeployment integrationDeployment) { Integration integration = integrationDeployment.getIntegrationId().map(i -> dataManager.fetch(Integration.class, i)).orElseThrow(()-> new IllegalStateException("Integration not found!")); dataManager.update(new Integration.Builder().createFrom(integration).version(integrationDeployment.getVersion()).build()); }
private void updateIntegration(IntegrationDeployment integrationDeployment, IntegrationDeploymentState state) { Integration current = dataManager.fetch(Integration.class, integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId"))); //Set the deployed integrationDeployment id. Integration updated = new Integration.Builder().createFrom(current) .deploymentId(integrationDeployment.getVersion().get()) .currentStatus(state) .build(); dataManager.update(updated); }
private DeploymentData createDeploymentData(Integration integration, IntegrationDeployment integrationDeployment) { Properties applicationProperties = IntegrationSupport.buildApplicationProperties(integrationDeployment, dataManager, encryptionComponent); String username = integration.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return DeploymentData.builder() .addLabel(OpenShiftService.INTEGRATION_ID_LABEL, Labels.sanitize(integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId")))) .addLabel(OpenShiftService.DEPLOYMENT_ID_LABEL, integrationDeployment.getVersion().orElse(0).toString()) .addLabel(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)) .addSecretEntry("application.properties", propsToString(applicationProperties)) .build(); }
private DeploymentData createDeploymentData(Integration integration, IntegrationDeployment integrationDeployment) { Properties applicationProperties = projectGenerator.generateApplicationProperties(integration); String username = integrationDeployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return DeploymentData.builder() .addLabel(OpenShiftService.INTEGRATION_ID_LABEL, Labels.sanitize(integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId")))) .addLabel(OpenShiftService.DEPLOYMENT_ID_LABEL, Integer.toString(integrationDeployment.getVersion())) .addLabel(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)) .addAnnotation(OpenShiftService.INTEGRATION_NAME_ANNOTATION, integration.getName()) .addAnnotation(OpenShiftService.INTEGRATION_ID_ANNOTATION, integrationDeployment.getIntegrationId().get()) .addAnnotation(OpenShiftService.DEPLOYMENT_VERSION_ANNOTATION, Integer.toString(integrationDeployment.getVersion())) .addSecretEntry("application.properties", propsToString(applicationProperties)) .build(); }
private ResourceIdentifier toIntegrationResourceIdentifier(IntegrationDeployment integrationDeployment) { return new ResourceIdentifier.Builder() .id(integrationDeployment.getIntegrationId()) .kind(Kind.Integration) .name(Optional.ofNullable(integrationDeployment.getSpec().getName())) .build(); }
final String integrationId = integrationDeployment.getIntegrationId().get(); LOG.info("Integration {} : Start processing integration: {}, version: {} with handler:{}", integrationId, integrationId, integrationDeployment.getVersion(), handler.getClass().getSimpleName()); handler.execute(integrationDeployment, update->{
LOG.info("Integration {} : Start processing integration: {}, version: {} with handler:{}", integrationDeployment.getIntegrationId().get(), integrationDeployment.getVersion().get(), handler.getClass().getSimpleName()); StateUpdate update = handler.execute(integrationDeployment); if (update!=null) {