Search in sources :

Example 1 with ExecException

use of com.sun.enterprise.util.ExecException 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)

Example 2 with ExecException

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

the class SharedAndExternalServiceTest 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/external-and-shared-service-test.war");
    // archive location.
    org.junit.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-external-and-shared-service-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 + "/external-and-shared-service-test/list", "Here is a list of animals in the zoo.");
        testSharedAndExternalService();
        // 4. Access the app to make sure PaaS-external-and-shared-service-test app is correctly
        // provisioned after running Shared-Services test
        get("http://" + instanceIP + ":" + HTTP_PORT + "/external-and-shared-service-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) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServerContext(org.glassfish.internal.api.ServerContext) File(java.io.File) Test(org.junit.Test)

Example 3 with ExecException

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

the class MyDBPlugin method start.

public void start(VirtualMachine virtualMachine, boolean firstStart) {
    String[] startdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "start-database", "--dbport", "1528" };
    ProcessExecutor startDatabase = new ProcessExecutor(startdbArgs);
    try {
        startDatabase.execute();
    } catch (ExecException e) {
        e.printStackTrace();
    }
}
Also used : ExecException(com.sun.enterprise.util.ExecException) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor)

Example 4 with ExecException

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

the class MyDBPlugin method stop.

public void stop(VirtualMachine virtualMachine) {
    String[] stopdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "stop-database", "--dbport", "1528" };
    ProcessExecutor stopDatabase = new ProcessExecutor(stopdbArgs);
    try {
        stopDatabase.execute();
    } catch (ExecException e) {
        e.printStackTrace();
    }
}
Also used : ExecException(com.sun.enterprise.util.ExecException) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor)

Aggregations

ExecException (com.sun.enterprise.util.ExecException)4 ProcessExecutor (com.sun.enterprise.util.ProcessExecutor)4 File (java.io.File)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 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