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);
}
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();
}
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();
}
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())));
}
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;
}
Aggregations