private List<Flow> getFlowsInitialize() { return Integration.super.getFlows(); }
/** * Check if Integration has active deployments. * @param deployment The specified {@link IntegrationDeployment}. * @return The true if there are, false otherwise. */ private boolean hasPublishedDeployments(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String id = Labels.validate(integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration"))); String version = String.valueOf(integration.getVersion()); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.INTEGRATION_ID_LABEL, id); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !version.equals(d.getMetadata().getLabels().get(OpenShiftService.DEPLOYMENT_VERSION_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count() > 0; }
private Map<String, String> getConfiguredPropertiesInitialize() { return Integration.super.getConfiguredProperties(); }
@Override public Integration updateFlowExcerpts(Integration integration) { // Update excerpt for api provider endpoints only if (integration == null || !integration.getTags().contains("api-provider")) { return integration; } return new Integration.Builder() .createFrom(integration) .flows(integration.getFlows().stream() .map(this::flowWithExcerpts) .collect(Collectors.toList())) .build(); }
EquivContext context = identifier(parentContext, another.getName(), another.getClass()); context.setFail(ONE_NULL, NULL, NOT_NULL); return false; EquivContext context = identifier(parentContext, one.getName(), one.getClass()); if (another == null) { context.setFail(ANOTHER_NULL, NOT_NULL, NULL); List<Connection> myConnections = one.getConnections(); if (myConnections == null) { if (another.getConnections() != null) { context.setFail("connections", NULL, NOT_NULL); return false; Connection anotherConnection = another.findConnectionById(myConnection.getId().get()).orElse(null); if (! equivalent(context, myConnection, anotherConnection)) { return false; List<Flow> myFlows = one.getFlows(); if (myFlows == null) { if (another.getFlows() != null) { context.setFail("flows", NULL, NOT_NULL); return false; Flow anotherFlow = another.findFlowById(myFlow.getId().get()).orElse(null); if (! equivalent(context, myFlow, anotherFlow)) { return false; pair(one.getKind(), another.getKind(), "id"),
final List<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class).getItems().stream() .filter(d -> !d.getSpec().isDeleted()) .collect(Collectors.toList()); final Set<Integration> deployedIintegrations = deployments.stream() final String id = integration.getId().get(); final List<Flow> flows = integration.getFlows(); builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages)); builder.putMetadata("integration-id", id); builder.putMetadata("integration-version", Integer.toString(integration.getVersion())); builder.messages(messages);
@Override public String getName() { return getTarget().getName(); }
private Collection<? extends LeveledMessage> computeDeploymentDifferences(Integration integration, Collection<IntegrationDeployment> allDeployments) { List<IntegrationDeployment> deployments = allDeployments.stream() .filter(d -> d.getIntegrationId().equals(integration.getId())) .filter(d -> d.getCurrentState().equals(IntegrationDeploymentState.Published)) .collect(Collectors.toList()); for (Step deployedStep : deployedInteg.getSteps()) { deployedStep.getAction() .filter(ConnectorAction.class::isInstance)
@Value.Default default Optional<String> getIntegrationId() { return getSpec().getId(); }
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")); String integrationId = integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId")); String version = Integer.toString(integrationDeployment.getVersion()); final Builder deploymentDataBuilder = DeploymentData.builder() .withVersion(integrationDeployment.getVersion()) .addLabel(OpenShiftService.INTEGRATION_ID_LABEL, Labels.validate(integrationId)) .addLabel(OpenShiftService.DEPLOYMENT_VERSION_LABEL, version) .addLabel(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)) .addAnnotation(OpenShiftService.INTEGRATION_NAME_ANNOTATION, integration.getName()) .addAnnotation(OpenShiftService.INTEGRATION_ID_LABEL, integrationId) .addAnnotation(OpenShiftService.DEPLOYMENT_VERSION_LABEL, version) .addSecretEntry("application.properties", propsToString(applicationProperties)); integration.getConfiguredProperties().forEach((k, v) -> deploymentDataBuilder.addProperty(k, v)); DeploymentData data = deploymentDataBuilder.build(); if (this.customizers != null && !this.customizers.isEmpty()) { for (DeploymentDataCustomizer customizer : customizers) { data = customizer.customize(data, integrationDeployment); } } return data; }
private int getVersionInitialize() { return Integration.super.getVersion(); }
private List<Step> getStepsInitialize() { return Integration.super.getSteps(); }
private String getLabel(Integration integration) { return String.format("Integration [%s]", Names.sanitize(integration.getName())); }
/** * 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 static Stream<Step> allSteps(Integration integration) { return integration.getFlows().stream().flatMap(f -> f.getSteps().stream()); }
private String getLabel(IntegrationDeployment integrationDeployment) { return String.format("Integration [%s]", Names.sanitize(integrationDeployment.getSpec().getName())); }
/** * Count the deployments of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of deployed integrations (excluding the current). */ private int countDeployments(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String id = Labels.validate(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")); Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.USERNAME_LABEL, Labels.sanitize(username)); return (int) openShiftService().getDeploymentsByLabel(labels) .stream() .filter(d -> !id.equals(d.getMetadata().getLabels().get(OpenShiftService.INTEGRATION_ID_LABEL))) .filter(d -> d.getSpec().getReplicas() > 0) .count(); }
/** * Collect dependencies. */ default Collection<Dependency> collectDependencies(Integration integration) { return collectDependencies(integration.getFlows().stream().flatMap(flow -> flow.getSteps().stream()).collect(Collectors.toList()), true); }
private IntegrationDeploymentState determineState(IntegrationDeployment integrationDeployment) { Map<String, String> labels = new HashMap<>(); labels.put(OpenShiftService.INTEGRATION_ID_LABEL, Labels.validate(integrationDeployment.getIntegrationId().get())); labels.put(OpenShiftService.DEPLOYMENT_VERSION_LABEL, String.valueOf(integrationDeployment.getVersion())); if (!openShiftService.exists(integrationDeployment.getSpec().getName()) || !openShiftService.isScaled(integrationDeployment.getSpec().getName(), 1, labels)) { return IntegrationDeploymentState.Unpublished; } else { return IntegrationDeploymentState.Published; } }
@Override public void configure() throws Exception { final Integration integration = loadIntegration(); final List<Flow> flows = integration.getFlows(); for (int f = 0; f < flows.size(); f++) { configureFlow(flows.get(f), String.valueOf(f)); } }