Search in sources :

Example 6 with OpenShiftClientException

use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException 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 7 with OpenShiftClientException

use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException in project kie-wb-common by kiegroup.

the class OpenShiftClient method getRuntimeEndpoint.

public OpenShiftRuntimeEndpoint getRuntimeEndpoint(String id) throws OpenShiftClientException {
    try {
        OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
        String prjName = runtimeId.project();
        String svcName = runtimeId.service();
        OpenShiftRuntimeEndpoint endpoint = new OpenShiftRuntimeEndpoint();
        Route route = delegate.routes().inNamespace(prjName).withName(svcName).get();
        if (route != null) {
            RouteSpec routeSpec = route.getSpec();
            endpoint.setProtocol(routeSpec.getTls() != null ? "https" : "http");
            endpoint.setHost(routeSpec.getHost());
            RoutePort routePort = routeSpec.getPort();
            if (routePort != null) {
                IntOrString targetPort = routePort.getTargetPort();
                if (targetPort != null) {
                    endpoint.setPort(targetPort.getIntVal());
                }
            }
        }
        return endpoint;
    } catch (Throwable t) {
        throw new OpenShiftClientException(t.getMessage(), t);
    }
}
Also used : RoutePort(io.fabric8.openshift.api.model.RoutePort) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) Route(io.fabric8.openshift.api.model.Route)

Example 8 with OpenShiftClientException

use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException 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 9 with OpenShiftClientException

use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException in project kie-wb-common by kiegroup.

the class OpenShiftClient method destroy.

public void destroy(String id) throws OpenShiftClientException {
    try {
        OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
        String prjName = runtimeId.project();
        String svcName = runtimeId.service();
        // TODO: should we always depend on the app label being specified, or gotten from the service?
        String appName = runtimeId.application();
        if (appName == null || appName.isEmpty()) {
            Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
            if (service != null) {
                appName = service.getMetadata().getLabels().get(APP_LABEL);
            }
        }
        /*
             * cascading delete of deploymentConfigs means we don't have to also do the following:
             *     delegate.deploymentConfigs().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
             *     delegate.replicationControllers().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
             *     delegate.pods().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
             * , but deleting services and routes are still necessary:
             */
        delegate.deploymentConfigs().inNamespace(prjName).withName(svcName).cascading(true).delete();
        if (appName != null) {
            delegate.services().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
            delegate.routes().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
        } else {
            delegate.services().inNamespace(prjName).delete();
            delegate.routes().inNamespace(prjName).delete();
        }
        // clean up any generated image streams, secrets, and service accounts
        for (ImageStream item : delegate.imageStreams().inNamespace(prjName).list().getItems()) {
            if (isGuvnorAlaGenerated(item)) {
                delegate.imageStreams().inNamespace(prjName).delete(item);
            }
        }
        for (Secret item : delegate.secrets().inNamespace(prjName).list().getItems()) {
            if (isGuvnorAlaGenerated(item)) {
                delegate.secrets().inNamespace(prjName).delete(item);
            }
        }
        for (ServiceAccount item : delegate.serviceAccounts().inNamespace(prjName).list().getItems()) {
            if (isGuvnorAlaGenerated(item)) {
                delegate.serviceAccounts().inNamespace(prjName).delete(item);
            }
        }
        // clean up generated project
        if (isGuvnorAlaGenerated(delegate.projects().withName(prjName).get())) {
            delegate.projects().withName(prjName).delete();
        }
    } catch (Throwable t) {
        throw new OpenShiftClientException(t.getMessage(), t);
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Service(io.fabric8.kubernetes.api.model.Service) ImageStream(io.fabric8.openshift.api.model.ImageStream) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 10 with OpenShiftClientException

use of org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException in project kie-wb-common by kiegroup.

the class OpenShiftRuntimeManager method restart.

@Override
public void restart(RuntimeId runtimeId) throws RuntimeOperationException {
    OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId());
    try {
        LOG.info("Restarting runtime: " + runtimeId.getId());
        openshift.getOpenShiftClient(runtime.getProviderId()).restart(runtime.getId());
        refresh(runtimeId);
        LOG.info("Restarted runtime: " + runtimeId.getId());
    } catch (OpenShiftClientException ex) {
        LOG.error("Error Restarting runtime: " + runtimeId.getId(), ex);
        throw new RuntimeOperationException("Error Restarting 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)

Aggregations

OpenShiftClientException (org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException)11 RuntimeOperationException (org.guvnor.ala.exceptions.RuntimeOperationException)6 OpenShiftRuntime (org.guvnor.ala.openshift.model.OpenShiftRuntime)6 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)4 OpenShiftRuntimeState (org.guvnor.ala.openshift.model.OpenShiftRuntimeState)3 OpenShiftProvider (org.guvnor.ala.openshift.model.OpenShiftProvider)2 OpenShiftRuntimeEndpoint (org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)2 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 Service (io.fabric8.kubernetes.api.model.Service)1 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 DoneableDeploymentConfig (io.fabric8.openshift.api.model.DoneableDeploymentConfig)1 ImageStream (io.fabric8.openshift.api.model.ImageStream)1 Route (io.fabric8.openshift.api.model.Route)1 RoutePort (io.fabric8.openshift.api.model.RoutePort)1 RouteSpec (io.fabric8.openshift.api.model.RouteSpec)1 LinkedHashMap (java.util.LinkedHashMap)1 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)1 OpenShiftClient (org.guvnor.ala.openshift.access.OpenShiftClient)1