incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject svn commit: r1497565 - in /incubator/ambari/trunk/ambari-server/src: main/java/org/apache/ambari/server/api/handlers/ main/java/org/apache/ambari/server/api/services/ main/java/org/apache/ambari/server/controller/ main/java/org/apache/ambari/server/con...
Date Thu, 27 Jun 2013 21:12:35 GMT
Author: ncole
Date: Thu Jun 27 21:12:35 2013
New Revision: 1497565

URL: http://svn.apache.org/r1497565
Log:
AMBARI-2504. Added default_base_url when updating stack repo URLs (ncole)

Modified:
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/UpdateHandler.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RepositoryResponse.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.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/RepositoryResourceProviderTest.java

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/UpdateHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/UpdateHandler.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/UpdateHandler.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/UpdateHandler.java
Thu Jun 27 21:12:35 2013
@@ -50,6 +50,8 @@ public class UpdateHandler extends BaseM
 
     } catch (UnsupportedPropertyException e) {
       result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
+    } catch (IllegalArgumentException e) {
+      result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e));
     } catch (NoSuchParentResourceException e) {
       result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.NOT_FOUND, e));
     } catch (NoSuchResourceException e) {

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
Thu Jun 27 21:12:35 2013
@@ -84,6 +84,7 @@ public class AmbariMetaInfo {
   private static final String REPOSITORY_XML_ATTRIBUTE_OS_TYPE = "type";
   private static final String REPOSITORY_XML_REPO_BLOCK_NAME = "repo";
   private static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
+  private static final String REPOSITORY_XML_PROPERTY_DEFAULT_BASEURL = "default_baseurl";
   private static final String REPOSITORY_XML_PROPERTY_REPOID = "repoid";
   private static final String REPOSITORY_XML_PROPERTY_REPONAME = "reponame";
   private static final String REPOSITORY_XML_PROPERTY_MIRRORSLIST = "mirrorslist";
@@ -343,8 +344,16 @@ public class AmbariMetaInfo {
                 
                 if (xmlRepoId.equals(repoId)) {
                   NodeList nl = property.getElementsByTagName(REPOSITORY_XML_PROPERTY_BASEURL);
-                  for (int k = 0; k < nl.getLength(); k++) {
-                    nl.item(k).setTextContent(baseUrl);
+                  if (null != nl && nl.getLength() > 0) {
+                    String defaultBaseUrl = getTagValue(REPOSITORY_XML_PROPERTY_DEFAULT_BASEURL,
property);
+                    if (null == defaultBaseUrl) {
+                      Node n = doc.createElement(REPOSITORY_XML_PROPERTY_DEFAULT_BASEURL);
+                      n.setTextContent(nl.item(0).getTextContent());
+                      if (null != ri)
+                        ri.setDefaultBaseUrl(nl.item(0).getTextContent());
+                      property.appendChild(n);
+                    }
+                    nl.item(0).setTextContent(baseUrl);
                   }
                 }
               }
@@ -893,14 +902,11 @@ public class AmbariMetaInfo {
             continue;
           }
           Element property = (Element) repoNode;
-          String repoId = getTagValue(REPOSITORY_XML_PROPERTY_REPOID,
-              property);
-          String repoName = getTagValue(REPOSITORY_XML_PROPERTY_REPONAME,
-              property);
-          String baseUrl = getTagValue(
-              REPOSITORY_XML_PROPERTY_BASEURL, property);
-          String mirrorsList = getTagValue(
-              REPOSITORY_XML_PROPERTY_MIRRORSLIST, property);
+          String repoId = getTagValue(REPOSITORY_XML_PROPERTY_REPOID, property);
+          String repoName = getTagValue(REPOSITORY_XML_PROPERTY_REPONAME, property);
+          String baseUrl = getTagValue(REPOSITORY_XML_PROPERTY_BASEURL, property);
+          String mirrorsList = getTagValue(REPOSITORY_XML_PROPERTY_MIRRORSLIST, property);
+          String defaultBaseUrl = getTagValue(REPOSITORY_XML_PROPERTY_DEFAULT_BASEURL, property);
 
           String[] osTypes = osType.split(",");
 
@@ -911,6 +917,7 @@ public class AmbariMetaInfo {
             repositoryInfo.setRepoName(repoName);
             repositoryInfo.setBaseUrl(baseUrl);
             repositoryInfo.setMirrorsList(mirrorsList);
+            repositoryInfo.setDefaultBaseUrl(defaultBaseUrl);
 
             if (LOG.isDebugEnabled()) {
               LOG.debug("Adding repo to stack"

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
Thu Jun 27 21:12:35 2013
@@ -19,9 +19,18 @@
 package org.apache.ambari.server.controller;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.InetAddress;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
@@ -44,6 +53,7 @@ import org.apache.ambari.server.actionma
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.internal.URLStreamProvider;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;
@@ -82,6 +92,7 @@ import org.apache.ambari.server.state.sv
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUpgradeEvent;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -146,6 +157,9 @@ public class AmbariManagementControllerI
 
   final private static String JDK_RESOURCE_LOCATION =
       "/resources/";
+  
+  final private static int REPO_URL_CONNECT_TIMEOUT = 2000;
+  final private static int REPO_URL_READ_TIMEOUT = 500;
 
   final private String jdkResourceUrl;
   final private String ojdbcUrl;
@@ -4310,9 +4324,17 @@ public class AmbariManagementControllerI
       
       if (null != rr.getBaseUrl()) {
         // verify url is accessible
-        ambariMetaInfo.updateRepository(rr.getStackName(),
-            rr.getStackVersion(), rr.getOsType(), rr.getRepoId(),
-            rr.getBaseUrl());
+        URLStreamProvider usp = new URLStreamProvider(
+            REPO_URL_CONNECT_TIMEOUT, REPO_URL_READ_TIMEOUT);
+        try {
+          IOUtils.readLines(usp.readFrom(rr.getBaseUrl()));
+          ambariMetaInfo.updateRepository(rr.getStackName(),
+              rr.getStackVersion(), rr.getOsType(), rr.getRepoId(),
+              rr.getBaseUrl());
+        }
+        catch (IOException ioe) {
+          throw new IllegalArgumentException("Could not access base_url '" + rr.getBaseUrl(),
ioe);
+        }
       }
     }
   }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RepositoryResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RepositoryResponse.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RepositoryResponse.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RepositoryResponse.java
Thu Jun 27 21:12:35 2013
@@ -25,14 +25,17 @@ public class RepositoryResponse {
   private String repoId;
   private String repoName;
   private String mirrorsList;
+  private String defaultBaseUrl;
   
   
-  public RepositoryResponse(String baseUrl, String osType, String repoId, String repoName,
String mirrorsList) {
+  public RepositoryResponse(String baseUrl, String osType, String repoId,
+      String repoName, String mirrorsList, String defaultBaseUrl) {
     setBaseUrl(baseUrl);
     setOsType(osType);
     setRepoId(repoId);
     setRepoName(repoName);
     setMirrorsList(mirrorsList);
+    setDefaultBaseUrl(defaultBaseUrl);
   }
 
 
@@ -70,20 +73,25 @@ public class RepositoryResponse {
     return repoName;
   }
 
-
   public void setRepoName(String repoName) {
     this.repoName = repoName;
   }
 
-
   public String getMirrorsList() {
     return mirrorsList;
   }
 
-
   public void setMirrorsList(String mirrorsList) {
     this.mirrorsList = mirrorsList;
   }
+  
+  public String getDefaultBaseUrl() {
+    return defaultBaseUrl;
+  }
+  
+  public void setDefaultBaseUrl(String url) {
+    this.defaultBaseUrl = url;
+  }
 
 
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
Thu Jun 27 21:12:35 2013
@@ -69,6 +69,9 @@ public class RepositoryResourceProvider 
   public static final String REPOSITORY_MIRRORS_LIST_PROPERTY_ID = PropertyHelper
       .getPropertyId("Repositories", "mirrors_list");
   
+  public static final String REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID = PropertyHelper
+      .getPropertyId("Repositories", "default_base_url");
+  
 
   private static Set<String> pkPropertyIds = new HashSet<String>(
       Arrays.asList(new String[] { STACK_NAME_PROPERTY_ID,
@@ -148,6 +151,9 @@ public class RepositoryResourceProvider 
 
         setResourceProperty(resource, REPOSITORY_MIRRORS_LIST_PROPERTY_ID,
             response.getMirrorsList(), requestedIds);
+        
+        setResourceProperty(resource, REPOSITORY_DEFAULT_BASE_URL_PROPERTY_ID,
+            response.getDefaultBaseUrl(), requestedIds);
 
         resources.add(resource);
     }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryInfo.java
Thu Jun 27 21:12:35 2013
@@ -26,6 +26,7 @@ public class RepositoryInfo {
   private String repoId;
   private String repoName;
   private String mirrorsList;
+  private String defaultBaseUrl;
 
   /**
    * @return the baseUrl
@@ -96,6 +97,20 @@ public class RepositoryInfo {
   public void setMirrorsList(String mirrorsList) {
     this.mirrorsList = mirrorsList;
   }
+  
+  /**
+   * @return the default base url
+   */
+  public String getDefaultBaseUrl() {
+    return defaultBaseUrl;
+  }
+
+  /**
+   * @param url the default base url to set
+   */
+  public void setDefaultBaseUrl(String url) {
+    defaultBaseUrl = url;
+  }
 
   @Override
   public String toString() {
@@ -111,6 +126,6 @@ public class RepositoryInfo {
   
   public RepositoryResponse convertToResponse()
   {
-    return new RepositoryResponse(getBaseUrl(), getOsType(), getRepoId(), getRepoName(),
getMirrorsList());
+    return new RepositoryResponse(getBaseUrl(), getOsType(), getRepoId(), getRepoName(),
getMirrorsList(), getDefaultBaseUrl());
   }
 }

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=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/properties.json (original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/properties.json Thu Jun 27 21:12:35
2013
@@ -135,6 +135,7 @@
         "Repositories/repo_id",
         "Repositories/repo_name",
         "Repositories/mirrors_list",
+        "Repositories/default_base_url",
         "_"
     ],
     "StackService":[

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=1497565&r1=1497564&r2=1497565&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 Jun 27 21:12:35 2013
@@ -444,10 +444,16 @@ public class AmbariMetaInfoTest {
     
     try {
       RepositoryInfo repository = metaInfo.getRepository(STACK_NAME_HDP, STACK_VERSION_HDP,
OS_TYPE, REPO_ID);
+      String defaultBaseUrl = repository.getDefaultBaseUrl();
+      Assert.assertNull(defaultBaseUrl);
+      
+      // what it will expected to be
+      defaultBaseUrl = repository.getBaseUrl();
       
       metaInfo.updateRepository(STACK_NAME_HDP, STACK_VERSION_HDP, OS_TYPE, REPO_ID, TMP_URL1);
       repository = metaInfo.getRepository(STACK_NAME_HDP, STACK_VERSION_HDP, OS_TYPE, REPO_ID);
       Assert.assertEquals(TMP_URL1, repository.getBaseUrl());
+      Assert.assertEquals(defaultBaseUrl, repository.getDefaultBaseUrl());
       
       // reload from disk
       AmbariMetaInfo metaInfo1 = new AmbariMetaInfo(tmp, new File("target/version"));

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryResourceProviderTest.java?rev=1497565&r1=1497564&r2=1497565&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryResourceProviderTest.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryResourceProviderTest.java
Thu Jun 27 21:12:35 2013
@@ -57,7 +57,7 @@ public class RepositoryResourceProviderT
     AmbariManagementController managementController = EasyMock.createMock(AmbariManagementController.class);
 
     RepositoryResponse rr = new RepositoryResponse(VAL_BASE_URL, VAL_OS,
-        VAL_REPO_ID, VAL_REPO_NAME, null);
+        VAL_REPO_ID, VAL_REPO_NAME, null, null);
     Set<RepositoryResponse> allResponse = new HashSet<RepositoryResponse>();
     allResponse.add(rr);
     
@@ -126,7 +126,7 @@ public class RepositoryResourceProviderT
     AmbariManagementController managementController = EasyMock.createMock(AmbariManagementController.class);
 
     RepositoryResponse rr = new RepositoryResponse(VAL_BASE_URL, VAL_OS,
-        VAL_REPO_ID, VAL_REPO_NAME, null);
+        VAL_REPO_ID, VAL_REPO_NAME, null, null);
     Set<RepositoryResponse> allResponse = new HashSet<RepositoryResponse>();
     allResponse.add(rr);    
     
@@ -145,7 +145,7 @@ public class RepositoryResourceProviderT
 
     // add the property map to a set for the request.
     Map<String, Object> properties = new LinkedHashMap<String, Object>();
-    properties.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http://bar.com");
+    properties.put(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, "http://garbage.eu.co");
 
     // create the request
     Request request = PropertyHelper.getUpdateRequest(properties, null);



Mime
View raw message