Search in sources :

Example 6 with Server

use of org.eclipse.wst.server.core.internal.Server 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)

Example 7 with Server

use of org.eclipse.wst.server.core.internal.Server in project jbosstools-openshift by jbosstools.

the class CDKLaunchController method handleOpenShiftUnavailable.

private void handleOpenShiftUnavailable(final IControllableServerBehavior beh, final OpenShiftNotReadyPollingException osnrpe) {
    // Log error?  Show dialog?
    ((ControllableServerBehavior) beh).setServerStarted();
    ((Server) beh.getServer()).setMode(ILaunchManager.RUN_MODE);
    new Job(osnrpe.getMessage()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            return CDKCoreActivator.statusFactory().errorStatus("Error contacting OpenShift", osnrpe);
        }
    }.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) 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) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) IControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior) Job(org.eclipse.core.runtime.jobs.Job)

Example 8 with Server

use of org.eclipse.wst.server.core.internal.Server in project jbosstools-openshift by jbosstools.

the class AbstractCDKLaunchController method handleOpenShiftUnavailable.

private void handleOpenShiftUnavailable(final IControllableServerBehavior beh, final OpenShiftNotReadyPollingException osnrpe) {
    // Log error?  Show dialog?
    ((ControllableServerBehavior) beh).setServerStarted();
    ((Server) beh.getServer()).setMode("run");
    new Job(osnrpe.getMessage()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            return CDKCoreActivator.statusFactory().errorStatus("Error contacting OpenShift", osnrpe);
        }
    }.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) IControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior) Job(org.eclipse.core.runtime.jobs.Job)

Example 9 with Server

use of org.eclipse.wst.server.core.internal.Server in project jbosstools-openshift by jbosstools.

the class OpenShiftLaunchController method mapPortForwarding.

/**
 * Map the remote port to a local port.
 * Return the local port in use, or -1 if failed
 * @param server
 * @param remotePort
 * @return the local debug port or -1 if port forwarding did not start or was cancelled.
 * @throws CoreException
 */
protected int mapPortForwarding(final DebugContext context, final IProgressMonitor monitor) throws CoreException {
    monitor.subTask("Starting port forwarding...");
    IPod pod = context.getPod();
    if (pod == null) {
        throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could not find running pod to forward to in server adapter \"{0}\"", getServer().getName())));
    }
    Set<PortPair> podPorts = PortForwardingUtils.getForwardablePorts(pod);
    int remotePort = context.getDebugPort();
    if (remotePort == DebugContext.NO_DEBUG_PORT) {
        throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("No pod port to forward to specified in server adapter \"{0}\"", getServer().getName())));
    }
    Optional<PortPair> debugPort = podPorts.stream().filter(p -> remotePort == p.getRemotePort()).findFirst();
    if (!debugPort.isPresent()) {
        throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Pod port specified in server adapter \"{0}\" is not present in pod \"{1}\"", getServer().getName(), pod.getName())));
    }
    if (PortForwardingUtils.isPortForwardingStarted(pod)) {
        return debugPort.get().getLocalPort();
    }
    if (mapPorts(podPorts, monitor)) {
        PortForwardingUtils.startPortForwarding(pod, podPorts, IBinaryCapability.SKIP_TLS_VERIFY);
        if (PortForwardingUtils.isPortForwardingStarted(pod)) {
            return debugPort.get().getLocalPort();
        }
    }
    throw new CoreException(StatusFactory.errorStatus(OpenShiftCoreActivator.PLUGIN_ID, NLS.bind("Could not setup port forwarding to pod \"{0}\" in server adapter \"{1}\"", pod.getName(), getServer().getName())));
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) PortForwardingUtils(org.jboss.tools.openshift.internal.core.portforwarding.PortForwardingUtils) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) CoreException(org.eclipse.core.runtime.CoreException) IDebugListener(org.jboss.tools.openshift.internal.core.server.debug.IDebugListener) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DebugException(org.eclipse.debug.core.DebugException) IStatus(org.eclipse.core.runtime.IStatus) Server(org.eclipse.wst.server.core.internal.Server) ILaunch(org.eclipse.debug.core.ILaunch) AbstractSubsystemController(org.jboss.ide.eclipse.as.wtp.core.server.behavior.AbstractSubsystemController) StatusFactory(org.jboss.tools.foundation.core.plugin.log.StatusFactory) SocketUtil(org.eclipse.jdt.launching.SocketUtil) NLS(org.eclipse.osgi.util.NLS) ClassCollectingHCRListener(org.jboss.ide.eclipse.as.core.util.ClassCollectingHCRListener) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) OpenShiftServerBehaviour(org.jboss.tools.openshift.core.server.OpenShiftServerBehaviour) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) ILaunchManager(org.eclipse.debug.core.ILaunchManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) IBinaryCapability(com.openshift.restclient.capability.IBinaryCapability) Optional(java.util.Optional) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) IReplicationController(com.openshift.restclient.model.IReplicationController) OpenShiftDebugMode(org.jboss.tools.openshift.internal.core.server.debug.OpenShiftDebugMode) DockerImageLabels(org.jboss.tools.openshift.core.server.DockerImageLabels) IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) OpenShiftServerUtils.toCoreException(org.jboss.tools.openshift.core.server.OpenShiftServerUtils.toCoreException) IPod(com.openshift.restclient.model.IPod) ServerProcess(org.jboss.ide.eclipse.as.wtp.core.server.launch.ServerProcess) IProject(org.eclipse.core.resources.IProject) IModule(org.eclipse.wst.server.core.IModule) DebugLaunchConfigs(org.jboss.tools.openshift.internal.core.server.debug.DebugLaunchConfigs) IJavaDebugTarget(org.eclipse.jdt.debug.core.IJavaDebugTarget) IResource(com.openshift.restclient.model.IResource) Job(org.eclipse.core.runtime.jobs.Job) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IJavaHotCodeReplaceListener(org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener) OpenShiftCoreMessages(org.jboss.tools.openshift.core.OpenShiftCoreMessages) Connection(org.jboss.tools.openshift.core.connection.Connection) DebugContext(org.jboss.tools.openshift.internal.core.server.debug.DebugContext) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) ILaunchServerController(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ILaunchServerController) ISubsystemController(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ISubsystemController) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftServerUtils.toCoreException(org.jboss.tools.openshift.core.server.OpenShiftServerUtils.toCoreException) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) IPod(com.openshift.restclient.model.IPod)

Example 10 with Server

use of org.eclipse.wst.server.core.internal.Server in project webtools.servertools by eclipse.

the class GlobalCommandManager method getReadOnlyFiles.

/**
 * Return an array of read-only files.
 *
 * @param server a server
 * @return a possibly empty array of files
 */
public static IFile[] getReadOnlyFiles(IServerAttributes server) {
    try {
        List<IFile> list = new ArrayList<IFile>();
        IFile file = ((Server) server).getFile();
        if (file != null)
            list.add(file);
        IFile[] files = new IFile[list.size()];
        list.toArray(files);
        return files;
    } catch (Exception e) {
        if (Trace.SEVERE) {
            Trace.trace(Trace.STRING_SEVERE, "getReadOnlyFiles", e);
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) Server(org.eclipse.wst.server.core.internal.Server) ArrayList(java.util.ArrayList) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

Server (org.eclipse.wst.server.core.internal.Server)23 IServer (org.eclipse.wst.server.core.IServer)17 IStatus (org.eclipse.core.runtime.IStatus)11 CoreException (org.eclipse.core.runtime.CoreException)7 IOException (java.io.IOException)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Job (org.eclipse.core.runtime.jobs.Job)4 ControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)4 File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 Status (org.eclipse.core.runtime.Status)3 IServerType (org.eclipse.wst.server.core.IServerType)3 IMemento (org.eclipse.wst.server.core.internal.IMemento)3 IControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.IControllableServerBehavior)3 CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)3 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IDebugEventSetListener (org.eclipse.debug.core.IDebugEventSetListener)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2