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)); }
@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; }
@Override public void delete(String id) { Integration existing = Getter.super.get(id); //Set all integration status to Undeployed. Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", existing.getId().get()); if (deploymentIds != null && !deploymentIds.isEmpty()) { deploymentIds.stream() .map(i -> getDataManager().fetch(IntegrationDeployment.class, i)) .filter(r -> r != null) .map(r -> r.withTargetState(IntegrationDeploymentState.Unpublished)) .forEach(r -> getDataManager().update(r)); } Integration updatedIntegration = new Integration.Builder() .createFrom(existing) .updatedAt(System.currentTimeMillis()) .isDeleted(true) .build(); Updater.super.update(id, updatedIntegration); }