Search in sources :

Example 1 with ControllableServerBehavior

use of org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior in project jbosstools-openshift by jbosstools.

the class CDKRegistryTest method testRegistryURL.

@Test
public void testRegistryURL() throws Exception {
    ConfigureDependentFrameworksListener configureListener = (ConfigureDependentFrameworksListener) CDKCoreActivator.getDefault().getConfigureDependentFrameworksListener();
    configureListener.disable();
    CredentialService.getCredentialModel().addDomain("redhat.com", "redhat.com", true);
    CredentialService.getCredentialModel().addCredentials(CredentialService.getCredentialModel().getDomain("redhat.com"), "user", "password");
    CDKOpenshiftUtility util = new CDKOpenshiftUtility();
    createCDKFile("Basic", null, null);
    IServer cdkServer = createServer("openshift33");
    ServiceManagerEnvironment adb = createLoader(cdkServer);
    IConnection con = util.createOpenshiftConnection(adb, ConnectionsRegistrySingleton.getInstance());
    assertNotNull(con);
    // Can't test the registry provider model bc it hides the internal details
    CDKRegistryProvider prov = new CDKRegistryProvider() {

        protected ServiceManagerEnvironment getServiceManagerEnvironment(IServer server) {
            try {
                return createLoader(server);
            } catch (Exception e) {
                fail(e.getMessage());
            }
            return null;
        }
    };
    IStatus reg = prov.getRegistryURL(con);
    assertNotNull(reg);
    assertFalse(reg.isOK());
    ControllableServerBehavior beh = (ControllableServerBehavior) cdkServer.loadAdapter(ControllableServerBehavior.class, new NullProgressMonitor());
    beh.setServerStarted();
    reg = prov.getRegistryURL(con);
    assertNotNull(reg);
    assertTrue(reg.isOK());
    configureListener.enable();
    beh.setServerStopped();
}
Also used : CDKRegistryProvider(org.jboss.tools.openshift.cdk.server.core.internal.registry.CDKRegistryProvider) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) CDKOpenshiftUtility(org.jboss.tools.openshift.cdk.server.core.internal.listeners.CDKOpenshiftUtility) ServiceManagerEnvironment(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ServiceManagerEnvironment) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) ConfigureDependentFrameworksListener(org.jboss.tools.openshift.cdk.server.core.internal.listeners.ConfigureDependentFrameworksListener) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with ControllableServerBehavior

use of org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior in project jbosstools-openshift by jbosstools.

the class CDKServer method getUsername.

public String getUsername() {
    ControllableServerBehavior beh = (ControllableServerBehavior) getServer().loadAdapter(ControllableServerBehavior.class, new NullProgressMonitor());
    Object user2 = beh.getSharedData(CDKServerBehaviour.PROP_CACHED_USER);
    if (user2 instanceof String)
        return (String) user2;
    String user = getServer().getAttribute(PROP_USERNAME, (String) null);
    if (user == null) {
        ICredentialDomain domain = CredentialService.getCredentialModel().getDomain(CredentialService.REDHAT_ACCESS);
        user = domain.getDefaultUsername();
    }
    return user;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICredentialDomain(org.jboss.tools.foundation.core.credentials.ICredentialDomain) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)

Example 3 with ControllableServerBehavior

use of org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior in project jbosstools-openshift by jbosstools.

the class CDKServer method getPassword.

public String getPassword() throws UsernameChangedException {
    ControllableServerBehavior beh = (ControllableServerBehavior) getServer().loadAdapter(ControllableServerBehavior.class, new NullProgressMonitor());
    Object pw = beh.getSharedData(CDKServerBehaviour.PROP_CACHED_PASSWORD);
    if (pw instanceof String)
        return (String) pw;
    ICredentialDomain domain = CredentialService.getCredentialModel().getDomain(CredentialService.REDHAT_ACCESS);
    String user = getUsername();
    if (user != null && domain != null) {
        try {
            return domain.getCredentials(user);
        } catch (StorageException se) {
            CDKCoreActivator.getDefault().getLog().log(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, se.getMessage(), se));
        } catch (UsernameChangedException uce) {
            if (uce.getSaveCredentials()) {
                saveChangedCredentials(uce);
            }
            throw uce;
        }
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) UsernameChangedException(org.jboss.tools.foundation.core.credentials.UsernameChangedException) ICredentialDomain(org.jboss.tools.foundation.core.credentials.ICredentialDomain) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 4 with ControllableServerBehavior

use of org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior in project jbosstools-openshift by jbosstools.

the class CDK3LaunchController method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    final IServer s = ServerUtil.getServer(configuration);
    if (s == null) {
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate server from launch configuration."));
    }
    final ControllableServerBehavior beh = (ControllableServerBehavior) JBossServerBehaviorUtils.getControllableBehavior(configuration);
    beh.setServerStarting();
    String minishiftLoc = MinishiftBinaryUtility.getMinishiftLocation(s);
    if (minishiftLoc == null || !(new File(minishiftLoc).exists())) {
        beh.setServerStopped();
        if (minishiftLoc == null)
            throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate minishift command. Please set a correct value in the server editor."));
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Expected location of minishift command does not exist: " + minishiftLoc + "\nPlease set a correct value in the server editor."));
    }
    CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    boolean skipReg = cdkServer.skipRegistration();
    if (passCredentials && !skipReg) {
        handleCredentialsDuringLaunch(s, cdkServer, beh);
    }
    // Poll the server once more
    IStatus stat = getCDKPoller(s).getCurrentStateSynchronous(s);
    if (stat.isOK()) {
        beh.setServerStarted();
        ((Server) beh.getServer()).setMode("run");
        return;
    }
    String args = configuration.getAttribute(ATTR_ARGS, (String) null);
    // Add listener first
    IDebugEventSetListener debug = getDebugListener(launch);
    DebugPlugin.getDefault().addDebugEventListener(debug);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.DEBUG_LISTENER, debug);
    Process p = null;
    try {
        CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
        p = new CDKLaunchUtility().callMinishiftConsole(s, args, getStartupLaunchName(s), cdk.skipRegistration());
    } catch (IOException ioe) {
        CDKCoreActivator.pluginLog().logError(ioe);
        beh.setServerStopped();
        DebugPlugin.getDefault().removeDebugEventListener(debug);
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, ioe.getMessage(), ioe));
    }
    if (p == null) {
        beh.setServerStopped();
        DebugPlugin.getDefault().removeDebugEventListener(debug);
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to minishift up has failed."));
    }
    IProcess process = addProcessToLaunch(p, launch, s, false, minishiftLoc);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.PROCESS, process);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer) Server(org.eclipse.wst.server.core.internal.Server) CDK3Server(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDK3Server) IServer(org.eclipse.wst.server.core.IServer) CDK32Server(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDK32Server) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) CoreException(org.eclipse.core.runtime.CoreException) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Example 5 with ControllableServerBehavior

use of org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior in project jbosstools-openshift by jbosstools.

the class CDKLaunchController method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    final IServer s = ServerUtil.getServer(configuration);
    verifyServer(s);
    final ControllableServerBehavior beh = (ControllableServerBehavior) JBossServerBehaviorUtils.getControllableBehavior(configuration);
    beh.setServerStarting();
    String vagrantLoc = VagrantBinaryUtility.getVagrantLocation(s);
    if (vagrantLoc == null || !(new File(vagrantLoc).exists())) {
        beh.setServerStopped();
        if (vagrantLoc == null)
            throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Unable to locate vagrant command. Please check the server's launch configuration on the 'Environment' tab to ensure that the command is available on your Path environment variable."));
        throw new CoreException(CDKCoreActivator.statusFactory().errorStatus("Expected location of vagrant command does not exist: " + vagrantLoc));
    }
    CDKServer cdkServer = (CDKServer) s.loadAdapter(CDKServer.class, new NullProgressMonitor());
    boolean passCredentials = cdkServer.passCredentials();
    boolean skipReg = cdkServer.skipRegistration();
    if (passCredentials && !skipReg) {
        setBehaviourUserAndPassword(s, beh, cdkServer);
    }
    // Poll the server once more
    IStatus stat = getCDKPoller(s).getCurrentStateSynchronous(s);
    if (stat.isOK()) {
        beh.setServerStarted();
        ((Server) beh.getServer()).setMode(ILaunchManager.RUN_MODE);
        return;
    }
    String args = configuration.getAttribute(ATTR_ARGS, (String) null);
    CDKServer cdk = (CDKServer) getServer().loadAdapter(CDKServer.class, new NullProgressMonitor());
    Process p = getProcess(s, beh, args, cdk.skipRegistration());
    if (p == null) {
        beh.setServerStopped();
        throw new CoreException(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, "Call to vagrant up has failed."));
    }
    IProcess process = addProcessToLaunch(p, launch, s, true);
    IDebugEventSetListener debug = getDebugListener(new IProcess[] { process }, launch);
    DebugPlugin.getDefault().addDebugEventListener(debug);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.PROCESS, process);
    beh.putSharedData(AbstractStartJavaServerLaunchDelegate.DEBUG_LISTENER, debug);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer) Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) IProcess(org.eclipse.debug.core.model.IProcess) IDebugEventSetListener(org.eclipse.debug.core.IDebugEventSetListener) CoreException(org.eclipse.core.runtime.CoreException) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) IControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) CDKServer(org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)

Aggregations

ControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)9 IStatus (org.eclipse.core.runtime.IStatus)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IServer (org.eclipse.wst.server.core.IServer)5 Server (org.eclipse.wst.server.core.internal.Server)4 IControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior)4 CoreException (org.eclipse.core.runtime.CoreException)3 Status (org.eclipse.core.runtime.Status)3 CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)3 File (java.io.File)2 IOException (java.io.IOException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 IDebugEventSetListener (org.eclipse.debug.core.IDebugEventSetListener)2 IProcess (org.eclipse.debug.core.model.IProcess)2 ICredentialDomain (org.jboss.tools.foundation.core.credentials.ICredentialDomain)2 URISyntaxException (java.net.URISyntaxException)1 StorageException (org.eclipse.equinox.security.storage.StorageException)1 PollThread (org.jboss.ide.eclipse.as.core.server.internal.PollThread)1 UsernameChangedException (org.jboss.tools.foundation.core.credentials.UsernameChangedException)1