@Value.Default default Optional<String> getIntegrationId() { return getSpec().getId(); }
/** * 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(); }
/** * 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; }
/** * 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(); }
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 id = integration.getId().get();