Search in sources :

Example 16 with ServiceManagerEnvironment

use of org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment in project jbosstools-openshift by jbosstools.

the class CDKRegistryProvider method findServer.

private Pair findServer(IConnection connection) {
    CDKOpenshiftUtility util = new CDKOpenshiftUtility();
    IServer[] all = ServerCore.getServers();
    MultiStatus ms = new MultiStatus(CDKCoreActivator.PLUGIN_ID, 0, "CDKRegistryProvider unable to locate a registry URL for openshift connection " + connection.toString(), null);
    if (all.length == 0) {
        ms.add(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "No Servers exist in the workspace."));
    }
    boolean foundMinishift = false;
    for (int i = 0; i < all.length; i++) {
        ServiceManagerEnvironment env = getServiceManagerEnvironment(all[i]);
        ServiceManagerEnvironmentLoader type = ServiceManagerEnvironmentLoader.type(all[i]);
        if (type.getType() != ServiceManagerEnvironmentLoader.TYPE_MINISHIFT) {
            continue;
        }
        foundMinishift = true;
        if (all[i].getServerState() != IServer.STATE_STARTED) {
            ms.add(new Status(IStatus.INFO, CDKCoreActivator.PLUGIN_ID, "Unable to locate the CDK environment details for stopped server " + all[i].getName()));
            continue;
        }
        if (env == null) {
            ms.add(new Status(IStatus.INFO, CDKCoreActivator.PLUGIN_ID, "Unable to locate the CDK environment details for server " + all[i].getName()));
            continue;
        }
        if (!util.serverMatchesConnection(all[i], connection, env)) {
            ms.add(util.serverConnectionMatchError(all[i], connection, env));
            continue;
        }
        String registry = env.getDockerRegistry();
        if (registry == null || registry.isEmpty()) {
            String s = "Server {0} does not have a registry associated with it. Please verify that 'minishift openshift registry' returns a valid URL.";
            ms.add(new Status(IStatus.INFO, CDKCoreActivator.PLUGIN_ID, NLS.bind(s, all[i].getName())));
            continue;
        }
        return new Pair(null, all[i]);
    }
    if (all.length > 0 && !foundMinishift) {
        ms.add(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "No valid CDK Servers exist in the workspace."));
    }
    return new Pair(ms, null);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IServer(org.eclipse.wst.server.core.IServer) CDKOpenshiftUtility(org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility) ServiceManagerEnvironment(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment) MultiStatus(org.eclipse.core.runtime.MultiStatus) ServiceManagerEnvironmentLoader(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironmentLoader)

Aggregations

ServiceManagerEnvironment (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment)16 Test (org.junit.Test)13 IServer (org.eclipse.wst.server.core.IServer)7 CDKOpenshiftUtility (org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility)6 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)5 ConnectionsRegistry (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry)3 IStatus (org.eclipse.core.runtime.IStatus)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 CoreException (org.eclipse.core.runtime.CoreException)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)1 ControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)1 ConfigureDependentFrameworksListener (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ConfigureDependentFrameworksListener)1 ServiceManagerEnvironmentLoader (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironmentLoader)1 CDKRegistryProvider (org.jboss.tools.openshift.cdk.server.core.internal.registry.CDKRegistryProvider)1