use of io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails in project syndesis by syndesisio.
the class PublicApiHandlerTest method testGetIntegrationState.
@Test
public void testGetIntegrationState() {
final DataManager dataManager = mock(DataManager.class);
final Integration integration = new Integration.Builder().id("integration-id").name("integration-name").build();
when(dataManager.fetch(Integration.class, "integration-name")).thenReturn(integration);
final IntegrationHandler integrationHandler = mock(IntegrationHandler.class);
when(integrationHandler.get("integration-id")).thenReturn(new IntegrationOverview.Builder().createFrom(integration).currentState(IntegrationDeploymentState.Unpublished).build());
final MonitoringProvider monitoringProvider = mock(MonitoringProvider.class);
final IntegrationDeploymentStateDetails stateDetails = new IntegrationDeploymentStateDetails.Builder().build();
when(monitoringProvider.getIntegrationStateDetails("integration-id")).thenReturn(stateDetails);
// null's are not used
final PublicApiHandler handler = new PublicApiHandler(dataManager, null, null, null, monitoringProvider, new EnvironmentHandler(dataManager), null, integrationHandler);
final PublicApiHandler.IntegrationState integrationState = handler.getIntegrationState(newMockSecurityContext(), "integration-name");
assertThat(integrationState.getCurrentState()).isEqualTo(IntegrationDeploymentState.Unpublished);
assertThat(integrationState.getStateDetails()).isEqualTo(stateDetails);
}
use of io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails in project syndesis by syndesisio.
the class PublishingStateMonitor method accept.
@Override
@SuppressWarnings("PMD.NPathComplexity")
public void accept(IntegrationDeployment integrationDeployment) {
final String integrationId = integrationDeployment.getIntegrationId().get();
final String version = String.valueOf(integrationDeployment.getVersion());
final String compositeId = IntegrationDeployment.compositeId(integrationId, integrationDeployment.getVersion());
final IntegrationDeploymentState targetState = integrationDeployment.getTargetState();
// is it being published?
if (targetState.equals(Published)) {
IntegrationDeploymentDetailedState detailedState = null;
String podName = null;
LinkType linkType = null;
// work backwards, in reverse order: deployed pod, deployer pod, build pod, default to assembling
// 1. look for deployed pod
final PodList podList = getDeploymentPodList(integrationId, version);
if (!podList.getItems().isEmpty()) {
// TODO: handle pod scaling in the future
final Pod pod = podList.getItems().get(0);
podName = pod.getMetadata().getName();
// check if deployment is ready
if (Readiness.isPodReady(pod)) {
// no details needed once deployed successfully!!!
// NOTE that this won't happen always, the state polling window may miss this
// TODO need a cleanup handler to remove successfully published state details??
deleteStateDetails(compositeId);
} else {
linkType = getPodUrls(pod);
// pending deployment pod
detailedState = EVENTS == linkType ? IntegrationDeploymentDetailedState.DEPLOYING : IntegrationDeploymentDetailedState.STARTING;
}
} else {
// 2. look for deployer pod
final Optional<ReplicationController> replicationController = getReplicationController(integrationId, version);
if (replicationController.isPresent()) {
podName = replicationController.get().getMetadata().getAnnotations().get(DEPLOYER_POD_NAME_ANNOTATION);
if (podName != null) {
final Pod deployerPod = getPod(podName);
if (deployerPod != null) {
// with a deployer pod, detailed state is always deploying
linkType = getPodUrls(deployerPod);
detailedState = IntegrationDeploymentDetailedState.DEPLOYING;
} else {
// clear podName, since it doesn't exist yet
podName = null;
}
}
}
// 3. look for build pod, if deployer pod not found
if (podName == null) {
final Optional<Build> build = getBuild(integrationId, version);
if (build.isPresent()) {
podName = build.get().getMetadata().getAnnotations().get(BUILD_POD_NAME_ANNOTATION);
if (podName != null) {
final Pod pod = getPod(podName);
if (pod != null) {
linkType = getPodUrls(pod);
// pending deployment pod
detailedState = EVENTS == linkType ? IntegrationDeploymentDetailedState.ASSEMBLING : IntegrationDeploymentDetailedState.BUILDING;
} else {
// clear podName, since it doesn't exist yet
podName = null;
}
}
}
}
if (detailedState == null) {
// 4. default initial state, with no event or log urls!!!
detailedState = IntegrationDeploymentDetailedState.ASSEMBLING;
}
}
if (detailedState != null) {
IntegrationDeploymentStateDetails stateDetails = getStateDetails(integrationId, version, compositeId, detailedState, podName, linkType);
if (dataManager.fetch(IntegrationDeploymentStateDetails.class, compositeId) != null) {
dataManager.update(stateDetails);
} else {
dataManager.create(stateDetails);
}
}
}
}
Aggregations