public int getVersion() { return deployment.getVersion(); }
public Optional<Integer> getDeploymentVersion() { return deployment.map(x->x.getVersion()); }
public boolean isDraft() { return deployment.map(x -> x.getVersion() != integration.getVersion()).orElse(true); }
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)); }
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)); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path(value = "/{id}/overview") public IntegrationOverview getOverview(@PathParam("id") final String id) { Integration integration = Getter.super.get(id); List<IntegrationDeployment> deployments = getDataManager().fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id+":"), ReverseFilter.getInstance()) .getItems(); Optional<IntegrationBulletinBoard> bulletins = Optional .ofNullable(getDataManager().fetch(IntegrationBulletinBoard.class, id)); return new IntegrationOverview(integration, bulletins, deployments.stream().filter(d -> d.getVersion() == integration.getVersion()).findFirst()) { @Override public List<DeploymentOverview> getDeployments() { return deployments.stream() .map(x->new DeploymentOverview(x)) .collect(Collectors.toList()); } }; }
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(); }
@PUT @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/deployments") public IntegrationDeployment putDeployment(@Context SecurityContext sec, @NotNull @PathParam("id") @ApiParam(required = true) String id) { Integration integration = Getter.super.get(id); int nextDeploymentVersion = 1; // Update previous deployments targetState=Undeployed and make sure nextDeploymentVersion is larger than all previous ones. Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", id); if (deploymentIds != null && !deploymentIds.isEmpty()) { Stream<IntegrationDeployment> deployments = deploymentIds.stream() .map(i -> getDataManager().fetch(IntegrationDeployment.class, i)) .filter(r -> r != null); for (IntegrationDeployment d : deployments.toArray(IntegrationDeployment[]::new)) { nextDeploymentVersion = Math.max(nextDeploymentVersion, d.getVersion()+1); getDataManager().update(d.withTargetState(IntegrationDeploymentState.Unpublished)); } } IntegrationDeployment deployment = new IntegrationDeployment.Builder() .id(IntegrationDeployment.compositeId(id, nextDeploymentVersion)) .spec(integration) .version(nextDeploymentVersion) // .userId(SecurityContextHolder.getContext().getAuthentication().getName()) .userId(sec.getUserPrincipal().getName()) .build(); deployment = getDataManager().create(deployment); return deployment; }
LOG.info("Integration {} : Start processing integration: {}, version: {} with handler:{}", integrationId, integrationId, integrationDeployment.getVersion(), handler.getClass().getSimpleName()); handler.execute(integrationDeployment, update->{ if (LOG.isInfoEnabled()) {
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) {