use of io.syndesis.common.model.integration.IntegrationDeployment 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;
}
use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class IntegrationHandler method toCurrentIntegrationOverview.
public IntegrationOverview toCurrentIntegrationOverview(Integration integration) {
final DataManager dataManager = getDataManager();
final String id = integration.getId().get();
final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration);
// add board
DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board);
// Defaults
builder.isDraft(true);
builder.currentState(IntegrationDeploymentState.Unpublished);
builder.targetState(IntegrationDeploymentState.Unpublished);
// Get the latest connection.
builder.connections(integration.getConnections().stream().map(this::toCurrentConnection).collect(Collectors.toList()));
// Get the latest steps.
builder.steps(integration.getSteps().stream().map(this::toCurrentSteps).collect(Collectors.toList()));
for (IntegrationDeployment deployment : dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance())) {
builder.addDeployment(IntegrationDeploymentOverview.of(deployment));
if (deployment.getVersion() == integration.getVersion()) {
builder.isDraft(deployment.getVersion() != integration.getVersion());
builder.targetState(deployment.getTargetState());
builder.currentState(deployment.getCurrentState());
builder.deploymentVersion(deployment.getVersion());
}
}
return builder.build();
}
use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class IntegrationHandler method setTargetStatus.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/deployments/{version}/targetState")
@SuppressFBWarnings("UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD")
public void setTargetStatus(@NotNull @PathParam("id") @ApiParam(required = true) String id, @NotNull @PathParam("version") @ApiParam(required = true) Integer version, TargetStateRequest request) {
String compositeId = IntegrationDeployment.compositeId(id, version);
IntegrationDeployment deployment = getDataManager().fetch(IntegrationDeployment.class, compositeId);
deployment = new IntegrationDeployment.Builder().createFrom(deployment).targetState(request.targetState).build();
getDataManager().update(deployment);
}
use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class PublishHandler method hasPublishedDeployments.
/**
* 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;
}
use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.
the class IntegrationController method reschedule.
@SuppressWarnings("FutureReturnValueIgnored")
private void reschedule(String integrationId) {
LOG.debug("Reschedule IntegrationDeployment check, id:{}, keys: {}", integrationId, scheduledChecks);
scheduler.schedule(() -> {
IntegrationDeployment i = dataManager.fetch(IntegrationDeployment.class, integrationId);
LOG.debug("Trigger checkIntegrationStatus, id:{}", integrationId);
checkIntegrationStatus(i);
}, SCHEDULE_INTERVAL_IN_SECONDS, TimeUnit.SECONDS);
}
Aggregations