http://git-wip-us.apache.org/repos/asf/hadoop/blob/27d60a16/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/TestYarnNativeServices.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/TestYarnNativeServices.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/TestYarnNativeServices.java
index 091e624..df6d642 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/TestYarnNativeServices.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/TestYarnNativeServices.java
@@ -33,7 +33,7 @@ import org.apache.hadoop.yarn.service.api.records.Component;
 import org.apache.hadoop.yarn.service.api.records.Container;
 import org.apache.hadoop.yarn.service.api.records.ContainerState;
 import org.apache.hadoop.yarn.service.client.ServiceClient;
-import org.apache.hadoop.yarn.service.exceptions.SliderException;
+import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
 import org.apache.hadoop.yarn.service.utils.SliderFileSystem;
 import org.hamcrest.CoreMatchers;
 import org.junit.After;
@@ -86,7 +86,7 @@ public class TestYarnNativeServices extends ServiceTestUtils {
   @Test (timeout = 200000)
   public void testCreateFlexStopDestroyService() throws Exception {
     setupInternal(NUM_NMS);
-    ServiceClient client = createClient();
+    ServiceClient client = createClient(getConf());
     Service exampleApp = createExampleApplication();
     client.actionCreate(exampleApp);
     SliderFileSystem fileSystem = new SliderFileSystem(getConf());
@@ -141,7 +141,7 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
   @Test (timeout = 200000)
   public void testComponentStartOrder() throws Exception {
     setupInternal(NUM_NMS);
-    ServiceClient client = createClient();
+    ServiceClient client = createClient(getConf());
     Service exampleApp = new Service();
     exampleApp.setName("teststartorder");
     exampleApp.setVersion("v1");
@@ -169,7 +169,7 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
     String userB = "userb";
 
     setupInternal(NUM_NMS);
-    ServiceClient client = createClient();
+    ServiceClient client = createClient(getConf());
     String origBasePath = getConf().get(YARN_SERVICE_BASE_PATH);
 
     Service userAApp = new Service();
@@ -221,7 +221,7 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
     System.setProperty("user.name", user);
 
     setupInternal(NUM_NMS);
-    ServiceClient client = createClient();
+    ServiceClient client = createClient(getConf());
 
     Service appA = new Service();
     appA.setName(sameAppName);
@@ -290,7 +290,7 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
     setConf(conf);
     setupInternal(NUM_NMS);
 
-    ServiceClient client = createClient();
+    ServiceClient client = createClient(getConf());
     Service exampleApp = createExampleApplication();
     client.actionCreate(exampleApp);
     Multimap<String, String> containersBeforeFailure =
@@ -333,6 +333,28 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
     client.actionDestroy(exampleApp.getName());
   }
 
+  @Test(timeout = 200000)
+  public void testUpgradeService() throws Exception {
+    setupInternal(NUM_NMS);
+    ServiceClient client = createClient(getConf());
+
+    Service service = createExampleApplication();
+    client.actionCreate(service);
+    waitForServiceToBeStarted(client, service);
+
+    //upgrade the service
+    service.setVersion("v2");
+    client.actionUpgrade(service);
+
+    //wait for service to be in upgrade state
+    waitForServiceToBeInState(client, service, ServiceState.UPGRADING);
+    SliderFileSystem fs = new SliderFileSystem(getConf());
+    Service fromFs = ServiceApiUtil.loadServiceUpgrade(fs,
+        service.getName(), service.getVersion());
+    Assert.assertEquals(service.getName(), fromFs.getName());
+    Assert.assertEquals(service.getVersion(), fromFs.getVersion());
+  }
+
   // Check containers launched are in dependency order
   // Get all containers into a list and sort based on container launch time 
e.g.
   // compa-c1, compa-c2, compb-c1, compb-c2;
@@ -470,16 +492,7 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
    */
   private void waitForServiceToBeStable(ServiceClient client,
       Service exampleApp) throws TimeoutException, InterruptedException {
-    GenericTestUtils.waitFor(() -> {
-      try {
-        Service retrievedApp = client.getStatus(exampleApp.getName());
-        System.out.println(retrievedApp);
-        return retrievedApp.getState() == ServiceState.STABLE;
-      } catch (Exception e) {
-        e.printStackTrace();
-        return false;
-      }
-    }, 2000, 200000);
+    waitForServiceToBeInState(client, exampleApp, ServiceState.STABLE);
   }
 
   /**
@@ -492,11 +505,25 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
    */
   private void waitForServiceToBeStarted(ServiceClient client,
       Service exampleApp) throws TimeoutException, InterruptedException {
+    waitForServiceToBeInState(client, exampleApp, ServiceState.STARTED);
+  }
+
+  /**
+   * Wait until service is started. It does not have to reach a stable state.
+   *
+   * @param client
+   * @param exampleApp
+   * @throws TimeoutException
+   * @throws InterruptedException
+   */
+  private void waitForServiceToBeInState(ServiceClient client,
+      Service exampleApp, ServiceState desiredState) throws TimeoutException,
+      InterruptedException {
     GenericTestUtils.waitFor(() -> {
       try {
         Service retrievedApp = client.getStatus(exampleApp.getName());
         System.out.println(retrievedApp);
-        return retrievedApp.getState() == ServiceState.STARTED;
+        return retrievedApp.getState() == desiredState;
       } catch (Exception e) {
         e.printStackTrace();
         return false;
@@ -504,21 +531,6 @@ public class TestYarnNativeServices extends 
ServiceTestUtils {
     }, 2000, 200000);
   }
 
-  private ServiceClient createClient() throws Exception {
-    ServiceClient client = new ServiceClient() {
-      @Override protected Path addJarResource(String appName,
-          Map<String, LocalResource> localResources)
-          throws IOException, SliderException {
-        // do nothing, the Unit test will use local jars
-        return null;
-      }
-    };
-    client.init(getConf());
-    client.start();
-    return client;
-  }
-
-
   private int countTotalContainers(Service service) {
     int totalContainers = 0;
     for (Component component : service.getComponents()) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/27d60a16/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.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/client/TestServiceClient.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/client/TestServiceClient.java
new file mode 100644
index 0000000..cc5b6ec
--- /dev/null
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/client/TestServiceClient.java
@@ -0,0 +1,125 @@
+/**
+ * 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.hadoop.yarn.service.client;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptReport;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.service.ClientAMProtocol;
+import org.apache.hadoop.yarn.service.ServiceTestUtils;
+import org.apache.hadoop.yarn.service.api.records.Service;
+import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.Matchers;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link ServiceClient}.
+ */
+public class TestServiceClient {
+
+  @Rule
+  public ServiceTestUtils.ServiceFSWatcher rule =
+      new ServiceTestUtils.ServiceFSWatcher();
+
+  @Test
+  public void testActionUpgrade() throws Exception {
+    ApplicationId applicationId = ApplicationId.newInstance(
+        System.currentTimeMillis(), 1);
+    ServiceClient client = createServiceClient(applicationId);
+
+    Service service = ServiceTestUtils.createExampleApplication();
+    service.setVersion("v1");
+    client.actionCreate(service);
+
+    //upgrade the service
+    service.setVersion("v2");
+    client.actionUpgrade(service);
+
+    //wait for service to be in upgrade state
+    Service fromFs = ServiceApiUtil.loadServiceUpgrade(rule.getFs(),
+        service.getName(), service.getVersion());
+    Assert.assertEquals(service.getName(), fromFs.getName());
+    Assert.assertEquals(service.getVersion(), fromFs.getVersion());
+  }
+
+
+  private ServiceClient createServiceClient(ApplicationId applicationId)
+      throws Exception {
+    ClientAMProtocol amProxy = mock(ClientAMProtocol.class);
+    YarnClient yarnClient = createMockYarnClient();
+    ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(
+        applicationId, 1);
+    ApplicationAttemptReport attemptReport =
+        ApplicationAttemptReport.newInstance(attemptId, "localhost", 0,
+            null, null, null,
+        YarnApplicationAttemptState.RUNNING, null);
+
+    ApplicationReport appReport = mock(ApplicationReport.class);
+    when(appReport.getHost()).thenReturn("localhost");
+
+    when(yarnClient.getApplicationAttemptReport(Matchers.any()))
+        .thenReturn(attemptReport);
+    when(yarnClient.getApplicationReport(applicationId)).thenReturn(appReport);
+
+    ServiceClient client = new ServiceClient() {
+      @Override
+      protected void serviceInit(Configuration configuration) throws Exception 
{
+      }
+
+      @Override
+      protected ClientAMProtocol createAMProxy(String serviceName,
+          ApplicationReport appReport) throws IOException, YarnException {
+        return amProxy;
+      }
+
+      @Override
+      ApplicationId submitApp(Service app) throws IOException, YarnException {
+        return applicationId;
+      }
+    };
+
+    client.setFileSystem(rule.getFs());
+    client.setYarnClient(yarnClient);
+
+    client.init(rule.getConf());
+    client.start();
+    return client;
+  }
+
+  private YarnClient createMockYarnClient() throws IOException, YarnException {
+    YarnClient yarnClient = mock(YarnClient.class);
+    
when(yarnClient.getApplications(Matchers.any(GetApplicationsRequest.class)))
+        .thenReturn(new ArrayList<>());
+    return yarnClient;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/27d60a16/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestCoreFileSystem.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/utils/TestCoreFileSystem.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/utils/TestCoreFileSystem.java
new file mode 100644
index 0000000..ba4a658
--- /dev/null
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/test/java/org/apache/hadoop/yarn/service/utils/TestCoreFileSystem.java
@@ -0,0 +1,46 @@
+/**
+ * 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.hadoop.yarn.service.utils;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.service.ServiceTestUtils;
+import org.apache.hadoop.yarn.service.conf.YarnServiceConstants;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests for {@link CoreFileSystem}.
+ */
+public class TestCoreFileSystem {
+
+  @Rule
+  public ServiceTestUtils.ServiceFSWatcher rule =
+      new ServiceTestUtils.ServiceFSWatcher();
+
+  @Test
+  public void testClusterUpgradeDirPath() {
+    String serviceName = "testClusterUpgrade";
+    String version = "v1";
+    Path expectedPath = new Path(rule.getFs().buildClusterDirPath(serviceName),
+        YarnServiceConstants.UPGRADE_DIR + "/" + version);
+    Assert.assertEquals("incorrect upgrade path", expectedPath,
+        rule.getFs().buildClusterUpgradeDirPath(serviceName, version));
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/27d60a16/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java
----------------------------------------------------------------------
diff --git 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java
 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java
index a09663e..d5eb787 100644
--- 
a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java
+++ 
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/api/AppAdminClient.java
@@ -229,4 +229,20 @@ public abstract class AppAdminClient extends 
CompositeService {
   @Unstable
   public abstract String getStatusString(String appIdOrName) throws
       IOException, YarnException;
+
+  /**
+   * Upgrade a long running service.
+   *
+   * @param appName the name of the application
+   * @param fileName specification of application upgrade to save.
+   *
+   * @return exit code
+   * @throws IOException IOException
+   * @throws YarnException exception in client or server
+   */
+  @Public
+  @Unstable
+  public abstract int actionUpgrade(String appName, String fileName)
+      throws IOException, YarnException;
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to