use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.
the class PublishHandler method setVersion.
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());
}
use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.
the class PublishHandler method countDeployments.
/**
* 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();
}
use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.
the class IntegrationHandler method create.
@Override
public Integration create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Integration integration) {
Integration encryptedIntegration = encryptionSupport.encrypt(integration);
Integration updatedIntegration = new Integration.Builder().createFrom(encryptedIntegration).createdAt(System.currentTimeMillis()).build();
// Create the the integration.
return getDataManager().create(updatedIntegration);
}
use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.
the class IntegrationHandler method getIntegration.
// **************************
// Helpers
// **************************
public Integration getIntegration(String id) {
final DataManager dataManager = getDataManager();
final Integration integration = dataManager.fetch(Integration.class, id);
if (integration == null) {
throw new EntityNotFoundException();
}
return integration;
}
use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.
the class IntegrationHandler method putDeployment.
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/deployments")
public IntegrationDeployment putDeployment(@Context SecurityContext sec, @NotNull @PathParam("id") @ApiParam(required = true) String id) {
Integration integration = getIntegration(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(sec.getUserPrincipal().getName()).build();
deployment = getDataManager().create(deployment);
return deployment;
}
Aggregations