Search in sources :

Example 1 with OpenShiftRuntime

use of org.guvnor.ala.openshift.model.OpenShiftRuntime 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 OpenShiftRuntime

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

the class OpenShiftRuntimeManager method pause.

@Override
public void pause(RuntimeId runtimeId) throws RuntimeOperationException {
    OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        LOG.info("Pausing runtime: " + runtimeId.getId());
        openshift.getOpenShiftClient(runtime.getProviderId()).pause(runtime.getId());
        refresh(runtimeId);
        LOG.info("Paused runtime: " + runtimeId.getId());
    } catch (OpenShiftClientException ex) {
        LOG.error("Error Pausing runtime: " + runtimeId.getId(), ex);
        throw new RuntimeOperationException("Error Pausing runtime: " + runtimeId.getId(), ex);
    }
}
Also used : OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException)

Example 3 with OpenShiftRuntime

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

the class OpenShiftRuntimeManager method stop.

@Override
public void stop(RuntimeId runtimeId) throws RuntimeOperationException {
    OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        LOG.info("Stopping runtime: " + runtimeId.getId());
        openshift.getOpenShiftClient(runtime.getProviderId()).stop(runtime.getId());
        refresh(runtimeId);
        LOG.info("Stopped runtime: " + runtimeId.getId());
    } catch (OpenShiftClientException ex) {
        LOG.error("Error Stopping runtime: " + runtimeId.getId(), ex);
        throw new RuntimeOperationException("Error Stopping runtime: " + runtimeId.getId(), ex);
    }
}
Also used : OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) RuntimeOperationException(org.guvnor.ala.exceptions.RuntimeOperationException)

Example 4 with OpenShiftRuntime

use of org.guvnor.ala.openshift.model.OpenShiftRuntime 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 5 with OpenShiftRuntime

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

the class RuntimeEndpointsTestIT method checkOpenShiftService.

/**
 * Can be used if internal to red hat.
 * TODO: replace with more lightweight image and non-internal (minishift?) environment
 * @throws Exception
 */
@Ignore
public void checkOpenShiftService() throws Exception {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(APP_URL);
    ResteasyWebTarget restEasyTarget = (ResteasyWebTarget) target;
    RuntimeProvisioningService proxy = restEasyTarget.proxy(RuntimeProvisioningService.class);
    ProviderTypeList allProviderTypes = proxy.getProviderTypes(0, 10, "", true);
    assertNotNull(allProviderTypes);
    assertEquals(3, allProviderTypes.getItems().size());
    OpenShiftProviderConfigImpl openshiftProviderConfig = createProviderConfig();
    proxy.registerProvider(openshiftProviderConfig);
    ProviderList allProviders = proxy.getProviders(0, 10, "", true);
    assertEquals(1, allProviders.getItems().size());
    assertTrue(allProviders.getItems().get(0) instanceof OpenShiftProvider);
    OpenShiftProvider openshiftProvider = (OpenShiftProvider) allProviders.getItems().get(0);
    OpenShiftRuntimeConfig runtimeConfig = createRuntimeConfig(openshiftProvider, "coss1");
    @SuppressWarnings("unused") OpenShiftRuntime openshiftRuntime = getOpenShiftRuntime(proxy, 0, null);
    String runtimeId = proxy.newRuntime(runtimeConfig);
    openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.READY);
    proxy.startRuntime(runtimeId);
    openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.RUNNING);
    proxy.stopRuntime(runtimeId);
    openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.READY);
    proxy.destroyRuntime(runtimeId, true);
    openshiftRuntime = getOpenShiftRuntime(proxy, 0, null);
}
Also used : ProviderList(org.guvnor.ala.services.api.itemlist.ProviderList) RuntimeProvisioningService(org.guvnor.ala.services.api.RuntimeProvisioningService) OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) OpenShiftProviderConfigImpl(org.guvnor.ala.openshift.config.impl.OpenShiftProviderConfigImpl) ProviderTypeList(org.guvnor.ala.services.api.itemlist.ProviderTypeList) OpenShiftRuntimeConfig(org.guvnor.ala.openshift.config.OpenShiftRuntimeConfig) Ignore(org.junit.Ignore)

Aggregations

OpenShiftRuntime (org.guvnor.ala.openshift.model.OpenShiftRuntime)11 OpenShiftClientException (org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException)6 RuntimeOperationException (org.guvnor.ala.exceptions.RuntimeOperationException)5 OpenShiftProvider (org.guvnor.ala.openshift.model.OpenShiftProvider)3 OpenShiftRuntimeEndpoint (org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)3 OpenShiftRuntimeState (org.guvnor.ala.openshift.model.OpenShiftRuntimeState)3 Runtime (org.guvnor.ala.runtime.Runtime)3 OpenShiftRuntimeConfig (org.guvnor.ala.openshift.config.OpenShiftRuntimeConfig)2 ContextAwareOpenShiftRuntimeExecConfig (org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig)2 OpenShiftRuntimeInfo (org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo)2 Client (javax.ws.rs.client.Client)1 WebTarget (javax.ws.rs.client.WebTarget)1 DockerRuntime (org.guvnor.ala.docker.model.DockerRuntime)1 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)1 OpenShiftAccessInterface (org.guvnor.ala.openshift.access.OpenShiftAccessInterface)1 OpenShiftClient (org.guvnor.ala.openshift.access.OpenShiftClient)1 OpenShiftAccessInterfaceImpl (org.guvnor.ala.openshift.access.impl.OpenShiftAccessInterfaceImpl)1 OpenShiftParameters (org.guvnor.ala.openshift.config.OpenShiftParameters)1 OpenShiftProviderConfig (org.guvnor.ala.openshift.config.OpenShiftProviderConfig)1 OpenShiftRuntimeExecConfig (org.guvnor.ala.openshift.config.OpenShiftRuntimeExecConfig)1