[23/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/impl/ManagedSystemMemberImpl.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/ManagedSystemMemberImpl.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/ManagedSystemMemberImpl.java
new file mode 100644
index 000..abc6d01
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/ManagedSystemMemberImpl.java
@@ -0,0 +1,258 @@
+/*
+ * 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.impl;
+
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.ConfigurationParameter;
+import org.apache.geode.internal.admin.api.ManagedEntityConfig;
+import org.apache.geode.internal.admin.GemFireVM;
+
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+
+/**
+ * A SystemMember that is also managed (or manageable) by the 
admin API.
+ *
+ * This class must be public so that its methods can be invoked reflectively 
(for MBean operations)
+ * on instances of its subclasses.
+ *
+ * @since GemFire 4.0
+ */
+public abstract class ManagedSystemMemberImpl extends SystemMemberImpl
+implements InternalManagedEntity {
+
+  /** Controller for starting and stopping local or remote managers */
+  protected ManagedEntityController controller;
+
+  /** The state of this managed entity (see bug 32455) */
+  private int state = UNKNOWN;
+
+  /** A lock that is obtained while this entity's state changes */
+  private final Object stateChange = new Object();
+
+  // Constructors //
+
+  /**
+   * Creates a new ManagedSystemMemberImpl that represents an 
existing member of an
+   * AdminDistributedSystem.
+   */
+  protected ManagedSystemMemberImpl(AdminDistributedSystemImpl system, 
GemFireVM vm)
+  throws AdminException {
+
+super(system, vm);
+this.controller = system.getEntityController();
+  }
+
+  /**
+   * Creates a new ManagedSystemMemberImpl that represents a 
non-existing member with
+   * the given ManagedEntityConfig that has not yet been started.
+   */
+  protected ManagedSystemMemberImpl(AdminDistributedSystemImpl system, 
ManagedEntityConfig config)
+  throws AdminException {
+
+super(system);
+this.internalId = null;
+this.id = getNewId();
+this.host = config.getHost();
+this.name = this.id;
+this.controller = system.getEntityController();
+  }
+
+  // Instance Methods //
+
+  public String getWorkingDirectory() {
+return this.getEntityConfig().getWorkingDirectory();
+  }
+
+  public void setWorkingDirectory(String workingDirectory) {
+this.getEntityConfig().setWorkingDirectory(workingDirectory);
+  }
+
+  public String getProductDirectory() {
+return this.getEntityConfig().getProductDirectory();
+  }
+
+  public void setProductDirectory(String productDirectory) {
+this.getEntityConfig().setProductDirectory(productDirectory);
+  }
+
+  @Override
+  public String getHost() {
+return this.getEntityConfig().getHost();
+  }
+
+  public int setState(int state) {
+if (this.stateChange == null) {
+  // The initial state is set in the constructor before
+  // stateChange is initialized.
+  int oldState = this.state;
+  this.state = state;
+  return oldState;
+
+} else {
+  synchronized (this.stateChange) {
+int oldState = this.state;
+this.state = state;
+
+this.stateChange.notifyAll();
+
+return oldState;
+  }
+}
+  }
+
+  /**
+   * Returns whether or not this managed system member needs to be stopped. If 
this member is
+   * stopped or is stopping, then it does not need to be stopped. Otherwise, 
it will atomically
+   * place this member in the {@link #STOPPING} state. See bug 32455.
+   */
+  protected boolean needToStop() {
+synchronized (this.stateChange) {
+  if (this.state == STOPPED || this.state == STOPPING) {
+return false;
+
+  } else {
+

[23/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/impl/SystemMemberRegionImpl.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java
new file mode 100644
index 000..87a06b8
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/impl/SystemMemberRegionImpl.java
@@ -0,0 +1,372 @@
+/*
+ * 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.impl;
+
+import org.apache.geode.cache.*;
+// import org.apache.geode.internal.Assert;
+// import org.apache.geode.internal.admin.*;
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.SystemMemberRegion;
+import org.apache.geode.internal.admin.remote.*;
+
+import java.io.File;
+import java.util.*;
+
+/**
+ * View of a region in a GemFire system member's cache.
+ *
+ * @since GemFire 3.5
+ */
+public class SystemMemberRegionImpl implements SystemMemberRegion {
+
+  private AdminRegion r;
+  private RegionAttributes ra;
+  private CacheStatistics rs;
+  private Set subregionNames;
+  private Set subregionFullPaths;
+  private int entryCount;
+  private int subregionCount;
+
+  /** The cache to which this region belongs */
+  private final SystemMemberCacheImpl cache;
+
+  // constructors
+  public SystemMemberRegionImpl(SystemMemberCacheImpl cache, Region r) {
+this.cache = cache;
+this.r = (AdminRegion) r;
+  }
+
+  private void refreshFields() {
+this.ra = this.r.getAttributes();
+if (getStatisticsEnabled() && !this.ra.getDataPolicy().withPartitioning()) 
{
+  this.rs = this.r.getStatistics();
+} else {
+  this.rs = null;
+}
+{ // set subregionNames
+  Set s = this.r.subregions(false);
+  Set names = new TreeSet();
+  Set paths = new TreeSet();
+  Iterator it = s.iterator();
+  while (it.hasNext()) {
+Region r = (Region) it.next();
+String name = r.getName();
+names.add(name);
+paths.add(this.getFullPath() + Region.SEPARATOR_CHAR + name);
+  }
+  this.subregionNames = names;
+  this.subregionFullPaths = paths;
+}
+try {
+  int[] sizes = this.r.sizes();
+  this.entryCount = sizes[0];
+  this.subregionCount = sizes[1];
+} catch (CacheException ignore) {
+  this.entryCount = 0;
+  this.subregionCount = 0;
+}
+  }
+
+  // attributes
+  public String getName() {
+return this.r.getName();
+  }
+
+  public String getFullPath() {
+return this.r.getFullPath();
+  }
+
+  public java.util.Set getSubregionNames() {
+return this.subregionNames;
+  }
+
+  public java.util.Set getSubregionFullPaths() {
+return this.subregionFullPaths;
+  }
+
+  public String getUserAttribute() {
+return (String) r.getUserAttribute();
+  }
+
+  public String getCacheLoader() {
+Object o = this.ra.getCacheLoader();
+if (o == null) {
+  return "";
+} else {
+  return o.toString();
+}
+  }
+
+  public String getCacheWriter() {
+Object o = this.ra.getCacheWriter();
+if (o == null) {
+  return "";
+} else {
+  return o.toString();
+}
+  }
+
+  public String getKeyConstraint() {
+Class constraint = this.ra.getKeyConstraint();
+if (constraint == null) {
+  return "";
+} else {
+  return constraint.getName();
+}
+  }
+
+  public String getValueConstraint() {
+Class constraint = this.ra.getValueConstraint();
+if (constraint == null) {
+  return "";
+} else {
+  return constraint.getName();
+}
+  }
+
+  public boolean getEarlyAck() {
+return this.ra.getEarlyAck();
+  }
+
+  public int getRegionTimeToLiveTimeLimit() {
+return this.ra.getRegionTimeToLive().getTimeout();
+  }
+
+  public ExpirationAction getRegionTimeToLiveAction() {
+return this.ra.getRegionTimeToLive().getAction();
+  }
+
+  public int getEntryTimeToLiveTimeLimit() {
+return this.ra.getEntryTimeToLive().getTimeout();
+  }

[23/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/AdminDistributedSystemJmxImpl.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AdminDistributedSystemJmxImpl.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AdminDistributedSystemJmxImpl.java
new file mode 100755
index 000..7998091
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AdminDistributedSystemJmxImpl.java
@@ -0,0 +1,2289 @@
+/*
+ * 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 org.apache.geode.DataSerializer;
+import org.apache.geode.SystemFailure;
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.CacheServer;
+import org.apache.geode.internal.admin.api.CacheServerConfig;
+import org.apache.geode.internal.admin.api.CacheVm;
+import org.apache.geode.internal.admin.api.CacheVmConfig;
+import org.apache.geode.internal.admin.api.DistributedSystemConfig;
+import org.apache.geode.internal.admin.api.DistributionLocator;
+import org.apache.geode.internal.admin.api.DistributionLocatorConfig;
+import org.apache.geode.internal.admin.api.GemFireHealth;
+import org.apache.geode.internal.admin.api.SystemMember;
+import org.apache.geode.internal.admin.api.SystemMemberCacheEvent;
+import org.apache.geode.internal.admin.api.SystemMemberCacheListener;
+import org.apache.geode.internal.admin.api.SystemMemberRegionEvent;
+import org.apache.geode.internal.admin.api.SystemMemberType;
+import org.apache.geode.internal.admin.api.impl.AdminDistributedSystemImpl;
+import org.apache.geode.internal.admin.api.impl.CacheServerConfigImpl;
+import org.apache.geode.internal.admin.api.impl.DistributionLocatorImpl;
+import org.apache.geode.cache.persistence.PersistentID;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import 
org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.internal.Assert;
+import org.apache.geode.internal.admin.Alert;
+import org.apache.geode.internal.admin.*;
+import org.apache.geode.internal.admin.remote.UpdateAlertDefinitionMessage;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.internal.logging.InternalLogWriter;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.internal.logging.log4j.LocalizedMessage;
+import org.apache.logging.log4j.Logger;
+
+import javax.management.*;
+import javax.management.modelmbean.ModelMBean;
+import javax.management.openmbean.*;
+import java.io.*;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Provides MBean support for managing a GemFire distributed system.
+ * 
+ * TODO: refactor to implement DistributedSystem and delegate to instance of 
DistributedSystemImpl.
+ * Wrap all delegate calls w/ e.printStackTrace() since the HttpAdaptor 
devours them (what to do w/
+ * template methods then?)
+ *
+ * @since GemFire 3.5
+ */
+public class AdminDistributedSystemJmxImpl extends AdminDistributedSystemImpl
+implements ManagedResource, DistributedSystemConfig, StatAlertsAggregator {
+
+  private static final Logger logger = LogService.getLogger();
+
+  private Properties mailProps;
+
+  // The file name where the StatAlertDefinitions would be serialized
+  private String statAlertDefnSerFile = System.getProperty("user.dir");
+
+  /**
+   * Simple counter incrementing on each notification. This this currently 
resets at every restart
+   * of Agent
+   */
+  private final AtomicInteger notificationSequenceNumber = new AtomicInteger();
+
+  /**
+   * Variable to indicate if there are no Rmi clients connected.
+   */
+  private volatile boolean isRmiClientCountZero;
+
+  /**
+   * Variable to indicate if Statistics Alert definitions could be