SLIDER-59 added name, version, and description fields/tags to slider app listing and made minor unit test corrections for failing tests

git-svn-id: https://svn.apache.org/repos/asf/incubator/slider/trunk@1595332 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
index 225cce5..a7bdd14 100644
--- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
+++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java
@@ -121,6 +121,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 /**
  * Client service for Slider
@@ -688,13 +689,18 @@
     }
     MapOperations sliderAMResourceComponent =
       resourceOperations.getOrAddComponent(SliderKeys.COMPONENT_AM);
+
+    // add the tags if available
+    Set<String> applicationTags = provider.getApplicationTags(sliderFileSystem,
+      appOperations.getGlobalOptions().get(AgentKeys.APP_DEF));
     AppMasterLauncher amLauncher = new AppMasterLauncher(clustername,
         SliderKeys.APP_TYPE,
         config,
         sliderFileSystem,
         yarnClient,
         clusterSecure,
-        sliderAMResourceComponent);
+        sliderAMResourceComponent,
+        applicationTags);
 
     ApplicationId appId = amLauncher.getApplicationId();
     // set the application name;
diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java
index 3ff6b62..a61e6bb 100644
--- a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java
+++ b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java
@@ -79,6 +79,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.TreeSet;
@@ -525,9 +526,14 @@
   public static String appReportToString(ApplicationReport r, String separator) {
     StringBuilder builder = new StringBuilder(512);
     builder.append("application ").append(
-      r.getName()).append("/").append(r.getApplicationType());
-    builder.append(separator).append(
-      "state: ").append(r.getYarnApplicationState());
+      r.getName()).append("/").append(r.getApplicationType()).append(separator);
+    Set<String> tags = r.getApplicationTags();
+    if (!tags.isEmpty()) {
+      for (String tag : tags) {
+        builder.append(tag).append(separator);
+      }
+    }
+    builder.append("state: ").append(r.getYarnApplicationState());
     builder.append(separator).append("URL: ").append(r.getTrackingUrl());
     builder.append(separator).append("Started ").append(new Date(r.getStartTime()).toGMTString());
     long finishTime = r.getFinishTime();
diff --git a/slider-core/src/main/java/org/apache/slider/core/launch/AppMasterLauncher.java b/slider-core/src/main/java/org/apache/slider/core/launch/AppMasterLauncher.java
index 85b022a..dc4a886 100644
--- a/slider-core/src/main/java/org/apache/slider/core/launch/AppMasterLauncher.java
+++ b/slider-core/src/main/java/org/apache/slider/core/launch/AppMasterLauncher.java
@@ -36,6 +36,7 @@
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.Set;
 
 public class AppMasterLauncher extends AbstractLauncher {
 
@@ -73,7 +74,8 @@
                            CoreFileSystem fs,
                            SliderYarnClientImpl yarnClient,
                            boolean secureCluster,
-                           Map<String, String> options
+                           Map<String, String> options,
+                           Set<String> applicationTags
                           ) throws IOException, YarnException {
     super(conf, fs);
     this.yarnClient = yarnClient;
@@ -88,6 +90,9 @@
     submissionContext.setApplicationName(name);
     // app type used in service enum;
     submissionContext.setApplicationType(type);
+    if (!applicationTags.isEmpty()) {
+      submissionContext.setApplicationTags(applicationTags);
+    }
     extractResourceRequirements(resource, options);
 
   }
diff --git a/slider-core/src/main/java/org/apache/slider/providers/AbstractClientProvider.java b/slider-core/src/main/java/org/apache/slider/providers/AbstractClientProvider.java
index 1736636..1ff56a9 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/AbstractClientProvider.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/AbstractClientProvider.java
@@ -32,7 +32,9 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 import static org.apache.slider.api.ResourceKeys.COMPONENT_INSTANCES;
 import static org.apache.slider.api.ResourceKeys.DEF_YARN_CORES;
@@ -207,4 +209,13 @@
     validateInstanceDefinition(instanceDefinition);
   }
 
+  /**
+   * Return a set of application specific string tags.
+   * @return the set of tags.
+   */
+  public Set<String> getApplicationTags (SliderFileSystem fileSystem,
+                                         String appDef) throws SliderException {
+    return Collections.emptySet();
+  }
+
 }
diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java
index e15667b..9f082f8 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentClientProvider.java
@@ -34,11 +34,14 @@
 import org.apache.slider.providers.AbstractClientProvider;
 import org.apache.slider.providers.ProviderRole;
 import org.apache.slider.providers.ProviderUtils;
+import org.apache.slider.providers.agent.application.metadata.Metainfo;
+import org.apache.slider.providers.agent.application.metadata.Service;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -194,4 +197,23 @@
       IOException,
       SliderException {
   }
+
+  @Override
+  public Set<String> getApplicationTags(SliderFileSystem fileSystem,
+                                        String appDef) throws SliderException {
+    Set<String> tags;
+    try {
+      Metainfo metainfo = AgentUtils.getApplicationMetainfo(fileSystem, appDef);
+      Service service = metainfo.getServices().get(0);
+      tags = new HashSet<>();
+      tags.add("Name: " + service.getName());
+      tags.add("Version: " + service.getVersion());
+      tags.add("Description: " + service.getComment());
+    } catch (IOException e) {
+      log.error("error retrieving metainfo from {}", appDef, e);
+      throw new SliderException("error retrieving metainfo", e);
+    }
+
+    return tags;
+  }
 }
diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java
index d3ce958..b246dac 100644
--- a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java
+++ b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentProviderService.java
@@ -242,17 +242,7 @@
 
   protected Metainfo getApplicationMetainfo(SliderFileSystem fileSystem,
                                             String appDef) throws IOException {
-    log.info("Reading metainfo at {}", appDef);
-    InputStream metainfoStream = SliderUtils.getApplicationResourceInputStream(
-        fileSystem.getFileSystem(), new Path(appDef), "metainfo.xml");
-    if (metainfoStream == null) {
-      log.error("metainfo.xml is unavailable at {}.", appDef);
-      throw new IOException("metainfo.xml is required in app package.");
-    }
-
-    Metainfo metainfo = new MetainfoParser().parse(metainfoStream);
-
-    return metainfo;
+    return AgentUtils.getApplicationMetainfo(fileSystem, appDef);
   }
 
   protected void publishComponentConfiguration(String name, String description,
diff --git a/slider-core/src/main/java/org/apache/slider/providers/agent/AgentUtils.java b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentUtils.java
new file mode 100644
index 0000000..f296a95
--- /dev/null
+++ b/slider-core/src/main/java/org/apache/slider/providers/agent/AgentUtils.java
@@ -0,0 +1,51 @@
+/*
+ * 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.slider.providers.agent;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.slider.common.tools.SliderFileSystem;
+import org.apache.slider.common.tools.SliderUtils;
+import org.apache.slider.providers.agent.application.metadata.Metainfo;
+import org.apache.slider.providers.agent.application.metadata.MetainfoParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ *
+ */
+public class AgentUtils {
+  private static final Logger log = LoggerFactory.getLogger(AgentUtils.class);
+
+  static Metainfo getApplicationMetainfo(SliderFileSystem fileSystem,
+                                            String appDef) throws IOException {
+    log.info("Reading metainfo at {}", appDef);
+    InputStream metainfoStream = SliderUtils.getApplicationResourceInputStream(
+        fileSystem.getFileSystem(), new Path(appDef), "metainfo.xml");
+    if (metainfoStream == null) {
+      log.error("metainfo.xml is unavailable at {}.", appDef);
+      throw new IOException("metainfo.xml is required in app package.");
+    }
+
+    Metainfo metainfo = new MetainfoParser().parse(metainfoStream);
+
+    return metainfo;
+  }
+
+}
diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
index b8eecf1..6818be4 100644
--- a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneRegistryAM.groovy
@@ -194,7 +194,7 @@
 
 
     describe("Registry List")
-    log.info(GET(registryURL, RestPaths.REGISTRY_SERVICE ))
+    log.info(GET(registryURL))
 
 
     describe "Registry Retrieval Class"
diff --git a/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy b/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
index df5c23b..303cc73 100644
--- a/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/registry/curator/TestRegistryRestResources.groovy
@@ -116,18 +116,17 @@
     //WS get
     Client client = createTestClient();
 
-    // test the exposed WADL link
     WebResource webResource = client.resource(registry_url);
-    ClientResponse response = webResource.type(MediaType.APPLICATION_XML)
-           .get(ClientResponse.class);
-    assert response.status == 200
-    assert response.type == (new MediaType("application", WADL))
+    List<String> serviceList = webResource.type(MediaType.APPLICATION_JSON)
+           .get(List.class);
+    log.info("service list: {}", serviceList)
+    assert serviceList.contains(SliderKeys.APP_TYPE)
 
     // test the available GET URIs
     webResource = client.resource(
         appendToURL(registry_url, RestPaths.REGISTRY_SERVICE));
-    
-    response = webResource.type(MediaType.APPLICATION_JSON)
+
+    ClientResponse response = webResource.type(MediaType.APPLICATION_JSON)
                           .get(ClientResponse.class);
     def responseStr = response.getEntity(String.class)
     log.info("response is " + responseStr)
diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider.java b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider.java
new file mode 100644
index 0000000..69f5a1c
--- /dev/null
+++ b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAgentClientProvider.java
@@ -0,0 +1,49 @@
+/*
+ * 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.slider.providers.agent;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.slider.common.tools.SliderFileSystem;
+import org.apache.slider.common.tools.SliderUtils;
+import org.junit.Test;
+
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ *
+ */
+public class TestAgentClientProvider {
+  @Test
+  public void testGetApplicationTags () throws Exception {
+    Configuration configuration = new Configuration();
+    FileSystem fs = FileSystem.getLocal(configuration);
+    SliderFileSystem sliderFileSystem = new SliderFileSystem(fs, configuration);
+
+    AgentClientProvider provider = new AgentClientProvider(null);
+    Set<String> tags = provider.getApplicationTags(sliderFileSystem,
+      "target/test-classes/org/apache/slider/common/tools/test.zip");
+    assert tags != null;
+    assert !tags.isEmpty();
+    assert tags.contains("Name: STORM");
+    assert tags.contains("Description: Apache Hadoop Stream processing framework");
+    assert tags.contains("Version: 0.9.1.2.1");
+
+  }
+}