Search in sources :

Example 1 with ProcessExecutor

use of com.sun.enterprise.util.ProcessExecutor in project Payara by payara.

the class RepositoryManager method createMQInstance.

/**
 * Create MQ instance.
 * @param config the {@link RepositoryConfig} to create the MQ instance within
 */
protected void createMQInstance(RepositoryConfig config) {
    final PEFileLayout layout = getFileLayout(config);
    final File broker = layout.getImqBrokerExecutable();
    final File mqVarHome = layout.getImqVarHome();
    try {
        FileUtils.mkdirsMaybe(mqVarHome);
        final List<String> cmdInput = new ArrayList<String>();
        cmdInput.add(broker.getAbsolutePath());
        cmdInput.add("-init");
        cmdInput.add("-varhome");
        cmdInput.add(mqVarHome.getAbsolutePath());
        ProcessExecutor pe = new ProcessExecutor(cmdInput.toArray(new String[cmdInput.size()]));
        pe.execute(false, false);
    } catch (Exception ioe) {
    /*
             * Dont do anything. * IMQ instance is created just to make sure that Off line IMQ commands can be executed, even before
             * starting the broker. A typical scenario is while on-demand startup is off, user might try to do imqusermgr. Here
             * broker may not have started.
             *
             * Failure in creating the instance doesnt need to abort domain creation.
             */
    }
}
Also used : ArrayList(java.util.ArrayList) PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor) File(java.io.File) ZipFile(com.sun.enterprise.util.zip.ZipFile) IOException(java.io.IOException)

Example 2 with ProcessExecutor

use of com.sun.enterprise.util.ProcessExecutor in project Payara by payara.

the class SMFService method importService.

private boolean importService() throws Exception {
    final String[] cmda = new String[] { SMFService.SVCCFG, "import", getManifestFilePath() };
    final ProcessExecutor pe = new ProcessExecutor(cmda);
    if (info.dryRun)
        cleanupManifest();
    else
        // throws ExecException in case of an error
        pe.execute();
    if (info.trace)
        printOut("Imported the SMF Service: " + info.fqsn);
    return (true);
}
Also used : ProcessExecutor(com.sun.enterprise.util.ProcessExecutor)

Example 3 with ProcessExecutor

use of com.sun.enterprise.util.ProcessExecutor in project Payara by payara.

the class SMFService method isUserSmfAuthorized.

private boolean isUserSmfAuthorized(final String user, final StringBuilder auths) {
    boolean authorized = false;
    String path2Auths = "auths";
    String at = ",";
    final String AUTH1 = "solaris.*";
    final String AUTH2 = "solaris.smf.*";
    final String AUTH3 = "solaris.smf.modify";
    if (System.getProperty("PATH_2_AUTHS") != null)
        path2Auths = System.getProperty("PATH_2_AUTHS");
    if (System.getProperty("AUTH_TOKEN") != null)
        at = System.getProperty("AUTH_TOKEN");
    try {
        final String[] cmd = new String[] { path2Auths, user };
        ProcessExecutor pe = new ProcessExecutor(cmd);
        pe.setExecutionRetentionFlag(true);
        pe.execute();
        auths.append(pe.getLastExecutionOutput());
        final StringTokenizer st = new StringTokenizer(pe.getLastExecutionOutput(), at);
        while (st.hasMoreTokens()) {
            String t = st.nextToken();
            t = t.trim();
            if (AUTH1.equals(t) || AUTH2.equals(t) || AUTH3.equals(t)) {
                authorized = true;
                break;
            }
        }
        return (authorized);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor) ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException)

Example 4 with ProcessExecutor

use of com.sun.enterprise.util.ProcessExecutor in project Payara by payara.

the class SMFService method serviceNameExists.

private boolean serviceNameExists(final String sn) {
    boolean exists = false;
    try {
        final String[] cmd = new String[] { "/usr/bin/svcs", sn };
        ProcessExecutor pe = new ProcessExecutor(cmd);
        pe.setExecutionRetentionFlag(true);
        pe.execute();
        exists = true;
    } catch (final Exception e) {
    // returns a non-zero status -- the service does not exist, status is already set
    }
    return (exists);
}
Also used : ProcessExecutor(com.sun.enterprise.util.ProcessExecutor) ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException)

Example 5 with ProcessExecutor

use of com.sun.enterprise.util.ProcessExecutor in project Payara by payara.

the class ExtSharedServiceEnableDisableTest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS-bookstore application.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/ext-shared-service-enable-disable-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    // Obtaining the IP address of the DAS
    String ip_address = "127.0.0.1";
    try {
        Enumeration netint_enum = NetworkInterface.getNetworkInterfaces();
        for (Iterator it = Collections.list(netint_enum).iterator(); it.hasNext(); ) {
            NetworkInterface netint = (NetworkInterface) it.next();
            if (netint.getName().equals("virbr0")) {
                Enumeration inetAddresses = netint.getInetAddresses();
                if (inetAddresses.hasMoreElements()) {
                    InetAddress inetAddress = (InetAddress) inetAddresses.nextElement();
                    ip_address = inetAddress.toString();
                    ip_address = ip_address.substring(1, ip_address.length());
                    break;
                }
            }
        }
    } catch (SocketException socketException) {
        socketException.printStackTrace();
    }
    Deployer deployer = null;
    String appName = null;
    try {
        {
            // start-database
            ServiceLocator habitat = Globals.getDefaultHabitat();
            ServerContext serverContext = habitat.getService(ServerContext.class);
            String[] startdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "start-database", "--dbhome", serverContext.getInstallRoot().getAbsolutePath() + File.separator + "databases", "--dbhost", ip_address };
            ProcessExecutor startDatabase = new ProcessExecutor(startdbArgs);
            try {
                startDatabase.execute();
            } catch (ExecException e) {
                e.printStackTrace();
            }
        }
        // Create the shared & external services first, as these services will be referenced by the application
        createSharedAndExternalServices(ip_address);
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandRunner commandRunner = glassfish.getCommandRunner();
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS-ext-shared-service-enable-disable-test app is correctly
        // provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
        testSharedAndExternalService();
        // 4. Access the app to make sure PaaS-ext-shared-service-enable-disable-test app is correctly
        // provisioned after running Shared-Services test
        get("http://" + instanceIP + ":" + HTTP_PORT + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
    // 5. Undeploy the Zoo catalogue application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            deleteSharedAndExternalService();
            {
                // stop-database
                ServiceLocator habitat = Globals.getDefaultHabitat();
                ServerContext serverContext = habitat.getService(ServerContext.class);
                String[] stopDbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "stop-database", "--dbhost", ip_address };
                ProcessExecutor stopDatabase = new ProcessExecutor(stopDbArgs);
                try {
                    stopDatabase.execute();
                } catch (ExecException e) {
                    e.printStackTrace();
                }
            }
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                System.out.println(commandResult.getOutput().toString());
                if (commandResult.getOutput().contains("Nothing to list")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) ExecException(com.sun.enterprise.util.ExecException) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor) ExecException(com.sun.enterprise.util.ExecException) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServerContext(org.glassfish.internal.api.ServerContext) GlassFish(org.glassfish.embeddable.GlassFish) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Aggregations

ProcessExecutor (com.sun.enterprise.util.ProcessExecutor)9 ExecException (com.sun.enterprise.util.ExecException)4 File (java.io.File)3 ProcessManagerException (com.sun.enterprise.universal.process.ProcessManagerException)2 PrintStream (java.io.PrintStream)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 ServerContext (org.glassfish.internal.api.ServerContext)2 Test (org.junit.Test)2 PEFileLayout (com.sun.enterprise.admin.servermgmt.pe.PEFileLayout)1 ZipFile (com.sun.enterprise.util.zip.ZipFile)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 CommandResult (org.glassfish.embeddable.CommandResult)1 CommandRunner (org.glassfish.embeddable.CommandRunner)1 Deployer (org.glassfish.embeddable.Deployer)1 GlassFish (org.glassfish.embeddable.GlassFish)1 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)1