You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/04/18 19:10:58 UTC

svn commit: r1469457 - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ ambari-server/src/main/resources/ ambari-server/src/test/ja...

Author: smohanty
Date: Thu Apr 18 17:10:57 2013
New Revision: 1469457

URL: http://svn.apache.org/r1469457
Log:
AMBARI-1972. Stacks2 api implemenation using the standard framework is not complete - does not show configuration tags. (smohanty)

Added:
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProviderTest.java
Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/StackConfigurationResponse.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProvider.java
    incubator/ambari/trunk/ambari-server/src/main/resources/properties.json
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1469457&r1=1469456&r2=1469457&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Thu Apr 18 17:10:57 2013
@@ -760,6 +760,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1972. Stacks2 api implemenation using the standard framework is not
+ complete - does not show configuration tags. (smohanty)
+
  AMBARI-1954. Dashboard does not come up if the upgrade stack does not contain
  a service with the same name. (yusaku)
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/StackConfigurationResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/StackConfigurationResponse.java?rev=1469457&r1=1469456&r2=1469457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/StackConfigurationResponse.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/StackConfigurationResponse.java Thu Apr 18 17:10:57 2013
@@ -22,17 +22,18 @@ package org.apache.ambari.server.control
 public class StackConfigurationResponse {
 
   
-  public StackConfigurationResponse(String propertyName, String propertyValue, String propertyDescription, String fileName) {
+  public StackConfigurationResponse(String propertyName, String propertyValue, String propertyDescription, String type) {
     setPropertyName(propertyName);
     setPropertyValue(propertyValue);
     setPropertyDescription(propertyDescription);
-    setFileName(fileName);
+    setType(type);
   }
   
   private String propertyName;
   private String propertyValue;
   private String propertyDescription;
-  private String fileName;
+  private String type;
+
 
   public String getPropertyName() {
     return propertyName;
@@ -58,11 +59,11 @@ public class StackConfigurationResponse 
     this.propertyDescription = propertyDescription;
   }
 
-  public String getFileName() {
-    return fileName;
+  public String getType() {
+    return type;
   }
-
-  public void setFileName(String fileName) {
-    this.fileName = fileName;
+  
+  public void setType(String type) {
+    this.type = type;
   }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProvider.java?rev=1469457&r1=1469456&r2=1469457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProvider.java Thu Apr 18 17:10:57 2013
@@ -43,26 +43,27 @@ import org.apache.ambari.server.controll
 public class StackConfigurationResourceProvider extends
     ReadOnlyResourceProvider {
 
-  private static final String STACK_NAME_PROPERTY_ID = PropertyHelper
+  public static final String STACK_NAME_PROPERTY_ID = PropertyHelper
       .getPropertyId("StackConfigurations", "stack_name");
 
-  private static final String STACK_VERSION_PROPERTY_ID = PropertyHelper
+  public static final String STACK_VERSION_PROPERTY_ID = PropertyHelper
       .getPropertyId("StackConfigurations", "stack_version");
 
-  private static final String SERVICE_NAME_PROPERTY_ID = PropertyHelper
+  public static final String SERVICE_NAME_PROPERTY_ID = PropertyHelper
       .getPropertyId("StackConfigurations", "service_name");
 
-  private static final String PROPERTY_NAME_PROPERTY_ID = PropertyHelper
+  public static final String PROPERTY_NAME_PROPERTY_ID = PropertyHelper
       .getPropertyId("StackConfigurations", "property_name");
 
-  private static final String PROPERTY_VALUE_PROPERTY_ID = PropertyHelper
+  public static final String PROPERTY_VALUE_PROPERTY_ID = PropertyHelper
       .getPropertyId("StackConfigurations", "property_value");
 
-  private static final String PROPERTY_DESCRIPTION_PROPERTY_ID = PropertyHelper
+  public static final String PROPERTY_DESCRIPTION_PROPERTY_ID = PropertyHelper
       .getPropertyId("StackConfigurations", "property_description");
 
-  private static final String PROPERTY_FILE_NAME_PROPERTY_ID = PropertyHelper
-      .getPropertyId("StackConfigurations", "filename");
+  public static final String PROPERTY_TYPE_PROPERTY_ID = PropertyHelper
+      .getPropertyId("StackConfigurations", "type");
+
 
   private static Set<String> pkPropertyIds = new HashSet<String>(
       Arrays.asList(new String[] { STACK_NAME_PROPERTY_ID,
@@ -113,9 +114,9 @@ public class StackConfigurationResourceP
 
       setResourceProperty(resource, PROPERTY_DESCRIPTION_PROPERTY_ID,
           response.getPropertyDescription(), requestedIds);
-
-      setResourceProperty(resource, PROPERTY_FILE_NAME_PROPERTY_ID,
-          response.getFileName(), requestedIds);
+      
+      setResourceProperty(resource, PROPERTY_TYPE_PROPERTY_ID,
+          response.getType(), requestedIds);
 
       resources.add(resource);
     }

Modified: incubator/ambari/trunk/ambari-server/src/main/resources/properties.json
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/properties.json?rev=1469457&r1=1469456&r2=1469457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/properties.json (original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/properties.json Thu Apr 18 17:10:57 2013
@@ -153,7 +153,7 @@
         "StackConfigurations/property_name",
         "StackConfigurations/property_value",
         "StackConfigurations/property_description",
-        "StackConfigurations/filename",
+        "StackConfigurations/type",
         "_"
     ],
     "StackServiceComponent":[

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java?rev=1469457&r1=1469456&r2=1469457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java Thu Apr 18 17:10:57 2013
@@ -72,6 +72,7 @@ public class AmbariMetaInfoTest {
   private AmbariMetaInfo metaInfo = null;
   private final static Logger LOG =
       LoggerFactory.getLogger(AmbariMetaInfoTest.class);
+  private static final String FILE_NAME = "hbase-site.xml";
   
 
   @Rule
@@ -386,6 +387,7 @@ public class AmbariMetaInfoTest {
   public void testGetProperty() throws Exception {
     PropertyInfo property = metaInfo.getProperty(STACK_NAME_HDP, STACK_VERSION_HDP, SERVICE_NAME_HDFS, PROPERTY_NAME);
     Assert.assertEquals(property.getName(), PROPERTY_NAME);
+    Assert.assertEquals(property.getFilename(), FILE_NAME);
 
     try {
       metaInfo.getProperty(STACK_NAME_HDP, STACK_VERSION_HDP, SERVICE_NAME_HDFS, NON_EXT_VALUE);

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java?rev=1469457&r1=1469456&r2=1469457&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java Thu Apr 18 17:10:57 2013
@@ -27,6 +27,7 @@ import org.apache.ambari.server.controll
 import org.apache.ambari.server.controller.ServiceComponentHostRequest;
 import org.apache.ambari.server.controller.ServiceComponentRequest;
 import org.apache.ambari.server.controller.ServiceRequest;
+import org.apache.ambari.server.controller.StackConfigurationRequest;
 import org.apache.ambari.server.controller.TaskStatusRequest;
 import org.apache.ambari.server.controller.UserRequest;
 import org.apache.ambari.server.controller.spi.Resource;
@@ -207,6 +208,13 @@ public class AbstractResourceProviderTes
       EasyMock.reportMatcher(new UserRequestSetMatcher(name));
       return null;
     }
+    
+    public static Set<StackConfigurationRequest> getStackConfigurationRequestSet(String stackName, String stackVersion,
+        String serviceName, String propertyName)
+    {
+      EasyMock.reportMatcher(new StackConfigurationRequestSetMatcher(stackName, stackVersion, serviceName, propertyName));
+      return null;
+    }
   }
 
   /**
@@ -558,6 +566,48 @@ public class AbstractResourceProviderTes
       stringBuffer.append("UserRequestSetMatcher(").append(userRequest).append(")");
     }
   }
+  
+
+  /**
+   * Matcher for a Stack set containing a single request.
+   */
+  public static class StackConfigurationRequestSetMatcher extends HashSet<StackConfigurationRequest> implements IArgumentMatcher {
+
+    private final StackConfigurationRequest stackConfigurationRequest;
+
+    public StackConfigurationRequestSetMatcher(String stackName, String stackVersion,
+        String serviceName, String propertyName) {
+      this.stackConfigurationRequest = new StackConfigurationRequest(stackName, stackVersion, serviceName, propertyName);
+      add(this.stackConfigurationRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof StackConfigurationRequest &&
+          eq(((StackConfigurationRequest) request).getPropertyName(), stackConfigurationRequest.getPropertyName()) &&
+          eq(((StackConfigurationRequest) request).getServiceName(), stackConfigurationRequest.getServiceName()) &&
+          eq(((StackConfigurationRequest) request).getStackName(), stackConfigurationRequest.getStackName()) &&
+          eq(((StackConfigurationRequest) request).getStackVersion(), stackConfigurationRequest.getStackVersion());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("StackConfigurationRequestSetMatcher(").append(stackConfigurationRequest).append(")");
+    }
+  }
 
   /**
    * A test observer that records the last event.

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProviderTest.java?rev=1469457&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProviderTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackConfigurationResourceProviderTest.java Thu Apr 18 17:10:57 2013
@@ -0,0 +1,106 @@
+/**
+ * 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.ambari.server.controller.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.StackConfigurationResponse;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StackConfigurationResourceProviderTest {
+  
+  private static final String PROPERTY_NAME = "name";
+  private static final String PROPERTY_VALUE = "value";
+  private static final String PROPERTY_DESC = "Desc";
+  private static final String TYPE = "type.xml";
+
+  @Test
+  public void testGetResources() throws Exception{
+       
+    Resource.Type type = Resource.Type.StackConfiguration;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+
+    Set<StackConfigurationResponse> allResponse = new HashSet<StackConfigurationResponse>();
+    
+    allResponse.add(new StackConfigurationResponse(PROPERTY_NAME, PROPERTY_VALUE, PROPERTY_DESC, TYPE));
+   
+    // set expectations
+    expect(managementController.getStackConfigurations(
+        AbstractResourceProviderTest.Matcher.getStackConfigurationRequestSet(null, null, null, null))).
+        andReturn(allResponse).times(1);
+    // replay
+    replay(managementController);
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(StackConfigurationResourceProvider.STACK_NAME_PROPERTY_ID);
+    propertyIds.add(StackConfigurationResourceProvider.STACK_VERSION_PROPERTY_ID);
+    propertyIds.add(StackConfigurationResourceProvider.SERVICE_NAME_PROPERTY_ID);
+    propertyIds.add(StackConfigurationResourceProvider.PROPERTY_NAME_PROPERTY_ID);
+    propertyIds.add(StackConfigurationResourceProvider.PROPERTY_VALUE_PROPERTY_ID);
+    propertyIds.add(StackConfigurationResourceProvider.PROPERTY_DESCRIPTION_PROPERTY_ID);
+    propertyIds.add(StackConfigurationResourceProvider.PROPERTY_TYPE_PROPERTY_ID);
+
+    // create the request
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+
+    // get all ... no predicate
+    Set<Resource> resources = provider.getResources(request, null);
+
+    Assert.assertEquals(allResponse.size(), resources.size());
+    
+    for (Resource resource : resources) {   
+      String propertyName = (String) resource.getPropertyValue(StackConfigurationResourceProvider.PROPERTY_NAME_PROPERTY_ID);
+      String propertyValue = (String) resource.getPropertyValue(StackConfigurationResourceProvider.PROPERTY_VALUE_PROPERTY_ID);
+      String propertyDesc = (String) 
+          resource.getPropertyValue(StackConfigurationResourceProvider.PROPERTY_DESCRIPTION_PROPERTY_ID);
+      String propertyType = (String) 
+          resource.getPropertyValue(StackConfigurationResourceProvider.PROPERTY_TYPE_PROPERTY_ID);
+      
+      Assert.assertEquals(PROPERTY_NAME, propertyName);
+      Assert.assertEquals(PROPERTY_VALUE, propertyValue);
+      Assert.assertEquals(PROPERTY_DESC, propertyDesc);
+      Assert.assertEquals(TYPE, propertyType);
+
+    }
+
+    // verify
+    verify(managementController);
+  } 
+
+}