Search in sources :

Example 1 with ServiceManagerEnvironmentLoader

use of org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironmentLoader 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

IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 IServer (org.eclipse.wst.server.core.IServer)1 CDKOpenshiftUtility (org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility)1 ServiceManagerEnvironment (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment)1 ServiceManagerEnvironmentLoader (org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironmentLoader)1