public int getIntegrationVersion() { return deployment.getSpec().getVersion(); }
private String getLabel(IntegrationDeployment integrationDeployment) { return String.format("Integration [%s]", Names.sanitize(integrationDeployment.getSpec().getName())); }
private boolean isIntegrationActiveAndUsingExtension(IntegrationDeployment integrationDeployment, Extension extension) { if (integrationDeployment == null || extension == null) { return false; } if (IntegrationDeploymentState.Published != integrationDeployment.getTargetState()) { return false; } return integrationDeployment.getSpec().getSteps().stream().anyMatch(step -> { boolean usedAsStep = extension.getExtensionId().equals( Optional.ofNullable(step) .flatMap(Step::getExtension) .map(Extension::getExtensionId) .orElse(null) ); boolean usedAsConnector = extension.getExtensionId().equals( Optional.ofNullable(step) .flatMap(Step::getConnection) .flatMap(Connection::getConnector) .flatMap(c -> c.getDependencies().stream().filter(Dependency::isExtension).findFirst()) .map(Dependency::getId) .orElse(null) ); return usedAsStep || usedAsConnector; }); }
default Collection<Dependency> collectDependencies(IntegrationDeployment deployment) { return collectDependencies(deployment.getSpec().getSteps()); }
/** * 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 build(IntegrationDeployment integration, DeploymentData data) throws IOException { InputStream tarInputStream = createProjectFiles(integration.getSpec()); logInfo(integration, "Created project files and starting build"); openShiftService().build(integration.getSpec().getName(), data, tarInputStream); }
@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); } } }
/** * 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.sanitize(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(); }
private boolean isReady(IntegrationDeployment integrationDeployment) { return openShiftService().isDeploymentReady(integrationDeployment.getSpec().getName()); }
private boolean isBuildFailed(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildFailed(integrationDeployment.getSpec().getName()); }
private boolean isBuildStarted(IntegrationDeployment integrationDeployment) { return openShiftService().isBuildStarted(integrationDeployment.getSpec().getName()); }
public boolean isRunning(IntegrationDeployment integrationDeployment) { return openShiftService().isScaled(integrationDeployment.getSpec().getName(), 1); }
public static Properties buildApplicationProperties(IntegrationDeployment integrationDeployment, DataManager dataManager, EncryptionComponent encryptionSupport) { final Properties properties = new Properties(); final List<? extends Step> steps = integrationDeployment.getSpec().getSteps();
private ResourceIdentifier toIntegrationResourceIdentifier(IntegrationDeployment integrationDeployment) { return new ResourceIdentifier.Builder() .id(integrationDeployment.getIntegrationId()) .kind(Kind.Integration) .name(Optional.ofNullable(integrationDeployment.getSpec().getName())) .build(); }
public IntegrationDeployment encrypt(IntegrationDeployment integrationDeployment) { return new IntegrationDeployment.Builder() .createFrom(integrationDeployment) .spec(new IntegrationDeploymentSpec.Builder().createFrom(integrationDeployment.getSpec()).steps(encrypt(integrationDeployment.getSpec().getSteps())).build()) .build(); }
private void deploy(IntegrationDeployment integration, DeploymentData data) throws IOException { logInfo(integration, "Starting deployment"); openShiftService().deploy(integration.getSpec().getName(), data); logInfo(integration, "Deployment done"); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState currentState = !openShiftService().exists(integrationDeployment.getSpec().getName()) || openShiftService().delete(integrationDeployment.getSpec().getName()) ? IntegrationDeploymentState.Unpublished : IntegrationDeploymentState.Pending; if (currentState == IntegrationDeploymentState.Unpublished) { logInfo(integrationDeployment,"Deleted"); IntegrationDeployment updated = new IntegrationDeployment.Builder().createFrom(integrationDeployment).addAllStepsDone(Collections.emptyList()).build(); dataManager.update(updated); } return new StateUpdate(currentState); }
public static IntegrationDeployment sanitize(IntegrationDeployment integrationDeployment, DataManager dataManager, EncryptionComponent encryptionSupport) { final int stepCount = integrationDeployment.getSpec().getSteps().size(); final List<Step> steps = new ArrayList<>(stepCount); final IntegrationDeploymentSpec.Builder builder = new IntegrationDeploymentSpec.Builder().createFrom(integrationDeployment.getSpec()); final Step source = integrationDeployment.getSpec().getSteps().get(i - 1); final Step target;