[1/2] hadoop git commit: YARN-8080. Add restart policy for YARN services. Contributed by Suma Shivaprasad

2018-05-17 Thread eyang
Repository: hadoop
Updated Branches:
  refs/heads/trunk 7802af6e9 -> 7f083ed86


http://git-wip-us.apache.org/repos/asf/hadoop/blob/7f083ed8/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
--
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
index 0b56d7e..26e8c93 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
@@ -6,9 +6,9 @@
  * 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
- *
+ * 
+ * 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.
@@ -18,56 +18,80 @@
 
 package org.apache.hadoop.yarn.service.component.instance;
 
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.ContainerStatus;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
 import org.apache.hadoop.yarn.service.ServiceContext;
+import org.apache.hadoop.yarn.service.ServiceScheduler;
 import org.apache.hadoop.yarn.service.ServiceTestUtils;
 import org.apache.hadoop.yarn.service.api.records.Container;
 import org.apache.hadoop.yarn.service.api.records.ContainerState;
+import org.apache.hadoop.yarn.service.api.records.Service;
 import org.apache.hadoop.yarn.service.component.Component;
 import org.apache.hadoop.yarn.service.component.ComponentEvent;
 import org.apache.hadoop.yarn.service.component.ComponentEventType;
 import org.apache.hadoop.yarn.service.component.TestComponent;
+import org.apache.hadoop.yarn.service.utils.ServiceUtils;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 /**
  * Tests for {@link ComponentInstance}.
  */
 public class TestComponentInstance {
 
-  @Rule
-  public ServiceTestUtils.ServiceFSWatcher rule =
+  @Rule public ServiceTestUtils.ServiceFSWatcher rule =
   new ServiceTestUtils.ServiceFSWatcher();
 
-  @Test
-  public void testContainerUpgrade() throws Exception {
+  @Test public void testContainerUpgrade() throws Exception {
 ServiceContext context = TestComponent.createTestContext(rule,
 "testContainerUpgrade");
-Component component = context.scheduler.getAllComponents().entrySet()
-.iterator().next().getValue();
+Component component =
+context.scheduler.getAllComponents().entrySet().iterator().next()
+.getValue();
 upgradeComponent(component);
 
-ComponentInstance instance = component.getAllComponentInstances()
-.iterator().next();
+ComponentInstance instance =
+component.getAllComponentInstances().iterator().next();
 ComponentInstanceEvent instanceEvent = new ComponentInstanceEvent(
 instance.getContainer().getId(), ComponentInstanceEventType.UPGRADE);
 instance.handle(instanceEvent);
 Container containerSpec = component.getComponentSpec().getContainer(
 instance.getContainer().getId().toString());
-Assert.assertEquals("instance not upgrading",
-ContainerState.UPGRADING, containerSpec.getState());
+Assert.assertEquals("instance not upgrading", ContainerState.UPGRADING,
+containerSpec.getState());
   }
 

[1/2] hadoop git commit: YARN-8080. Add restart policy for YARN services. Contributed by Suma Shivaprasad

2018-05-17 Thread eyang
Repository: hadoop
Updated Branches:
  refs/heads/branch-3.1 c6c3b0afa -> 044573b62


http://git-wip-us.apache.org/repos/asf/hadoop/blob/044573b6/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
--
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
index 0b56d7e..26e8c93 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/component/instance/TestComponentInstance.java
@@ -6,9 +6,9 @@
  * 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
- *
+ * 
+ * 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.
@@ -18,56 +18,80 @@
 
 package org.apache.hadoop.yarn.service.component.instance;
 
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.ContainerStatus;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
 import org.apache.hadoop.yarn.service.ServiceContext;
+import org.apache.hadoop.yarn.service.ServiceScheduler;
 import org.apache.hadoop.yarn.service.ServiceTestUtils;
 import org.apache.hadoop.yarn.service.api.records.Container;
 import org.apache.hadoop.yarn.service.api.records.ContainerState;
+import org.apache.hadoop.yarn.service.api.records.Service;
 import org.apache.hadoop.yarn.service.component.Component;
 import org.apache.hadoop.yarn.service.component.ComponentEvent;
 import org.apache.hadoop.yarn.service.component.ComponentEventType;
 import org.apache.hadoop.yarn.service.component.TestComponent;
+import org.apache.hadoop.yarn.service.utils.ServiceUtils;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 /**
  * Tests for {@link ComponentInstance}.
  */
 public class TestComponentInstance {
 
-  @Rule
-  public ServiceTestUtils.ServiceFSWatcher rule =
+  @Rule public ServiceTestUtils.ServiceFSWatcher rule =
   new ServiceTestUtils.ServiceFSWatcher();
 
-  @Test
-  public void testContainerUpgrade() throws Exception {
+  @Test public void testContainerUpgrade() throws Exception {
 ServiceContext context = TestComponent.createTestContext(rule,
 "testContainerUpgrade");
-Component component = context.scheduler.getAllComponents().entrySet()
-.iterator().next().getValue();
+Component component =
+context.scheduler.getAllComponents().entrySet().iterator().next()
+.getValue();
 upgradeComponent(component);
 
-ComponentInstance instance = component.getAllComponentInstances()
-.iterator().next();
+ComponentInstance instance =
+component.getAllComponentInstances().iterator().next();
 ComponentInstanceEvent instanceEvent = new ComponentInstanceEvent(
 instance.getContainer().getId(), ComponentInstanceEventType.UPGRADE);
 instance.handle(instanceEvent);
 Container containerSpec = component.getComponentSpec().getContainer(
 instance.getContainer().getId().toString());
-Assert.assertEquals("instance not upgrading",
-ContainerState.UPGRADING, containerSpec.getState());
+Assert.assertEquals("instance not upgrading", ContainerState.UPGRADING,
+containerSpec.getState());