dev@glassfish.java.net

proposed commit

From: Justin Lee <Justin.Lee_at_Sun.COM>
Date: Wed, 18 Nov 2009 11:37:44 -0500

I'm not sure if we're already in the "approve every commit" with the HCF
date floating around but better safe than sorry. I'm attaching 2
patches that extend on the issue in
https://glassfish.dev.java.net/issues/show_bug.cgi?id=10219 to confirm
an element is unused before deleting it. This actually requires an
integration of grizzly 1.9.18h but merging these changes now will have
no deleterious affects. The test itself is not enabled yet as that
*will* break the devtest run unless 18h is integrated. I've also found
some error messages not accounted for in LocalStrings.properties and
rectified that.


Index: ../core/kernel/src/main/java/com/sun/enterprise/v3/admin/commands/DeleteThreadpool.java
===================================================================
--- ../core/kernel/src/main/java/com/sun/enterprise/v3/admin/commands/DeleteThreadpool.java (revision 27350)
+++ ../core/kernel/src/main/java/com/sun/enterprise/v3/admin/commands/DeleteThreadpool.java Wed Nov 18 00:00:16 EST 2009
@@ -50,6 +50,7 @@
 import org.jvnet.hk2.annotations.Scoped;
 import org.jvnet.hk2.annotations.Inject;
 import org.jvnet.hk2.component.PerLookup;
+import org.jvnet.hk2.component.Habitat;
 import org.jvnet.hk2.config.ConfigSupport;
 import org.jvnet.hk2.config.SingleConfigCode;
 import org.jvnet.hk2.config.TransactionFailure;
@@ -58,6 +59,8 @@
 import com.sun.enterprise.config.serverbeans.Configs;
 
 import com.sun.grizzly.config.dom.ThreadPool;
+import com.sun.grizzly.config.dom.NetworkListener;
+import com.sun.grizzly.config.dom.Protocol;
 import com.sun.enterprise.config.serverbeans.ThreadPools;
 import com.sun.enterprise.util.LocalStringManagerImpl;
 import com.sun.enterprise.util.SystemPropertyConstants;
@@ -80,6 +83,9 @@
     @Inject
     Configs configs;
 
+ @Inject
+ Habitat habitat;
+
     /**
      * Executes the command with the command parameters passed as Properties
      * where the keys are the paramter names and the values the parameter values
@@ -94,12 +100,25 @@
         ThreadPools threadPools = config.getThreadPools();
 
         if(!isThreadPoolExists(threadPools)) {
- report.setMessage(localStrings.getLocalString("delete.threadpool" +
- ".notexists", "Thread Pool named {0} does not exist.", threadpool_id));
+ report.setMessage(localStrings.getLocalString("delete.threadpool.notexists",
+ "Thread Pool named {0} does not exist.", threadpool_id));
             report.setActionExitCode(ExitCode.FAILURE);
             return;
         }
 
+ ThreadPool pool = habitat.getComponent(ThreadPool.class, threadpool_id);
+ List<NetworkListener> nwlsnrList = pool.findNetworkListeners();
+ for (NetworkListener nwlsnr : nwlsnrList) {
+ if (pool.getName().equals(nwlsnr.getThreadPool())) {
+ report.setMessage(localStrings.getLocalString(
+ "delete.threadpool.beingused",
+ "{0} threadpool is being used in the network listener {1}",
+ threadpool_id, nwlsnr.getName()));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+ }
+
         try {
             ConfigSupport.apply(new SingleConfigCode<ThreadPools>() {
                 public Object run(ThreadPools param) throws PropertyVetoException,
Index: ../web/admin/src/main/java/org/glassfish/web/admin/cli/LocalStrings.properties
===================================================================
--- ../web/admin/src/main/java/org/glassfish/web/admin/cli/LocalStrings.properties (revision 34144)
+++ ../web/admin/src/main/java/org/glassfish/web/admin/cli/LocalStrings.properties Wed Nov 18 00:00:44 EST 2009
@@ -66,4 +66,7 @@
 delete.protocol.fail=Deletion of Transport {0} failed
 delete.protocol.beingused={0} protocol is being used in the network listener {1}
 
+delete.threadpool.notexists=Thread Pool named {0} does not exist.
+delete.threadpool.beingused={0} threadpool is being used in the network listener {1}
+
 create.http.fail.protocolnotfound=The specified protocol {0} is not yet configured
Index: ../web/admin/src/main/java/org/glassfish/web/admin/cli/DeleteProtocol.java
===================================================================
--- ../web/admin/src/main/java/org/glassfish/web/admin/cli/DeleteProtocol.java (revision 32920)
+++ ../web/admin/src/main/java/org/glassfish/web/admin/cli/DeleteProtocol.java Tue Nov 17 23:53:45 EST 2009
@@ -51,14 +51,13 @@
 import org.jvnet.hk2.annotations.Scoped;
 import org.jvnet.hk2.annotations.Inject;
 import org.jvnet.hk2.component.PerLookup;
+import org.jvnet.hk2.component.Habitat;
 import org.jvnet.hk2.config.ConfigSupport;
 import org.jvnet.hk2.config.SingleConfigCode;
 import org.jvnet.hk2.config.TransactionFailure;
 import com.sun.enterprise.util.LocalStringManagerImpl;
 
 import java.beans.PropertyVetoException;
-
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -76,10 +75,14 @@
     @Param(name="protocolname", primary=true)
     String protocolName;
 
- Protocol protocolToBeRemoved = null;
+ Protocol protocol = null;
     
     @Inject
     Configs configs;
+
+ @Inject
+ Habitat habitat;
+
     /**
      * Executes the command with the command parameters passed as Properties
      * where the keys are the paramter names and the values the parameter values
@@ -95,13 +98,9 @@
         Protocols protocols = networkConfig.getProtocols();
 
         try {
- for (Protocol protocol : protocols.getProtocol()) {
- if (protocolName.equalsIgnoreCase(protocol.getName())) {
- protocolToBeRemoved = protocol;
- }
- }
+ protocol = habitat.getComponent(Protocol.class, protocolName);
 
- if (protocolToBeRemoved == null) {
+ if (protocol == null) {
                 report.setMessage(localStrings.getLocalString(
                     "delete.protocol.notexists", "{0} protocol doesn't exist",
                     protocolName));
@@ -112,10 +111,9 @@
             // check if the protocol to be deleted is being used by
             // any network listener
 
- List<NetworkListener> nwlsnrList =
- protocolToBeRemoved.findNetworkListeners();
+ List<NetworkListener> nwlsnrList = protocol.findNetworkListeners();
             for (NetworkListener nwlsnr : nwlsnrList) {
- if (protocolToBeRemoved.getName().equals(nwlsnr.getProtocol())) {
+ if (protocol.getName().equals(nwlsnr.getProtocol())) {
                     report.setMessage(localStrings.getLocalString(
                         "delete.protocol.beingused",
                         "{0} protocol is being used in the network listener {1}",
@@ -128,8 +126,8 @@
             ConfigSupport.apply(new SingleConfigCode<Protocols>() {
                 public Object run(Protocols param)
                 throws PropertyVetoException, TransactionFailure {
- param.getProtocol().remove(protocolToBeRemoved);
- return protocolToBeRemoved;
+ param.getProtocol().remove(protocol);
+ return protocol;
                 }
             }, protocols);
             


Index: ../devtests/web/cometEcho/WebTest.java
===================================================================
--- ../devtests/web/cometEcho/WebTest.java (revision 31061)
+++ ../devtests/web/cometEcho/WebTest.java Tue Nov 17 16:28:08 EST 2009
@@ -33,13 +33,28 @@
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import java.util.concurrent.*;
 
-import com.sun.ejte.ccl.reporter.*;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
+import com.sun.appserv.test.util.results.SimpleReporterAdapter;
+
 /*
  * Unit test for comet: echo.
  */
@@ -47,8 +62,7 @@
 
     private static final String TEST_NAME = "comet-echo";
 
- private static SimpleReporterAdapter stat
- = new SimpleReporterAdapter("appserv-tests");
+ private static final SimpleReporterAdapter stat = new SimpleReporterAdapter("appserv-tests", TEST_NAME);
 
     private String host;
     private String port;
Index: ../devtests/web/asadminDeletes/src/main/java/org/glassfish/devtests/web/asadmindeletes/WebTest.java
===================================================================
--- ../devtests/web/asadminDeletes/src/main/java/org/glassfish/devtests/web/asadmindeletes/WebTest.java Tue Nov 17 23:56:25 EST 2009
+++ ../devtests/web/asadminDeletes/src/main/java/org/glassfish/devtests/web/asadmindeletes/WebTest.java Tue Nov 17 23:56:25 EST 2009
@@ -0,0 +1,153 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can obtain
+ * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [year]
+ * [name of copyright owner]"
+ *
+ * Contributor(s):
+ *
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+package org.glassfish.devtests.web.asadmindeletes;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.appserv.test.util.results.SimpleReporterAdapter;
+
+/*
+ * Unit test for asadmin deletes.
+ */
+public class WebTest {
+ private static final String TEST_NAME = "asadmin-deletes";
+ private static final SimpleReporterAdapter stat = new SimpleReporterAdapter("appserv-tests", TEST_NAME);
+ private final String name = System.currentTimeMillis() + "";
+ private final PrintWriter writer;
+
+ public WebTest() throws FileNotFoundException {
+ writer = new PrintWriter("test.out");
+ }
+
+ public static void main(String[] args) throws FileNotFoundException {
+ stat.addDescription("Unit test for deleting referenced domain.xml entities");
+ new WebTest().run();
+ }
+
+ public void run() {
+ asadmin2("create-threadpool", false, "create-threadpool", name);
+ asadmin2("create-transport", false, "create-transport", name);
+ asadmin2("create-protocol", false, "create-protocol", name);
+ asadmin2("create-http", false, "create-http", "--default-virtual-server", "server", name);
+ asadmin2("create-network-listener", false, "create-network-listener",
+ "--listenerport", "10000",
+ "--protocol", name,
+ "--threadpool", name,
+ "--transport", name,
+ name);
+ asadmin2("delete-threadpool", true, "delete-threadpool", name);
+ asadmin2("delete-transport", true, "delete-transport", name);
+ asadmin2("delete-protocol", true, "delete-protocol", name);
+ asadmin2("delete-network-listener", false, "delete-network-listener", name);
+ asadmin2("delete-protocol-2", false, "delete-protocol-2", name);
+ asadmin2("delete-threadpool-2", false, "delete-threadpool", name);
+ asadmin2("delete-transport-2", false, "delete-transport", name);
+ stat.printSummary();
+ }
+
+ private void asadmin2(String step, boolean shouldFail, final String... args) {
+ List<String> command = new ArrayList<String>();
+ command.add("asadmin");
+// command.add("--echo=true");
+// command.add("--terse=true");
+ command.addAll(Arrays.asList(args));
+ ProcessBuilder builder = new ProcessBuilder(command);
+ String status = SimpleReporterAdapter.FAIL;
+ Process process = null;
+ boolean failed = false;
+ try {
+ process = builder.start();
+ InputStream inStream = process.getInputStream();
+ InputStream errStream = process.getErrorStream();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ try {
+ final byte[] buf = new byte[1000];
+ int read;
+ while ((read = inStream.read(buf)) != -1) {
+ out.write(buf, 0, read);
+ }
+ while ((read = errStream.read(buf)) != -1) {
+ err.write(buf, 0, read);
+ }
+ } finally {
+ errStream.close();
+ inStream.close();
+ }
+ String outString = new String(out.toByteArray()).trim();
+ String errString = new String(err.toByteArray()).trim();
+ failed = outString.matches("Command.*failed\\.");
+// if (failed) {
+ print(outString, "out");
+ print(errString, "err");
+// }
+ if(failed) {
+ status = shouldFail ? SimpleReporterAdapter.PASS : SimpleReporterAdapter.FAIL;
+ } else {
+ status = shouldFail ? SimpleReporterAdapter.FAIL : SimpleReporterAdapter.PASS;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ if (shouldFail) {
+ status = SimpleReporterAdapter.PASS;
+ }
+ } finally {
+ if (process != null) {
+ process.destroy();
+ }
+ }
+ write(String.format("*** %s (shouldFail=%b, failed=%b) ==> %s", step, shouldFail, failed, status));
+ stat.addStatus(step, status);
+ }
+
+ private void print(final String string, final String name) {
+ if (string.length() != 0) {
+ write(String.format("*** %s = \"%s\"", name, string));
+ }
+ }
+
+ private void write(final String out) {
+ writer.println(out);
+ writer.flush();
+ }
+
+}
Index: ../devtests/web/asadminDeletes/build.xml
===================================================================
--- ../devtests/web/asadminDeletes/build.xml Tue Nov 17 21:21:45 EST 2009
+++ ../devtests/web/asadminDeletes/build.xml Tue Nov 17 21:21:45 EST 2009
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can obtain
+ a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
+ or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
+ Sun designates this particular file as subject to the "Classpath" exception
+ as provided by Sun in the GPL Version 2 section of the License file that
+ accompanied this code. If applicable, add the following below the License
+ Header, with the fields enclosed by brackets [] replaced by your own
+ identifying information: "Portions Copyrighted [year]
+ [name of copyright owner]"
+
+ Contributor(s):
+
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+-->
+<!DOCTYPE project [
+ <!ENTITY commonSetup SYSTEM "./../../../config/properties.xml">
+ <!ENTITY commonBuild SYSTEM "./../../../config/common.xml">
+ <!ENTITY run SYSTEM "./../../../config/run.xml">
+ <!ENTITY testproperties SYSTEM "./build.properties">
+ ]>
+
+<project name="webcontainer_unittest" default="all" basedir=".">
+
+ &commonSetup;
+ &commonBuild;
+ &testproperties;
+ &run;
+
+ <path id="class.path">
+ <pathelement location="${env.APS_HOME}/lib/reportbuilder.jar"/>
+ <pathelement location="build"/>
+ <fileset dir="${env.S1AS_HOME}/modules"/>
+ </path>
+ <pathconvert refid="class.path" property="test"/>
+
+ <target name="clean" depends="init-common">
+ <antcall target="clean-common"/>
+ <delete>
+ <fileset dir="build"/>
+ </delete>
+ </target>
+
+ <target name="build">
+ <mkdir dir="build"/>
+ <javac srcdir="src/main/java" destdir="build" debug="true"
+ classpath="${test}"
+ includes="**/*.java"/>
+ </target>
+
+ <target name="all" depends="init-common, build">
+ <java classname="org.glassfish.devtests.web.asadmindeletes.WebTest" classpath="${test}"/>
+ </target>
+
+ <target name="usage">
+ <antcall target="usage-common"/>
+ </target>
+</project>
Index: ../devtests/web/asadminDeletes/build.properties
===================================================================
--- ../devtests/web/asadminDeletes/build.properties Tue Nov 17 17:28:51 EST 2009
+++ ../devtests/web/asadminDeletes/build.properties Tue Nov 17 17:28:51 EST 2009
@@ -0,0 +1,3 @@
+<property name="module" value="web"/>
+<property name="appname" value="${module}-asadmin-deletes"/>
+<property name="assemble" value="${build.classes.dir}/archive"/>