Search in sources :

Example 1 with OpenShiftRuntimeState

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.

the class OpenShiftRuntimeExecExecutor method create.

private Optional<OpenShiftRuntime> create(final OpenShiftRuntimeConfig runtimeConfig) throws ProvisioningException {
    final Optional<OpenShiftProvider> _openshiftProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), OpenShiftProvider.class);
    if (!_openshiftProvider.isPresent()) {
        return Optional.empty();
    }
    OpenShiftProvider openshiftProvider = _openshiftProvider.get();
    OpenShiftClient openshiftClient = openshift.getOpenShiftClient(openshiftProvider);
    LOG.info("Creating runtime...");
    OpenShiftRuntimeState runtimeState;
    try {
        runtimeState = openshiftClient.create(runtimeConfig);
    } catch (OpenShiftClientException ex) {
        throw new ProvisioningException(ex.getMessage(), ex);
    }
    final String id = runtimeConfig.getRuntimeId().toString();
    LOG.info("Created runtime: " + id);
    OpenShiftRuntimeEndpoint endpoint = openshiftClient.getRuntimeEndpoint(id);
    return Optional.of(new OpenShiftRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig, openshiftProvider, endpoint, new OpenShiftRuntimeInfo(runtimeConfig), runtimeState));
}
Also used : OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftClient(org.guvnor.ala.openshift.access.OpenShiftClient) ProvisioningException(org.guvnor.ala.exceptions.ProvisioningException) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) OpenShiftRuntimeInfo(org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)

Example 2 with OpenShiftRuntimeState

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.

the class OpenShiftRuntimeManager method refresh.

@Override
public void refresh(RuntimeId runtimeId) throws RuntimeOperationException {
    OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    if (runtime != null) {
        try {
            // LOG.info( "Refreshing runtime: " + runtimeId.getId() );
            OpenShiftRuntimeState runtimeState = openshift.getOpenShiftClient(runtime.getProviderId()).getRuntimeState(runtime.getId());
            OpenShiftRuntime newRuntime = new OpenShiftRuntime(runtime.getId(), runtime.getName(), runtime.getConfig(), runtime.getProviderId(), runtime.getEndpoint(), runtime.getInfo(), runtimeState);
            runtimeRegistry.registerRuntime(newRuntime);
        } catch (OpenShiftClientException ex) {
            LOG.error("Error Refreshing runtime: " + runtimeId.getId(), ex);
            throw new RuntimeOperationException("Error Refreshing runtime: " + runtimeId.getId(), ex);
        }
    }
}
Also used : OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException)

Example 3 with OpenShiftRuntimeState

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.

the class OpenShiftClient method getRuntimeState.

private OpenShiftRuntimeState getRuntimeState(OpenShiftRuntimeId runtimeId) {
    String prjName = runtimeId.project();
    String svcName = runtimeId.service();
    String state;
    String startedAt;
    Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
    if (service != null) {
        Integer replicas = getReplicas(service);
        if (replicas != null && replicas.intValue() > 0) {
            state = OpenShiftRuntimeState.RUNNING;
        } else {
            state = OpenShiftRuntimeState.READY;
        }
        startedAt = service.getMetadata().getCreationTimestamp();
    } else {
        state = OpenShiftRuntimeState.UNKNOWN;
        startedAt = new Date().toString();
    }
    return new OpenShiftRuntimeState(state, startedAt);
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Date(java.util.Date)

Example 4 with OpenShiftRuntimeState

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.

the class OpenShiftClient method create.

// Support for OpenShiftRuntimeExecExecutor ------------------------------
public OpenShiftRuntimeState create(OpenShiftRuntimeConfig runtimeConfig) throws OpenShiftClientException {
    try {
        String prjName = runtimeConfig.getProjectName();
        String svcName = runtimeConfig.getServiceName();
        String appName = runtimeConfig.getApplicationName();
        OpenShiftRuntimeId runtimeId = new OpenShiftRuntimeId(prjName, svcName, appName);
        OpenShiftRuntimeState runtimeState = getRuntimeState(runtimeId);
        if (OpenShiftRuntimeState.UNKNOWN.equals(runtimeState.getState())) {
            createProject(prjName);
            createFromUri(prjName, runtimeConfig.getResourceSecretsUri());
            createFromUri(prjName, runtimeConfig.getResourceStreamsUri());
            createFromTemplate(runtimeConfig);
            runtimeState = getRuntimeState(runtimeId);
        }
        if (postCreateListener != null) {
            postCreateListener.trigger(this, runtimeConfig);
        }
        return runtimeState;
    } catch (Throwable t) {
        if (t instanceof OpenShiftClientException) {
            throw (OpenShiftClientException) t;
        } else {
            throw new OpenShiftClientException(t.getMessage(), t);
        }
    }
}
Also used : OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 5 with OpenShiftRuntimeState

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeState in project kie-wb-common by kiegroup.

the class OpenShiftRuntimeMarshallerTest method getValue.

@Override
public OpenShiftRuntime getValue() {
    OpenShiftProvider providerId = createOpenShiftProvider();
    OpenShiftRuntimeConfig runtimeConfig = new ContextAwareOpenShiftRuntimeExecConfig(RUNTIME_NAME, providerId, APPLICATION_NAME, KIE_SERVER_CONTAINER_DEPLOYMENT, PROJECT_NAME, RESOURCE_SECRETS_URI, RESOURCE_STREAMS_URI, RESOURCE_TEMPLATE_NAME, RESOURCE_TEMPLATE_PARAM_DELIMITER, RESOURCE_TEMPLATE_PARAM_ASSIGNER, RESOURCE_TEMPLATE_PARAM_VALUES, RESOURCE_TEMPLATE_URI, SERVICE_NAME);
    return new OpenShiftRuntime(RUNTIME_ID, RUNTIME_NAME, runtimeConfig, providerId, new OpenShiftRuntimeEndpoint(PROTOCOL, HOST, PORT, CONTEXT), new OpenShiftRuntimeInfo(runtimeConfig), new OpenShiftRuntimeState(STATE, STARTED_AT));
}
Also used : ContextAwareOpenShiftRuntimeExecConfig(org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig) OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftProviderImplMarshallerTest.createOpenShiftProvider(org.guvnor.ala.openshift.marshalling.OpenShiftProviderImplMarshallerTest.createOpenShiftProvider) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) OpenShiftRuntimeInfo(org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) OpenShiftRuntimeConfig(org.guvnor.ala.openshift.config.OpenShiftRuntimeConfig)

Aggregations

OpenShiftRuntimeState (org.guvnor.ala.openshift.model.OpenShiftRuntimeState)5 OpenShiftClientException (org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException)3 OpenShiftRuntime (org.guvnor.ala.openshift.model.OpenShiftRuntime)3 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 OpenShiftProvider (org.guvnor.ala.openshift.model.OpenShiftProvider)2 OpenShiftRuntimeEndpoint (org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)2 OpenShiftRuntimeInfo (org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo)2 Service (io.fabric8.kubernetes.api.model.Service)1 Date (java.util.Date)1 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)1 RuntimeOperationException (org.guvnor.ala.exceptions.RuntimeOperationException)1 OpenShiftClient (org.guvnor.ala.openshift.access.OpenShiftClient)1 OpenShiftRuntimeConfig (org.guvnor.ala.openshift.config.OpenShiftRuntimeConfig)1 ContextAwareOpenShiftRuntimeExecConfig (org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig)1 OpenShiftProviderImplMarshallerTest.createOpenShiftProvider (org.guvnor.ala.openshift.marshalling.OpenShiftProviderImplMarshallerTest.createOpenShiftProvider)1