public String[] getServerIds() { List<String> list = new ArrayList<String>(); for (IServer server : getServers()) { list.add(server.getId()); } return list.toArray(new String[] {}); }
public void serverChanged(ServerEvent event) { final IServer server = event.getServer(); JBossServer jbs = (JBossServer) server.loadAdapter(JBossServer.class, new NullProgressMonitor()); if (jbs != null && serverSwitchesToState(event, IServer.STATE_STARTING)) { // do not launch console for remotes, for now String type = ServerProfileModel.getProfile(server); if (!ServerProfileModel.DEFAULT_SERVER_PROFILE.equals(type)) return; new Thread() { public void run() { try { // delay to insure the server gets a chance to actually launch Thread.sleep(3000); } catch (InterruptedException ie) { } Display.getDefault() .asyncExec( new Runnable() { public void run() { ILaunch launch = server.getLaunch(); if (launch != null && launch.getProcesses().length > 0) new ShowInConsoleAction(getNullSelectionProvider()).perform(server); } }); } }.start(); } }
/** * retrieve all needed information to connect to JMX server * * @param server * @return */ public static String getJMXConnectionURL(IServer server) { String retVal = ""; BaseConfigPropertyProvider manProv = new BaseConfigPropertyProvider( server .getRuntime() .getLocation() .append("etc") .append("org.apache.karaf.management.cfg") .toFile()); BaseConfigPropertyProvider sysProv = new BaseConfigPropertyProvider( server.getRuntime().getLocation().append("etc").append("system.properties").toFile()); String url = manProv.getConfigurationProperty("serviceUrl"); if (url == null) return null; url = url.trim(); int pos = -1; while ((pos = url.indexOf("${")) != -1) { retVal += url.substring(0, pos); String placeHolder = url.substring(url.indexOf("${") + 2, url.indexOf("}")).trim(); String replacement = manProv.getConfigurationProperty(placeHolder); if (replacement == null) { replacement = sysProv.getConfigurationProperty(placeHolder); } if (replacement == null) { return null; } else { retVal += replacement.trim(); url = url.substring(pos + placeHolder.length() + 3); } } return retVal; }
public static DeployableServerBehavior getServerBehavior(ILaunchConfiguration configuration) throws CoreException { IServer server = ServerUtil.getServer(configuration); DeployableServerBehavior jbossServerBehavior = (DeployableServerBehavior) server.getAdapter(DeployableServerBehavior.class); return jbossServerBehavior; }
public boolean stopServer(String serverId) { IServer server = getServer(serverId); if (server == null) return false; else { server.stop(false); return true; } }
public static String[] getServerIdForProject(IProject project) { List<String> serverIds = new ArrayList<String>(); IServer[] serversForProject = getServersForProject(project); for (IServer server : serversForProject) { serverIds.add(server.getId()); } return serverIds.toArray(new String[] {}); }
private boolean hasURL() { IServer server = getServer(); ServerExtendedProperties props = (ServerExtendedProperties) server.loadAdapter(ServerExtendedProperties.class, new NullProgressMonitor()); if (props != null) return props.hasWelcomePage(); return false; }
public static ICarbonOperationManager getServerOperationManager(String serverId) { IServer server = getServer(serverId); if (getServerPlugin().containsKey(server.getServerType().getId())) return getServerPlugin().get(server.getServerType().getId()); else { return null; } }
/** * @param server that associates to a {@link CloudFoundryServer} * @return non-null {@link CloudFoundryServer} * @throws CoreException if server is not a {@link CloudFoundryServer} or error occurred while * resolving Cloud server */ public static CloudFoundryServer getCloudServer(IServer server) throws CoreException { CloudFoundryServer cfServer = (CloudFoundryServer) server.getAdapter(CloudFoundryServer.class); if (cfServer == null) { throw CloudErrorUtil.toCoreException( NLS.bind( Messages.CloudServerUtil_NOT_CLOUD_SERVER_ERROR, server.getName(), server.getId())); } return cfServer; }
public static IServer getRunningServer() { IServer server = null; for (IServer s : getServers()) { if (s.getServerState() == IServer.STATE_STARTED) { server = s; break; } } return server; }
public void configureLaunch(final ILaunch launch) throws CoreException { final IServer server = ServerUtil.getServer(configuration); server.addServerListener( new IServerListener() { IModule[] modules = server.getModules(); private boolean modulesChanged(IModule[] modules, IModule[] modules2) { if (CoreUtil.isNullOrEmpty(modules) && CoreUtil.isNullOrEmpty(modules2)) { return true; } if (CoreUtil.isNullOrEmpty(modules) || CoreUtil.isNullOrEmpty(modules2)) { return true; } if (modules.length != modules2.length) { return true; } for (int i = 0; i < modules.length; i++) { if (!modules[i].equals(modules2[i])) { return true; } } return false; } public synchronized void serverChanged(ServerEvent event) { if ((event.getKind() & ServerEvent.MODULE_CHANGE) > 0) { IModule[] newModules = event.getServer().getModules(); if (modulesChanged(modules, newModules)) { try { final PortalSourceLookupDirector director = (PortalSourceLookupDirector) launch.getSourceLocator(); director.initializeDefaults(configuration); } catch (Exception e) { LiferayServerCore.logError( "Unable to update source containers for server", e); // $NON-NLS-1$ } modules = newModules; } } } }); final ISourcePathComputer sourcePathComputer = getLaunchManager().getSourcePathComputer(this.sourceComputerId); this.setSourcePathComputer(sourcePathComputer); this.initializeDefaults(configuration); launch.setSourceLocator(this); }
public static IServer[] getServersForProject(IProject project) { List<IServer> serverIds = new ArrayList<IServer>(); for (IServer server : getServers()) { for (IModule module : server.getModules()) { if (module.getProject() == project) { serverIds.add(server); } } } return serverIds.toArray(new IServer[] {}); }
@Test public void shouldStopRunningServerWhenStoppingBundler() throws Exception { // pre-condition: create a first server (no need for script injection) createAndLaunchLiveReloadServer("Server 1", false); assertThat(liveReloadServer.getServerState()).isEqualTo(IServer.STATE_STARTED); // operation: stop the core bundle JBossLiveReloadCoreActivator.getDefault() .stop(JBossLiveReloadCoreActivator.getDefault().getBundle().getBundleContext()); // verification assertThat(liveReloadServer.getServerState()).isEqualTo(IServer.STATE_STOPPED); }
public void serverChanged(ServerEvent event) { IServer s = event.getServer(); JBossExtendedProperties props = (JBossExtendedProperties) s.loadAdapter(JBossExtendedProperties.class, null); if (props != null && props.getMultipleDeployFolderSupport() == ServerExtendedProperties.DEPLOYMENT_SCANNER_AS7_MANAGEMENT_SUPPORT) { if (serverSwitchesToState(event, IServer.STATE_STARTED)) { // Don't do any potentially long-running tasks here. launchJob(s); } } }
public void waitModuleStarted(IServer server, IModule[] module, IProgressMonitor monitor) { if (module.length == 0 || module[0] == null) return; try { String deploymentName = getDeploymentName(server, module[0]); boolean waitedOnce = false; while (!monitor.isCanceled()) { boolean done = isRootModuleStarted(server, module[0], deploymentName, monitor); if (done) { return; } if (!waitedOnce) { String info = "Module {0} on {1} not yet fully deployed. Waiting..."; // $NON-NLS-1$ IStatus s = new Status( IStatus.INFO, JBossServerCorePlugin.PLUGIN_ID, NLS.bind(info, module[0].getName(), server.getName()), null); ServerLogger.getDefault().log(server, s); } waitedOnce = true; try { Thread.sleep(2000); } catch (InterruptedException ie) { // Ignore, intentional } } String warning = "Module {0} on {1} still not ready to be shown in browser. Aborting delay."; //$NON-NLS-1$ IStatus s = new Status( IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, NLS.bind(warning, module[0].getName(), server.getName()), null); ServerLogger.getDefault().log(server, s); } catch (Exception e) { String er = "Error occurred while waiting for {0} to start on server {1}"; // $NON-NLS-1$ IStatus s = new Status( IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, NLS.bind(er, module[0].getName(), server.getName()), e); ServerLogger.getDefault().log(server, s); } }
@Test public void testMetadata() { try { IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType); IServerWorkingCopy wc = s.createWorkingCopy(); wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_METADATA); s = wc.save(true, null); String[] folders = getAdditions().getDeployLocationFolders(s); assertEquals(1, folders.length); assertTrue(folders[0].contains("metadata")); } catch (CoreException ce) { fail("Unable to save changes to server"); } }
public SshConnector(IServer server) { super(); this.server = server; this.behaviorDelegate = (IControllableServerBehavior) server.loadAdapter(IControllableServerBehavior.class, new NullProgressMonitor()); IKarafServerDelegate config = (IKarafServerDelegate) server.loadAdapter(IKarafServerDelegate.class, new NullProgressMonitor()); this.host = server.getHost(); this.port = config.getPortNumber(); this.userName = config.getUserName(); this.passwd = config.getPassword(); }
@Test public void testMetadataWithCustomModule() { try { // Create the server IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType); IServerWorkingCopy wc = s.createWorkingCopy(); wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_METADATA); s = wc.save(true, null); // Create the project projNum++; String projName = "Project" + projNum; IDataModel dm = CreateProjectOperationsUtility.getWebDataModel( projName, null, null, null, null, JavaEEFacetConstants.WEB_24, false); try { OperationTestCase.runAndVerify(dm); } catch (Exception e) { fail("Unable to create test web project: " + e.getMessage()); } IProject p = ResourceUtils.findProject(projName); assertTrue(p.exists()); IModule projMod = ServerUtil.getModule(p); // Set the custom setting. For now, just override output name wc = s.createWorkingCopy(); AbstractPublishingTest.setCustomDeployOverride(wc, projMod, "newName.war", null, null); s = wc.save(true, null); // verify no change vs standard metadata String[] folders = getAdditions().getDeployLocationFolders(s); assertEquals(1, folders.length); assertTrue(folders[0].contains("metadata")); // Change it to now make some other output folder wc = s.createWorkingCopy(); AbstractPublishingTest.setCustomDeployOverride( wc, projMod, "newName.war", "/home/user/deploy", null); s = wc.save(true, null); folders = getAdditions().getDeployLocationFolders(s); assertEquals(2, folders.length); assertTrue(folders[0].contains("metadata")); assertTrue(folders[1].equals("/home/user/deploy")); } catch (CoreException ce) { fail("Unable to save changes to server"); } }
/** * Returns list of cloud foundry server instances. May be emtpy, but not null. * * @return returns a non-null list of cloud foundry server instances. May be empty. */ public static List<CloudFoundryServer> getCloudServers() { IServer[] servers = ServerCore.getServers(); Set<CloudFoundryServer> matchedServers = new HashSet<CloudFoundryServer>(); if (servers != null) { for (IServer server : servers) { CloudFoundryServer cfServer = (CloudFoundryServer) server.loadAdapter(CloudFoundryServer.class, null); if (cfServer != null) { matchedServers.add(cfServer); } } } return new ArrayList<CloudFoundryServer>(matchedServers); }
public static ILiferayRuntime getLiferayRuntime(IServer server) { if (server != null) { return getLiferayRuntime(server.getRuntime()); } return null; }
public static IRemoteServer getRemoteServer(IServer server) { if (server != null) { return (IRemoteServer) server.loadAdapter(IRemoteServer.class, null); } return null; }
private boolean hasParentInServer(IProject project, IServer server, IProgressMonitor pm) { IModule[] modules = ServerUtil.getModules(project); if (modules == null || modules.length == 0) { return false; } IModule[] parents = null; boolean parentFound = false; for (IModule module : modules) { try { parents = server.getRootModules(module, pm); } catch (CoreException e) { org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e); } if (parents == null || parents.length == 0) { return false; } for (IModule parent : parents) { if (!parent.equals(module) && ServerUtil.containsModule(server, parent, pm)) { parentFound = true; break; } } } return parentFound; }
/** * @param serverID unique ID of the server. This should not just be the name of the server, but * the full id (e.g. for V2, it should include the space name) * @return CloudFoundry server that corresponds to the given ID, or null if not found */ public static CloudFoundryServer getCloudServer(String serverID) { IServer[] servers = ServerCore.getServers(); if (servers == null) { return null; } CloudFoundryServer cfServer = null; for (IServer server : servers) { cfServer = (CloudFoundryServer) server.loadAdapter(CloudFoundryServer.class, null); if (cfServer != null && cfServer.getServerId().equals(serverID)) { break; } } return cfServer; }
private void startProxy(final IServer startedServer) { // re-start exiting proxy id already exist if (proxyServers.containsKey(startedServer)) { final LiveReloadProxyServer proxyServer = proxyServers.get(startedServer); try { proxyServer.start(); } catch (Exception e) { Logger.error( "Failed to start LiveReload Proxy on port " + proxyServer.getConnectors()[0].getPort() + " for server " + startedServer.getName(), e); } } // create a new proxy else { final int targetPort = WSTUtils.getWebPort(startedServer); if (targetPort != -1) { try { // now, let's init and start the embedded jetty proxy server // from the // server attributes final boolean allowRemoteConnections = isRemoteConnectionsAllowed(); final boolean enableScriptInjection = isScriptInjectionEnabled(); final String proxyHost = getProxyHost(); final int proxyPort = getProxyPort(startedServer); final LiveReloadProxyServer proxyServer = new LiveReloadProxyServer( proxyHost, proxyPort, startedServer.getHost(), targetPort, websocketPort, allowRemoteConnections, enableScriptInjection); proxyServers.put(startedServer, proxyServer); final JettyServerRunner proxyRunner = JettyServerRunner.start(proxyServer); proxyRunners.put(startedServer, proxyRunner); } catch (Exception e) { Logger.error( "Failed to create or start LiveReload proxy for server " + startedServer.getName(), e); } } } }
public void execute() throws BuildException { IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectname); try { IServer server = WebDSLProjectBuilder.getProjectServer(project, null); if (server == null) { System.out.println("module is currently not in server, cannot remove it"); } else { System.out.println("Removing server module for project: " + projectname); removeProjectModuleFromServer(project, server, null); System.out.println("Stop server."); server.stop(true); } } catch (CoreException e) { e.printStackTrace(); } }
private IProject getProject(IServer server) { IModule[] modules = server.getModules(); if (modules == null || modules.length == 0) { return null; } return modules[0].getProject(); }
public static IServer[] getServersForRuntime(IRuntime runtime) { List<IServer> serverList = new ArrayList<IServer>(); if (runtime != null) { IServer[] servers = ServerCore.getServers(); if (!CoreUtil.isNullOrEmpty(servers)) { for (IServer server : servers) { if (runtime.equals(server.getRuntime())) { serverList.add(server); } } } } return serverList.toArray(new IServer[0]); }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try { Liferay7UpgradeAssistantSettings settings = UpgradeAssistantSettingsUtil.getObjectFromStore(Liferay7UpgradeAssistantSettings.class); final String portalName = settings.getPortalSettings().getNewName(); IServer server = ServerCore.findServer(portalName); server.start("run", new NullProgressMonitor()); } catch (IOException | CoreException e) { e.printStackTrace(); } return null; }
private IModule getWebModule(IModule[] m) { if (m.length > 0) { IModule module = m[m.length - 1]; if (isWebModule(module)) { return module; } else { IServer s = getServer(); IModule[] mms = s.getChildModules(m, null); for (IModule child : mms) { if (isWebModule(child)) { return child; } } } } return null; }
public static boolean waitUntilTheServerStarts(IServer server, Shell shell) { return waitForServerToChangeState( server, shell, IServer.STATE_STOPPED, IServer.STATE_STARTED, "Starting WSAS Server " + server.getId() + "..."); }