Search in sources :

Example 1 with IntegrationDeploymentStateDetails

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);
}
Also used : IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) IntegrationDeploymentStateDetails(io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails) Integration(io.syndesis.common.model.integration.Integration) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) DataManager(io.syndesis.server.dao.manager.DataManager) MonitoringProvider(io.syndesis.server.endpoint.monitoring.MonitoringProvider) Test(org.junit.Test)

Example 2 with IntegrationDeploymentStateDetails

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);
            }
        }
    }
}
Also used : IntegrationDeploymentStateDetails(io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails) IntegrationDeploymentDetailedState(io.syndesis.common.model.monitoring.IntegrationDeploymentDetailedState) PodList(io.fabric8.kubernetes.api.model.PodList) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) Pod(io.fabric8.kubernetes.api.model.Pod) Build(io.fabric8.openshift.api.model.Build) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) LinkType(io.syndesis.common.model.monitoring.LinkType)

Aggregations

IntegrationDeploymentStateDetails (io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails)2 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1 Build (io.fabric8.openshift.api.model.Build)1 Integration (io.syndesis.common.model.integration.Integration)1 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)1 IntegrationDeploymentDetailedState (io.syndesis.common.model.monitoring.IntegrationDeploymentDetailedState)1 LinkType (io.syndesis.common.model.monitoring.LinkType)1 DataManager (io.syndesis.server.dao.manager.DataManager)1 MonitoringProvider (io.syndesis.server.endpoint.monitoring.MonitoringProvider)1 EnvironmentHandler (io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler)1 IntegrationHandler (io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler)1 Test (org.junit.Test)1