private Optional<String> getIntegrationIdInitialize() { return IntegrationDeployment.super.getIntegrationId(); }
private String getLabel(IntegrationDeployment integrationDeployment) { return "Integration " + integrationDeployment.getIntegrationId().orElse("[none]"); }
/** * 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(); }
public boolean isRunning(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())); return openShiftService().isScaled(integrationDeployment.getSpec().getName(), 1, labels); }
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.unpublishing()) .forEach(r -> { dataManager.update(r); }); }
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; } }
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()); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { Map<String, String> stepsDone = new HashMap<>(integrationDeployment.getStepsDone()); stepsDone.remove("deploy"); //we are literally undoing this step. IntegrationDeploymentState currentState = IntegrationDeploymentState.Pending; 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())); List<DeploymentConfig> deployments = openShiftService().getDeploymentsByLabel(labels); Boolean isDeployed = !deployments.stream().filter(d -> d.getSpec().getReplicas() != 0).collect(Collectors.toList()).isEmpty(); if (isDeployed) { try { LOG.info("Undeploying integration deployment:{} version:{}", integrationDeployment.getSpec().getName(), integrationDeployment.getVersion()); openShiftService().scale(integrationDeployment.getSpec().getName(), labels, 0, 1, TimeUnit.MINUTES); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return new StateUpdate(currentState, stepsDone); } } Boolean isUndeployed = !deployments.stream().filter(d -> d.getStatus().getAvailableReplicas() == 0).collect(Collectors.toList()).isEmpty(); if(isUndeployed){ currentState = IntegrationDeploymentState.Unpublished; } return new StateUpdate(currentState, stepsDone); }
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());
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->{
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; }
public void accept(IntegrationDeployment integrationDeployment) { final String integrationId = integrationDeployment.getIntegrationId().get(); final String version = String.valueOf(integrationDeployment.getVersion()); final String compositeId = IntegrationDeployment.compositeId(integrationId, integrationDeployment.getVersion());
integrationId(instance.getIntegrationId()); Integration specValue = instance.getSpec(); if (specValue != null) {