[19/50] [abbrv] incubator-geode git commit: GEODE-288: move admin packages to internal

2016-11-15 Thread klund
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b6c305f8/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentImpl.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentImpl.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentImpl.java
new file mode 100644
index 000..6dbf134
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentImpl.java
@@ -0,0 +1,1624 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.admin.api.jmx.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
+import javax.management.ReflectionException;
+import javax.management.modelmbean.ModelMBean;
+import javax.management.remote.JMXConnectionNotification;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnectorServer;
+import javax.rmi.ssl.SslRMIClientSocketFactory;
+
+import mx4j.tools.adaptor.http.HttpAdaptor;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.GemFireException;
+import org.apache.geode.GemFireIOException;
+import org.apache.geode.LogWriter;
+import org.apache.geode.SystemFailure;
+import org.apache.geode.internal.admin.api.AdminDistributedSystem;
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.DistributedSystemConfig;
+import org.apache.geode.internal.admin.api.jmx.Agent;
+import org.apache.geode.internal.admin.api.jmx.AgentConfig;
+import org.apache.geode.internal.admin.api.jmx.AgentFactory;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.i18n.StringId;
+import org.apache.geode.internal.Banner;
+import org.apache.geode.internal.GemFireVersion;
+import org.apache.geode.internal.admin.remote.TailLogResponse;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.internal.logging.InternalLogWriter;
+import org.apache.geode.internal.logging.LogConfig;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.internal.logging.LogWriterFactory;
+import org.apache.geode.internal.logging.LoggingThreadGroup;
+import org.apache.geode.internal.logging.log4j.AlertAppender;
+import org.apache.geode.internal.logging.log4j.LocalizedMessage;
+import org.apache.geode.internal.logging.log4j.LogMarker;
+import org.apache.geode.internal.logging.log4j.LogWriterAppender;
+import org.apache.geode.internal.logging.log4j.LogWriterAppenders;
+
+/**
+ * The GemFire JMX Agent provides the ability to administrate one GemFire 
distributed system via
+ * JMX.
+ *
+ * @since GemFire 3.5
+ */
+public class AgentImpl implements Agent, ManagedResource {
+
+  private static final Logger logger = LogService.getLogger();
+
+  /**
+   * MX4J HttpAdaptor only supports "basic" as an authentication method. 
Enabling HttpAdaptor
+   * authentication ({@link AgentConfig#HTTP_AUTHENTICATION_ENABLED_NAME}) 
causes the browser to
+   * require a login with username ({@link 
AgentConfig#HTTP_AUTHENTICATION_USER_NAME}) and password
+   * ({@link AgentConfig#HTTP_AUTHENTICATION_PASSWORD_NAME}).
+   */
+  private static final String MX4J_HTTPADAPTOR_BASIC_AUTHENTICATION = "basic";
+
+  /** JMX Service URL template for JMX/RMI Connector Server */
+  private static final String JMX_SERVICE_URL = 

[19/50] [abbrv] incubator-geode git commit: GEODE-288: move admin packages to internal

2016-11-07 Thread klund
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6bb27bf1/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
new file mode 100644
index 000..932fe21
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
@@ -0,0 +1,918 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.admin.api.jmx.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.SortedMap;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.GemFireException;
+import org.apache.geode.SystemFailure;
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.jmx.Agent;
+import org.apache.geode.internal.admin.api.jmx.AgentConfig;
+import org.apache.geode.internal.admin.api.jmx.AgentFactory;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.internal.OSProcess;
+import org.apache.geode.internal.PureJavaMode;
+import org.apache.geode.internal.net.SocketCreator;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.internal.util.JavaCommandBuilder;
+
+/**
+ * A command line utility inspired by the CacheServerLauncher 
that is responsible for
+ * administering a stand-along GemFire JMX {@link Agent}.
+ * 
+ * 
+ * @since GemFire 3.5
+ */
+public class AgentLauncher {
+
+  private static final Logger logger = LogService.getLogger();
+
+  /** Should the launch command be printed? */
+  public static final boolean PRINT_LAUNCH_COMMAND =
+  Boolean.getBoolean(AgentLauncher.class.getSimpleName() + 
".PRINT_LAUNCH_COMMAND");
+
+  /* constants used to define state */
+  static final int SHUTDOWN = 0;
+  static final int STARTING = 1;
+  static final int RUNNING = 2;
+  static final int SHUTDOWN_PENDING = 3;
+  static final int SHUTDOWN_PENDING_AFTER_FAILED_STARTUP = 4;
+  static final int UNKNOWN = 6;
+
+  /** Agent configuration options */
+  static final String AGENT_PROPS = "agent-props";
+
+  /**
+   * A flag to indicate if the current log file should be kept. Used only when 
'start' is used to
+   * fork off the 'server'
+   */
+  static final String APPENDTO_LOG_FILE = "appendto-log-file";
+
+  /** optional and additional classpath entries */
+  static final String CLASSPATH = "classpath";
+
+  /** The directory argument */
+  static final String DIR = "dir";
+
+  /** Extra VM arguments */
+  static final String VMARGS = "vmargs";
+
+  /** The directory in which the agent's output resides */
+  private File workingDirectory = null;
+
+  /** The Status object for the agent */
+  private Status status = null;
+
+  /** base name for the agent to be launched */
+  private final String basename;
+
+  /** The name for the start up log file */
+  private final String startLogFileName;
+
+  /** The name of the status file */
+  private final String statusFileName;
+
+  /**
+   * Instantiates an AgentLauncher for execution and control of the GemFire 
JMX Agent process. This
+   * constructor is package private to prevent direct instantiation or 
subclassing by classes
+   * outside this package, but does allow the class to be tested as needed.
+   * 
+   * 
+   * @param basename base name for the application to be launched
+   */
+  AgentLauncher(final 

[19/50] [abbrv] incubator-geode git commit: GEODE-288: move admin packages to internal

2016-10-27 Thread klund
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/20a32286/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
new file mode 100644
index 000..23e9038
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.admin.api.jmx.impl;
+
+import javax.management.ObjectName;
+import javax.management.modelmbean.ModelMBean;
+
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.GemFireHealth;
+import org.apache.geode.internal.admin.api.GemFireHealthConfig;
+import org.apache.geode.internal.admin.api.impl.GemFireHealthConfigImpl;
+
+/**
+ * The JMX "managed resource" that represents the configuration for the health 
of GemFire.
+ * Basically, it provides the behavior of 
GemFireHealthConfigImpl, but does some JMX
+ * stuff like registering beans with the agent.
+ *
+ * 
+ *
+ * Unlike other ManagedResources this class cannot simply subclass
+ * GemFireHealthImpl because it instances are serialized and sent 
to other VMs. This is
+ * problematic because the other VMs most likely do not have JMX classes like
+ * ModelMBean on their classpaths. So, instead we delegate all of 
the
+ * GemFireHealthConfig behavior to another object which IS 
serialized.
+ *
+ * @see GemFireHealthJmxImpl#createDistributedSystemHealthConfig
+ *
+ *
+ * @since GemFire 3.5
+ */
+@edu.umd.cs.findbugs.annotations.SuppressWarnings(
+justification = "This class is deprecated. Also, any further changes so 
close to the release is inadvisable.")
+public class GemFireHealthConfigJmxImpl
+implements GemFireHealthConfig, ManagedResource, java.io.Serializable {
+
+  private static final long serialVersionUID = 1482719647163239953L;
+
+  /** The GemFireHealth that we help configure */
+  private GemFireHealth health;
+
+  /** The name of the MBean that will manage this resource */
+  private String mbeanName;
+
+  /** The ModelMBean that is configured to manage this resource */
+  private ModelMBean modelMBean;
+
+  /** The delegate that contains the real config state */
+  private GemFireHealthConfig delegate;
+
+  /** The object name of this managed resource */
+  private ObjectName objectName;
+
+  /// Constructors ///
+
+  /**
+   * Creates a new GemFireHealthConfigJmxImpl that configures the 
health monitoring of
+   * components running on the given host.
+   */
+  GemFireHealthConfigJmxImpl(GemFireHealthJmxImpl health, String hostName) 
throws AdminException {
+
+this.delegate = new GemFireHealthConfigImpl(hostName);
+this.health = health;
+this.mbeanName = new 
StringBuffer().append(MBEAN_NAME_PREFIX).append("GemFireHealthConfig,id=")
+
.append(MBeanUtil.makeCompliantMBeanNameProperty(health.getDistributedSystem().getId()))
+.append(",host=")
+.append((hostName == null ? "default" : 
MBeanUtil.makeCompliantMBeanNameProperty(hostName)))
+.toString();
+this.objectName = MBeanUtil.createMBean(this);
+  }
+
+  // Instance Methods //
+
+  /**
+   * Applies the changes made to this config back to the health monitor.
+   *
+   * @see GemFireHealth#setDistributedSystemHealthConfig
+   */
+  public void applyChanges() {
+String hostName = this.getHostName();
+if (hostName == null) {
+  this.health.setDefaultGemFireHealthConfig(this);
+
+} else {
+  this.health.setGemFireHealthConfig(hostName, this);
+}
+  }
+
+  public String getMBeanName() {
+return this.mbeanName;
+  }
+
+  public ModelMBean getModelMBean() {
+return this.modelMBean;
+  }
+
+  public ObjectName getObjectName() {
+return this.objectName;
+  }
+
+  public void setModelMBean(ModelMBean modelMBean) {
+