You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2012/11/07 09:13:24 UTC
svn commit: r1406489 [3/19] - in /incubator/ambari/branches/AMBARI-666: ./
ambari-agent/ ambari-agent/conf/ ambari-agent/conf/unix/
ambari-agent/src/main/puppet/manifestloader/
ambari-agent/src/main/puppet/modules/configgenerator/manifests/
ambari-agen...
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HostInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HostInfo.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HostInfo.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HostInfo.java Wed Nov 7 08:13:12 2012
@@ -65,7 +65,7 @@ public class HostInfo {
public String getArchitecture() {
return this.architecture;
}
-
+
@JsonProperty("architecture")
public void setArchitecture(String architecture) {
this.architecture = architecture;
@@ -75,7 +75,7 @@ public class HostInfo {
public String getDomain() {
return this.domain;
}
-
+
@JsonProperty("domain")
public void setDomain(String domain) {
this.domain = domain;
@@ -85,7 +85,7 @@ public class HostInfo {
public String getFQDN() {
return this.fqdn;
}
-
+
@JsonProperty("fqdn")
public void setFQDN(String fqdn) {
this.fqdn = fqdn;
@@ -100,7 +100,7 @@ public class HostInfo {
public void setHardwareIsa(String hardwareisa) {
this.hardwareisa = hardwareisa;
}
-
+
@JsonProperty("hardwaremodel")
public String getHardwareModel() {
return this.hardwaremodel;
@@ -115,7 +115,7 @@ public class HostInfo {
public String getHostName() {
return this.hostname;
}
-
+
@JsonProperty("hostname")
public void setHostName(String hostname) {
this.hostname = hostname;
@@ -135,7 +135,7 @@ public class HostInfo {
public String getInterfaces() {
return this.interfaces;
}
-
+
@JsonProperty("interfaces")
public void setInterfaces(String interfaces) {
this.interfaces = interfaces;
@@ -145,7 +145,7 @@ public class HostInfo {
public String getIPAddress() {
return this.ipaddress;
}
-
+
@JsonProperty("ipaddress")
public void setIPAddress(String ipaddress) {
this.ipaddress = ipaddress;
@@ -160,27 +160,27 @@ public class HostInfo {
public void setKernel(String kernel) {
this.kernel = kernel;
}
-
+
@JsonProperty("kernelmajversion")
public String getKernelMajVersion() {
return this.kernelmajversion;
}
-
+
@JsonProperty("kernelmajversion")
public void setKernelMajVersion(String kernelmajversion) {
this.kernelmajversion = kernelmajversion;
}
-
+
@JsonProperty("kernelrelease")
public String getKernelRelease() {
return this.kernelrelease;
}
-
+
@JsonProperty("kernelrelease")
public void setKernelRelease(String kernelrelease) {
this.kernelrelease = kernelrelease;
}
-
+
@JsonProperty("kernelversion")
public String getKernelVersion() {
return this.kernelversion;
@@ -205,32 +205,32 @@ public class HostInfo {
public long getFreeMemory() {
return this.memoryfree;
}
-
+
@JsonProperty("memoryfree")
public void setFreeMemory(long memoryfree) {
this.memoryfree = memoryfree;
}
-
+
@JsonProperty("memorysize")
public long getMemorySize() {
return this.memorysize;
}
-
+
@JsonProperty("memorysize")
public void setMemorySize(long memorysize) {
this.memorysize = memorysize;
}
-
+
@JsonProperty("mounts")
public List<DiskInfo> getMounts() {
return this.mounts;
}
-
+
@JsonProperty("mounts")
public void setMounts(List<DiskInfo> mounts) {
this.mounts = mounts;
}
-
+
@JsonProperty("memorytotal")
public long getMemoryTotal() {
return this.memorytotal;
@@ -240,12 +240,12 @@ public class HostInfo {
public void setMemoryTotal(long memorytotal) {
this.memorytotal = memorytotal;
}
-
+
@JsonProperty("netmask")
public String getNetMask() {
return this.netmask;
}
-
+
@JsonProperty("netmask")
public void setNetMask(String netmask) {
this.netmask = netmask;
@@ -255,7 +255,7 @@ public class HostInfo {
public String getOS() {
return this.operatingsystem;
}
-
+
@JsonProperty("operatingsystem")
public void setOS(String operatingsystem) {
this.operatingsystem = operatingsystem;
@@ -265,27 +265,27 @@ public class HostInfo {
public String getOSRelease() {
return this.operatingsystemrelease;
}
-
+
@JsonProperty("operatingsystemrelease")
public void setOSRelease(String operatingsystemrelease) {
this.operatingsystemrelease = operatingsystemrelease;
}
-
+
@JsonProperty("osfamily")
public String getOSFamily() {
return this.osfamily;
}
-
+
@JsonProperty("osfamily")
public void setOSFamily(String osfamily) {
this.osfamily = osfamily;
}
-
+
@JsonProperty("physicalprocessorcount")
public int getPhysicalProcessorCount() {
return this.physicalprocessorcount;
}
-
+
@JsonProperty("physicalprocessorcount")
public void setPhysicalProcessorCount(int physicalprocessorcount) {
this.physicalprocessorcount = physicalprocessorcount;
@@ -295,7 +295,7 @@ public class HostInfo {
public int getProcessorCount() {
return this.processorcount;
}
-
+
@JsonProperty("processorcount")
public void setProcessorCount(int processorcount) {
this.processorcount = processorcount;
@@ -305,37 +305,37 @@ public class HostInfo {
public boolean getSeLinux() {
return selinux;
}
-
+
@JsonProperty("selinux")
public void setSeLinux(boolean selinux) {
this.selinux = selinux;
}
-
+
@JsonProperty("swapfree")
public String getSwapFree() {
return this.swapfree;
}
-
+
@JsonProperty("swapfree")
public void setSwapFree(String swapfree) {
this.swapfree = swapfree;
}
-
+
@JsonProperty("swapsize")
public String getSwapSize() {
return swapsize;
}
-
+
@JsonProperty("swapsize")
public void setSwapSize(String swapsize) {
this.swapsize = swapsize;
}
-
+
@JsonProperty("timezone")
public String getTimeZone() {
return this.timezone;
}
-
+
@JsonProperty("timezone")
public void setTimeZone(String timezone) {
this.timezone = timezone;
@@ -345,7 +345,7 @@ public class HostInfo {
public String getUptime() {
return this.uptime;
}
-
+
@JsonProperty("uptime")
public void setUpTime(String uptime) {
this.uptime = uptime;
@@ -355,7 +355,7 @@ public class HostInfo {
public long getUptimeHours() {
return this.uptime_hours;
}
-
+
@JsonProperty("uptime_hours")
public void setUpTimeHours(long uptime_hours) {
this.uptime_hours = uptime_hours;
@@ -365,24 +365,36 @@ public class HostInfo {
public long getUpTimeDays() {
return this.uptime_days;
}
-
+
@JsonProperty("uptime_days")
public void setUpTimeDays(long uptime_days) {
this.uptime_days = uptime_days;
}
private String getDiskString() {
- String ret = "";
+ if (mounts == null) {
+ return null;
+ }
+ StringBuilder ret = new StringBuilder();
for (DiskInfo diskInfo : mounts) {
- ret = ret + "(" + diskInfo.toString() + ")";
+ ret.append("(").append(diskInfo.toString()).append(")");
}
- return ret;
+ return ret.toString();
}
public String toString() {
- return "[memory=" + this.memorytotal + "," +
+ return "[" +
+ "hostname=" + this.hostname + "," +
+ "fqdn=" + this.fqdn + "," +
+ "domain=" + this.domain + "," +
+ "architecture=" + this.architecture + "," +
+ "processorcount=" + this.processorcount + "," +
+ "physicalprocessorcount=" + this.physicalprocessorcount + "," +
+ "osname=" + this.operatingsystem + "," +
+ "osversion=" + this.operatingsystemrelease + "," +
+ "osfamily=" + this.osfamily + "," +
+ "memory=" + this.memorytotal + "," +
"uptime_hours=" + this.uptime_hours + "," +
- "operatingsystem=" + this.operatingsystem + "," +
"mounts=" + getDiskString() + "]\n";
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java Wed Nov 7 08:13:12 2012
@@ -100,7 +100,7 @@ public class AgentResource {
public HeartBeatResponse heartbeat(HeartBeat message)
throws WebApplicationException {
LOG.info("Received Heartbeat message " + message);
- HeartBeatResponse heartBeatResponse = new HeartBeatResponse();
+ HeartBeatResponse heartBeatResponse;
try {
heartBeatResponse = hh.handleHeartBeat(message);
} catch (Exception e) {
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java Wed Nov 7 08:13:12 2012
@@ -22,6 +22,12 @@ import org.apache.ambari.server.api.reso
import org.apache.ambari.server.api.services.Request;
import org.apache.ambari.server.api.services.Result;
import org.apache.ambari.server.api.services.ResultImpl;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+
+import java.util.Set;
/**
* Base handler for operations that persist state to the back-end.
@@ -31,9 +37,59 @@ public class BaseManagementHandler imple
public Result handleRequest(Request request) {
ResourceDefinition resource = request.getResourceDefinition();
resource.setProperties(request.getHttpBodyProperties());
- request.getPersistenceManager().persist(resource);
+ RequestStatus status = request.getPersistenceManager().persist(resource);
+
+ return createResult(request, status);
+ }
+
+ private Result createResult(Request request, RequestStatus requestStatus) {
+ boolean isSynchronous = requestStatus.getStatus() == RequestStatus.Status.Complete;
+
+ Result result = new ResultImpl(isSynchronous);
+ TreeNode<Resource> tree = result.getResultTree();
+
+ Set<Resource> setResources = requestStatus.getAssociatedResources();
+ TreeNode<Resource> resourcesNode = null;
+ if (! setResources.isEmpty()) {
+ resourcesNode = tree.addChild(null, "resources");
+ }
+ int count = 1;
+ for (Resource resource : setResources) {
+ //todo: provide a more meaningful node name
+ resourcesNode.addChild(resource, resource.getType() + ":" + count++);
+ }
+
+ if (! isSynchronous) {
+ Resource requestResource = requestStatus.getRequestResource();
+ TreeNode<Resource> r = tree.addChild(requestResource, "request");
+ String requestHref = buildRequestHref(request, requestStatus);
+ r.setProperty("href", requestHref);
+ }
+
+ return result;
+ }
+
+ //todo: this needs to be rewritten and needs to support operating on clusters collection
+ private String buildRequestHref(Request request, RequestStatus requestStatus) {
+ StringBuilder sb = new StringBuilder();
+ String origHref = request.getURI();
+ String[] toks = origHref.split("/");
+
+ for (int i = 0; i < toks.length; ++i) {
+ String s = toks[i];
+ sb.append(s).append('/');
+ if ("clusters".equals(s)) {
+ sb.append(toks[i + 1]).append('/');
+ break;
+ }
+ }
+
+ //todo: shouldn't know property name
+ Object requestId = requestStatus.getRequestResource().getPropertyValue(
+ PropertyHelper.getPropertyId("id", "Requests"));
+
+ sb.append("requests/").append(requestId);
- //todo: what to return from persist? Possibly just the href of the updated resource.
- return new ResultImpl();
+ return sb.toString();
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/RequestHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/RequestHandlerFactory.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/RequestHandlerFactory.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/RequestHandlerFactory.java Wed Nov 7 08:13:12 2012
@@ -35,9 +35,9 @@ public class RequestHandlerFactory {
switch (requestType) {
case GET:
return new ReadHandler();
- case PUT:
- return new CreateHandler();
case POST:
+ return new CreateHandler();
+ case PUT:
return new UpdateHandler();
case DELETE:
return new DeleteHandler();
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/query/QueryImpl.java Wed Nov 7 08:13:12 2012
@@ -21,6 +21,7 @@ package org.apache.ambari.server.api.que
import org.apache.ambari.server.api.resources.ResourceDefinition;
import org.apache.ambari.server.api.services.ResultImpl;
import org.apache.ambari.server.api.util.TreeNodeImpl;
+import org.apache.ambari.server.controller.internal.ClusterControllerImpl;
import org.apache.ambari.server.controller.internal.PropertyIdImpl;
import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
@@ -31,6 +32,9 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.api.services.Result;
import org.apache.ambari.server.controller.spi.*;
import org.apache.ambari.server.api.util.TreeNode;
+import org.mortbay.log.Log;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.*;
@@ -53,6 +57,9 @@ public class QueryImpl implements Query
*/
private Map<PropertyId, TemporalInfo> m_mapPropertyTemporalInfo = new HashMap<PropertyId, TemporalInfo>();
+ /**
+ * Map that associates categories with temporal data.
+ */
private Map<String, TemporalInfo> m_mapCategoryTemporalInfo = new HashMap<String, TemporalInfo>();
/**
@@ -75,7 +82,8 @@ public class QueryImpl implements Query
*/
private Predicate m_userPredicate;
-
+ private final static Logger LOG =
+ LoggerFactory.getLogger(QueryImpl.class);
/**
* Constructor.
*
@@ -145,16 +153,23 @@ public class QueryImpl implements Query
int count = 1;
for (Resource resource : iterResource) {
// add a child node for the resource and provide a unique name. The name is never used.
+ //todo: provide a more meaningful node name
TreeNode<Resource> node = tree.addChild(resource, resource.getType() + ":" + count++);
-
- for (Map.Entry<String, ResourceDefinition> entry : m_mapSubResources.entrySet()) {
+ LOG.info("Resource object resource " + resource);
+ for (Map.Entry<String, ResourceDefinition> entry : m_mapSubResources.entrySet()) {
String subResCategory = entry.getKey();
ResourceDefinition r = entry.getValue();
-
- r.setParentId(m_resourceDefinition.getType(), (String) resource.getPropertyValue(
+
+ r.setParentId(m_resourceDefinition.getType(), (String) (resource.getPropertyValue(
getClusterController().getSchema(m_resourceDefinition.getType()).
- getKeyPropertyId(m_resourceDefinition.getType())));
-
+ getKeyPropertyId(m_resourceDefinition.getType())).toString()));
+
+ LOG.info("Setting various values for resource " + r.getId());
+ if (r.getResourceIds() != null) {
+ for (Map.Entry<Resource.Type, String> tentry: r.getResourceIds().entrySet()) {
+ LOG.info("Resource Id's " + tentry.getKey() + " value " + tentry.getValue());
+ }
+ }
TreeNode<Resource> childResult = r.getQuery().execute().getResultTree();
childResult.setName(subResCategory);
childResult.setProperty("isCollection", "false");
@@ -344,6 +359,6 @@ public class QueryImpl implements Query
}
Result createResult() {
- return new ResultImpl();
+ return new ResultImpl(true);
}
}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ActionResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ActionResourceDefinition.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ActionResourceDefinition.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ActionResourceDefinition.java Wed Nov 7 08:13:12 2012
@@ -0,0 +1,55 @@
+/**
+ * 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.api.resources;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+
+public class ActionResourceDefinition extends BaseResourceDefinition {
+
+ private String m_clusterName;
+ private String m_serviceName;
+
+ public ActionResourceDefinition(String id, String clusterName, String serviceName) {
+ super(Resource.Type.Action, id);
+ m_clusterName = clusterName;
+ m_serviceName = serviceName;
+ setResourceId(Resource.Type.Cluster, m_clusterName);
+ setResourceId(Resource.Type.Service, m_serviceName);
+ getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Action).getKeyPropertyId(Resource.Type.Action));
+ }
+
+ @Override
+ public String getPluralName() {
+ return "actions";
+ }
+
+ @Override
+ public String getSingularName() {
+ return "action";
+ }
+
+ @Override
+ public Map<String, ResourceDefinition> getSubResources() {
+ return new HashMap<String, ResourceDefinition>();
+ }
+}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClusterResourceDefinition.java Wed Nov 7 08:13:12 2012
@@ -21,7 +21,6 @@ package org.apache.ambari.server.api.res
import java.util.HashMap;
import java.util.Map;
-import org.apache.ambari.server.controller.spi.PropertyId;
import org.apache.ambari.server.controller.spi.Resource;
/**
@@ -58,23 +57,25 @@ public class ClusterResourceDefinition e
Map<String, ResourceDefinition> mapChildren = new HashMap<String, ResourceDefinition>();
ServiceResourceDefinition serviceResource = new ServiceResourceDefinition(null, getId());
- PropertyId serviceIdProperty = getClusterController().getSchema(
- Resource.Type.Service).getKeyPropertyId(Resource.Type.Service);
- serviceResource.getQuery().addProperty(serviceIdProperty);
+ serviceResource.getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Service).getKeyPropertyId(Resource.Type.Service));
mapChildren.put(serviceResource.getPluralName(), serviceResource);
HostResourceDefinition hostResource = new HostResourceDefinition(null, getId());
- PropertyId hostIdProperty = getClusterController().getSchema(
- Resource.Type.Host).getKeyPropertyId(Resource.Type.Host);
- hostResource.getQuery().addProperty(hostIdProperty);
+ hostResource.getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Host).getKeyPropertyId(Resource.Type.Host));
mapChildren.put(hostResource.getPluralName(), hostResource);
ConfigurationResourceDefinition configResource = new ConfigurationResourceDefinition(null, null, getId());
- PropertyId configIdProperty = getClusterController().getSchema(
- Resource.Type.Configuration).getKeyPropertyId(Resource.Type.Configuration);
- configResource.getQuery().addProperty(configIdProperty);
+ configResource.getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Configuration).getKeyPropertyId(Resource.Type.Configuration));
mapChildren.put(configResource.getPluralName(), configResource);
+ RequestResourceDefinition requestResource = new RequestResourceDefinition(null, getId());
+ requestResource.getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Request).getKeyPropertyId(Resource.Type.Request));
+ mapChildren.put(requestResource.getPluralName(), requestResource);
+
return mapChildren;
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ConfigurationResourceDefinition.java Wed Nov 7 08:13:12 2012
@@ -22,16 +22,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.ambari.server.api.resources.ResourceDefinition.PostProcessor;
import org.apache.ambari.server.api.services.Request;
import org.apache.ambari.server.api.util.TreeNode;
import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.controller.spi.Schema;
-import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
/**
- * Service resource definition.
+ * Configuration resource definition.
*/
public class ConfigurationResourceDefinition extends BaseResourceDefinition {
@@ -40,28 +37,30 @@ public class ConfigurationResourceDefini
*/
private String m_clusterId;
+
/**
* Constructor.
*
- * @param id service id value
- * @param clusterId cluster id value
+ * @param configType configuration type
+ * @param configTag configuration tag
+ * @param clusterId cluster id value
*/
public ConfigurationResourceDefinition(String configType, String configTag, String clusterId) {
super(Resource.Type.Configuration, configType);
m_clusterId = clusterId;
setResourceId(Resource.Type.Cluster, m_clusterId);
-
+
if (null != configTag)
setProperty(PropertyHelper.getPropertyId("tag", "Config"), configTag);
}
-
+
@Override
public List<PostProcessor> getPostProcessors() {
List<PostProcessor> listProcessors = super.getPostProcessors();
listProcessors.add(new HrefProcessor());
return listProcessors;
- }
+ }
@Override
public String getPluralName() {
@@ -77,7 +76,7 @@ public class ConfigurationResourceDefini
public Map<String, ResourceDefinition> getSubResources() {
return new HashMap<String, ResourceDefinition>();
}
-
+
private class HrefProcessor extends BaseHrefPostProcessor {
@Override
@@ -87,15 +86,18 @@ public class ConfigurationResourceDefini
String clusterId = getResourceIds().get(Resource.Type.Cluster);
String type = (String) resultNode.getObject().getPropertyValue(PropertyHelper.getPropertyId("type"));
String tag = (String) resultNode.getObject().getPropertyValue(PropertyHelper.getPropertyId("tag"));
-
+
+ if (! href.endsWith("/")) {
+ href += '/';
+ }
href = href.substring(0, href.indexOf(clusterId) + clusterId.length() + 1) +
"configurations?type=" + type + "&tag=" + tag;
-
+
resultNode.setProperty("href", href);
} else {
super.process(request, resultNode, href);
}
-
+
}
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/HostResourceDefinition.java Wed Nov 7 08:13:12 2012
@@ -18,10 +18,13 @@
package org.apache.ambari.server.api.resources;
-import org.apache.ambari.server.controller.spi.PropertyId;
+
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import java.util.*;
/**
* Host resource definition.
@@ -43,6 +46,17 @@ public class HostResourceDefinition exte
super(Resource.Type.Host, id);
m_clusterId = clusterId;
setResourceId(Resource.Type.Cluster, m_clusterId);
+
+ if (null != clusterId) {
+ getQuery().addProperty(PropertyHelper.getPropertyId("cluster_name", "Hosts"));
+ }
+
+ if (null == id) {
+ getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Host).getKeyPropertyId(Resource.Type.Host));
+ } else {
+ getQuery().addProperty(null, "*", null);
+ }
}
@Override
@@ -59,12 +73,15 @@ public class HostResourceDefinition exte
public Map<String, ResourceDefinition> getSubResources() {
Map<String, ResourceDefinition> mapChildren = new HashMap<String, ResourceDefinition>();
- HostComponentResourceDefinition hostComponentResource = new HostComponentResourceDefinition(
- null, m_clusterId, getId());
- PropertyId hostComponentIdProperty = getClusterController().getSchema(
- Resource.Type.HostComponent).getKeyPropertyId(Resource.Type.HostComponent);
- hostComponentResource.getQuery().addProperty(hostComponentIdProperty);
- mapChildren.put(hostComponentResource.getPluralName(), hostComponentResource);
+ // !!! is this a host for a cluster
+ if (null != m_clusterId) {
+ HostComponentResourceDefinition hostComponentResource =
+ new HostComponentResourceDefinition(null, m_clusterId, getId());
+ hostComponentResource.getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.HostComponent).getKeyPropertyId(Resource.Type.HostComponent));
+ mapChildren.put(hostComponentResource.getPluralName(), hostComponentResource);
+ }
+
return mapChildren;
}
}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java Wed Nov 7 08:13:12 2012
@@ -0,0 +1,73 @@
+/**
+ * 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.api.resources;
+
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Request resource definition.
+ */
+public class RequestResourceDefinition extends BaseResourceDefinition {
+
+ /**
+ * value of cluster id foreign key
+ */
+ private String m_clusterId;
+
+
+ /**
+ * Constructor.
+ *
+ * @param id operation id value
+ * @param clusterId cluster id value
+ */
+ public RequestResourceDefinition(String id, String clusterId) {
+ super(Resource.Type.Request, id);
+ m_clusterId = clusterId;
+ setResourceId(Resource.Type.Cluster, m_clusterId);
+ }
+
+ @Override
+ public String getPluralName() {
+ return "requests";
+ }
+
+ @Override
+ public String getSingularName() {
+ return "request";
+ }
+
+ @Override
+ public Map<String, ResourceDefinition> getSubResources() {
+ Map<String, ResourceDefinition> mapChildren = new HashMap<String, ResourceDefinition>();
+
+ TaskResourceDefinition taskResourceDefinition =
+ new TaskResourceDefinition(null, m_clusterId, getId());
+ taskResourceDefinition.getQuery().addProperty(getClusterController().getSchema(
+ Resource.Type.Task).getKeyPropertyId(Resource.Type.Task));
+ mapChildren.put(taskResourceDefinition.getPluralName(), taskResourceDefinition);
+
+ return mapChildren;
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/TaskResourceDefinition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/TaskResourceDefinition.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/TaskResourceDefinition.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/resources/TaskResourceDefinition.java Wed Nov 7 08:13:12 2012
@@ -0,0 +1,71 @@
+/**
+ * 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.api.resources;
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+import java.util.Collections;
+import java.util.Map;
+
+
+/**
+ * Task resource definition.
+ */
+public class TaskResourceDefinition extends BaseResourceDefinition {
+
+ /**
+ * Value of cluster id foreign key.
+ */
+ private String m_clusterId;
+
+ /**
+ * Value of request id foreign key.
+ */
+ private String m_requestId;
+
+
+ /**
+ * Constructor.
+ *
+ * @param id task id value
+ * @param clusterId cluster id value
+ */
+ public TaskResourceDefinition(String id, String clusterId, String requestId) {
+ super(Resource.Type.Task, id);
+ m_clusterId = clusterId;
+ m_requestId = requestId;
+ setResourceId(Resource.Type.Cluster, m_clusterId);
+ setResourceId(Resource.Type.Request, m_requestId);
+ }
+
+ @Override
+ public String getPluralName() {
+ return "tasks";
+ }
+
+ @Override
+ public String getSingularName() {
+ return "task";
+ }
+
+ @Override
+ public Map<String, ResourceDefinition> getSubResources() {
+ return Collections.emptyMap();
+ }
+}
\ No newline at end of file
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/rest/HealthCheck.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/rest/HealthCheck.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/rest/HealthCheck.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/rest/HealthCheck.java Wed Nov 7 08:13:12 2012
@@ -30,7 +30,7 @@ import javax.ws.rs.core.MediaType;
@Path("/check")
public class HealthCheck {
- private final String status = "RUNNING";
+ private static final String status = "RUNNING";
// This method is called if TEXT_PLAIN is request
@GET
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ActionService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ActionService.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ActionService.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ActionService.java Wed Nov 7 08:13:12 2012
@@ -0,0 +1,124 @@
+/**
+ * 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.api.services;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.ambari.server.api.resources.ActionResourceDefinition;
+import org.apache.ambari.server.api.resources.ResourceDefinition;
+
+public class ActionService extends BaseService {
+ /**
+ * Parent cluster name.
+ */
+ private String m_clusterName;
+
+ private String m_serviceName;
+
+ /**
+ * Constructor.
+ *
+ * @param clusterName cluster id
+ * @param serviceName service
+ */
+ public ActionService(String clusterName, String serviceName) {
+ m_clusterName = clusterName;
+ m_serviceName = serviceName;
+ }
+
+ /**
+ * Handles URL: /clusters/{clusterId}/services/{serviceName}/actions
+ * Get all actions for a service in a cluster.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @return service collection resource representation
+ */
+ @GET
+ @Produces("text/plain")
+ public Response getActions(@Context HttpHeaders headers, @Context UriInfo ui) {
+ return handleRequest(headers, null, ui, Request.Type.GET,
+ createResourceDefinition(null, m_clusterName, m_serviceName));
+ }
+
+ /**
+ * Handles URL: /clusters/{clusterId}/services/{serviceName}/actions.
+ * The body should contain:
+ * <pre>
+ * {
+ * "actionName":"name_string",
+ * "parameters":
+ * {
+ * "key1":"value1",
+ * // ...
+ * "keyN":"valueN"
+ * }
+ * }
+ * </pre>
+ * Get all services for a cluster.
+ *
+ * @param headers http headers
+ * @param ui uri info
+ * @return service collection resource representation
+ */
+ @POST
+ @Produces("text/plain")
+ public Response createActions(String body,@Context HttpHeaders headers, @Context UriInfo ui) {
+ return handleRequest(headers, body, ui, Request.Type.POST,
+ createResourceDefinition(null, m_clusterName, m_serviceName));
+ }
+
+ /**
+ * Handles: POST /clusters/{clusterId}/services/{serviceId}/{actionName}
+ * Create a specific service.
+ *
+ * @param body http body
+ * @param headers http headers
+ * @param ui uri info
+ * @param serviceName service id
+ * @return information regarding the created service
+ */
+ @POST
+ @Path("{actionName}")
+ @Produces("text/plain")
+ public Response createService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
+ @PathParam("actionName") String actionName) {
+ return handleRequest(headers, body, ui, Request.Type.POST,
+ createResourceDefinition(actionName, m_clusterName, m_serviceName));
+ }
+
+ /**
+ * Create a service resource definition.
+ *
+ * @param serviceName host name
+ * @param clusterName cluster name
+ * @return a service resource definition
+ */
+ ResourceDefinition createResourceDefinition(String actionName,
+ String clusterName, String serviceName) {
+ return new ActionResourceDefinition(actionName, clusterName, serviceName);
+ }
+}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java Wed Nov 7 08:13:12 2012
@@ -18,38 +18,54 @@
package org.apache.ambari.server.api.services;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.state.PropertyInfo;
-import org.apache.ambari.server.state.RepositoryInfo;
-import org.apache.ambari.server.state.ServiceInfo;
-import org.apache.ambari.server.state.StackInfo;
-
-import javax.ws.rs.Path;
import java.io.File;
import java.io.IOException;
-import java.util.*;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.PropertyInfo;
+import org.apache.ambari.server.state.RepositoryInfo;
+import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.StackInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Node;
import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
/**
* ServiceInfo responsible getting information about cluster.
*/
-@Path("/metainfo/")
+@Singleton
public class AmbariMetaInfo {
private List<StackInfo> stacksResult = new ArrayList<StackInfo>();
-
- private final static Logger log = LoggerFactory.getLogger(AmbariMetaInfo.class);
+ private File stackRoot;
+ private final static Logger LOG = LoggerFactory
+ .getLogger(AmbariMetaInfo.class);
private static final String SERVICES_FOLDER_NAME = "services";
private static final String SERVICE_METAINFO_FILE_NAME = "metainfo.xml";
@@ -58,23 +74,196 @@ public class AmbariMetaInfo {
private static final String REPOSITORY_FILE_NAME = "repoinfo.xml";
private static final String REPOSITORY_FOLDER_NAME = "repos";
- private static final String REPOSITORY_XML_MAIN_BLOCK_NAME = "repo";
- private static final String REPOSITORY_XML_PROPERTY_URL = "url";
- private static final String REPOSITORY_XML_PROPERTY_OS = "os";
- private static final String REPOSITORY_XML_PROPERTY_DESCRIPTION = "description";
+ private static final String REPOSITORY_XML_MAIN_BLOCK_NAME = "os";
+ 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_REPOID = "repoid";
+ private static final String REPOSITORY_XML_PROPERTY_REPONAME = "reponame";
+ private static final String REPOSITORY_XML_PROPERTY_MIRRORSLIST = "mirrorslist";
private static final String METAINFO_XML_MAIN_BLOCK_NAME = "metainfo";
private static final String METAINFO_XML_PROPERTY_VERSION = "version";
private static final String METAINFO_XML_PROPERTY_USER = "user";
private static final String METAINFO_XML_PROPERTY_COMMENT = "comment";
+ private static final String METAINFO_XML_PROPERTY_COMPONENT_MAIN = "component";
+ private static final String METAINFO_XML_PROPERTY_COMPONENT_NAME = "name";
+ private static final String METAINFO_XML_PROPERTY_COMPONENT_CATEGORY = "category";
private static final String PROPERTY_XML_MAIN_BLOCK_NAME = "property";
private static final String PROPERTY_XML_PROPERTY_NAME = "name";
private static final String PROPERTY_XML_PROPERTY_VALUE = "value";
private static final String PROPERTY_XML_PROPERTY_DESCRIPTION = "description";
+
+ /**
+ * Ambari Meta Info Object
+ * @param conf Configuration API to be used.
+ * @throws Exception
+ */
+ @Inject
+ public AmbariMetaInfo(Configuration conf) throws Exception {
+ String stackPath = conf.getMetadataPath();
+ this.stackRoot = new File(stackPath);
+ }
+
+ @Inject
+ public AmbariMetaInfo(File stackRoot) throws Exception {
+ this.stackRoot = stackRoot;
+ }
+
+
+ /**
+ * Initialize the Ambari Meta Info
+ * @throws Exception throws exception if not able to parse the Meta data.
+ */
+ public void init() throws Exception {
+ getConfigurationInformation(stackRoot);
+ }
+
+
+ /**
+ * Get component category
+ * @param stackName
+ * @param version
+ * @param serviceName
+ * @param componentName
+ * @return component component Info
+ */
+ public ComponentInfo getComponentCategory(String stackName, String version,
+ String serviceName, String componentName) {
+ ComponentInfo component = null;
+ List<ComponentInfo> components = getComponentsByService(stackName, version,
+ serviceName);
+ if (components != null)
+ for (ComponentInfo cmp : components) {
+ if (cmp.getName().equals(componentName)) {
+ component = cmp;
+ break;
+ }
+ }
+ return component;
+ }
+
+
+ /**
+ * Get components by service
+ * @param stackName
+ * @param version
+ * @param serviceName
+ * @return
+ */
+ public List<ComponentInfo> getComponentsByService(String stackName,
+ String version, String serviceName) {
+ List<ComponentInfo> componentsResult = null;
+ ServiceInfo service = getServiceInfo(stackName, version, serviceName);
+ if (service != null)
+ componentsResult = service.getComponents();
+
+ return componentsResult;
+ }
+
+ public Map<String, List<RepositoryInfo>> getRepository(String stackName,
+ String version) {
+ Map<String, List<RepositoryInfo>> reposResult = null;
+ StackInfo stack = getStackInfo(stackName, version);
+ if (stack != null) {
+ List<RepositoryInfo> repository = stack.getRepositories();
+ reposResult = new HashMap<String, List<RepositoryInfo>>();
+ for (RepositoryInfo repo : repository) {
+ if (!reposResult.containsKey(repo.getOsType())) {
+ reposResult.put(repo.getOsType(),
+ new ArrayList<RepositoryInfo>());
+ }
+ reposResult.get(repo.getOsType()).add(repo);
+ }
+ }
+ return reposResult;
+ }
+
+ /*
+ * function for given a stack name and version, is it a supported stack
+ */
+ public boolean isSupportedStack(String stackName, String version) {
+ boolean exist = false;
+ StackInfo stack = getStackInfo(stackName, version);
+ if (stack == null)
+ exist = true;
+ return exist;
+ }
+
+ /*
+ * support isValidService(), isValidComponent for a given stack/version
+ */
+ public boolean isValidService(String stackName, String version,
+ String serviceName) {
+ ServiceInfo service = getServiceInfo(stackName, version, serviceName);
+ return (service != null);
+ }
+
+ /*
+ * support isValidService(), isValidComponent for a given stack/version
+ */
+ public boolean isValidServiceComponent(String stackName, String version,
+ String serviceName, String componentName) {
+ ServiceInfo service = getServiceInfo(stackName, version, serviceName);
+ if (service == null) {
+ return false;
+ }
+ for (ComponentInfo compInfo: service.getComponents()) {
+ if (compInfo.getName().equals(componentName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * Get the name of a service given the component name.
+ * @param stackName the stack name
+ * @param version the stack version
+ * @param componentName the component name
+ * @return the service name
+ */
+ public String getComponentToService(String stackName, String version,
+ String componentName) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Looking for service for component"
+ + ", stackName=" + stackName
+ + ", stackVersion=" + version
+ + ", componentName=" + componentName);
+ }
+ Map<String, ServiceInfo> services = getServices(stackName, version);
+ String retService = null;
+ if (services == null
+ || services.isEmpty()) {
+ return retService;
+ }
+ boolean found = false;
+ for (Map.Entry<String, ServiceInfo> entry: services.entrySet()) {
+ for (ComponentInfo compInfo: entry.getValue().getComponents()) {
+ if (compInfo.getName().equals(componentName)) {
+ retService = entry.getKey();
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ break;
+ }
+ return retService;
+ }
- public Map<String, Map<String, String>> getSupportedConfigs(String stackName, String version, String serviceName) {
+ /**
+ * Get the service configs supported for a service in a particular stack
+ * @param stackName the stack name
+ * @param version the version of the stack
+ * @param serviceName the name of the service in the stack
+ * @return the config knobs supported for the service
+ */
+ public Map<String, Map<String, String>> getSupportedConfigs(String stackName,
+ String version, String serviceName) {
Map<String, Map<String, String>> propertiesResult = new HashMap<String, Map<String, String>>();
ServiceInfo service = getServiceInfo(stackName, version, serviceName);
@@ -83,14 +272,17 @@ public class AmbariMetaInfo {
List<PropertyInfo> properties = service.getProperties();
if (properties != null)
for (PropertyInfo propertyInfo : properties) {
- Map<String, String> fileProperties = propertiesResult.get(propertyInfo.getFilename());
+ Map<String, String> fileProperties = propertiesResult
+ .get(propertyInfo.getFilename());
if (fileProperties == null) {
fileProperties = new HashMap<String, String>();
- fileProperties.put(propertyInfo.getName(), propertyInfo.getValue());
+ fileProperties.put(propertyInfo.getName(),
+ propertyInfo.getValue());
propertiesResult.put(propertyInfo.getFilename(), fileProperties);
} else {
- fileProperties.put(propertyInfo.getName(), propertyInfo.getValue());
+ fileProperties.put(propertyInfo.getName(),
+ propertyInfo.getValue());
}
}
@@ -99,11 +291,36 @@ public class AmbariMetaInfo {
return propertiesResult;
}
- public ServiceInfo getServiceInfo(String stackName, String version, String serviceName) {
+ /**
+ * Given a stack name and version return all the services with info
+ * @param stackName the stack name
+ * @param version the version of the stack
+ * @return the information of abt varios services that are supported in the
+ * stack
+ */
+ public Map<String, ServiceInfo> getServices(String stackName, String version) {
+
+ Map<String, ServiceInfo> servicesInfoResult = new HashMap<String, ServiceInfo>();
+
+ List<ServiceInfo> services = null;
+ StackInfo stack = getStackInfo(stackName, version);
+ if (stack == null)
+ return null;
+ services = stack.getServices();
+ if (services != null)
+ for (ServiceInfo service : services) {
+ servicesInfoResult.put(service.getName(), service);
+ }
+ return servicesInfoResult;
+ }
+
+ public ServiceInfo getServiceInfo(String stackName, String version,
+ String serviceName) {
ServiceInfo serviceInfoResult = null;
List<ServiceInfo> services = null;
StackInfo stack = getStackInfo(stackName, version);
- if (stack == null) return null;
+ if (stack == null)
+ return null;
services = stack.getServices();
if (services != null)
for (ServiceInfo service : services) {
@@ -123,11 +340,16 @@ public class AmbariMetaInfo {
return servicesResulr;
}
- private StackInfo getStackInfo(String stackName, String version) {
+ public List<StackInfo> getSupportedStacks() {
+ return stacksResult;
+ }
+
+ public StackInfo getStackInfo(String stackName, String version) {
StackInfo stackInfoResult = null;
for (StackInfo stack : stacksResult) {
- if (stackName.equals(stack.getName()) && version.equals(stack.getVersion())) {
+ if (stackName.equals(stack.getName())
+ && version.equals(stack.getVersion())) {
stackInfoResult = stack;
break;
}
@@ -136,75 +358,136 @@ public class AmbariMetaInfo {
}
- List<StackInfo> getSupportedStack() {
- return stacksResult;
- }
-
-
- public AmbariMetaInfo() throws Exception {
- getConfigurationInformation();
- }
-
- private void getConfigurationInformation() throws Exception {
+ private void getConfigurationInformation(File stackRoot) throws Exception {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Loading stack information"
+ + ", stackRoot=" + stackRoot.getPath());
+ }
- File stackRoot = new File(new Configuration().getMetadataPath());//TODO uncomment before commit
-// File stackRoot = new File("src/main/resources/stacks");
if (!stackRoot.isDirectory() && !stackRoot.exists())
- throw new IOException("" + Configuration.METADETA_DIR_PATH + " should be a directory with stack.");
+ throw new IOException("" + Configuration.METADETA_DIR_PATH
+ + " should be a directory with stack.");
File[] stacks = stackRoot.listFiles();
for (File stackFolder : stacks) {
- if (stackFolder.isFile()) continue;
+ if (stackFolder.isFile())
+ continue;
File[] concretStacks = stackFolder.listFiles();
for (File stack : concretStacks) {
- if (stack.isFile()) continue;
+ if (stack.isFile())
+ continue;
StackInfo stackInfo = new StackInfo();
stackInfo.setName(stackFolder.getName());
stackInfo.setVersion(stack.getName());
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding new stack to known stacks"
+ + ", stackName=" + stackFolder.getName()
+ + ", stackVersion=" + stack.getName());
+ }
+
stacksResult.add(stackInfo);
- //get repository data for current stack of techs
- File repositoryFolder = new File(stack.getAbsolutePath() + File.separator + REPOSITORY_FOLDER_NAME + File.separator + REPOSITORY_FILE_NAME);
+ // get repository data for current stack of techs
+ File repositoryFolder = new File(stack.getAbsolutePath()
+ + File.separator + REPOSITORY_FOLDER_NAME + File.separator
+ + REPOSITORY_FILE_NAME);
if (repositoryFolder.exists()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding repositories to stack"
+ + ", stackName=" + stackFolder.getName()
+ + ", stackVersion=" + stack.getName()
+ + ", repoFolder=" + repositoryFolder.getPath());
+ }
List<RepositoryInfo> repositoryInfoList = getRepository(repositoryFolder);
stackInfo.getRepositories().addAll(repositoryInfoList);
}
-
- //Get services for this stack
- File servicesRootFolder = new File(stack.getAbsolutePath() + File.separator + SERVICES_FOLDER_NAME);
+ // Get services for this stack
+ File servicesRootFolder = new File(stack.getAbsolutePath()
+ + File.separator + SERVICES_FOLDER_NAME);
File[] servicesFolders = servicesRootFolder.listFiles();
- if (servicesFolders != null)
+ if (servicesFolders != null) {
for (File serviceFolder : servicesFolders) {
- //Get information about service
+ // Get information about service
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(serviceFolder.getName());
stackInfo.getServices().add(serviceInfo);
- //Get metainfo data from metainfo.xml
- File metainfoFile = new File(serviceFolder.getAbsolutePath() + File.separator + SERVICE_METAINFO_FILE_NAME);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding new service to stack"
+ + ", stackName=" + stackFolder.getName()
+ + ", stackVersion=" + stack.getName()
+ + ", serviceName=" + serviceInfo.getName());
+ }
+
+ // Get metainfo data from metainfo.xml
+ File metainfoFile = new File(serviceFolder.getAbsolutePath()
+ + File.separator + SERVICE_METAINFO_FILE_NAME);
if (metainfoFile.exists()) {
setMetaInfo(metainfoFile, serviceInfo);
-
}
-
- //Get all properties from all "configs/*-site.xml" files
- File serviceConfigFolder = new File(serviceFolder.getAbsolutePath() + File.separator + SERVICE_CONFIG_FOLDER_NAME);
+ // Get all properties from all "configs/*-site.xml" files
+ File serviceConfigFolder = new File(serviceFolder.getAbsolutePath()
+ + File.separator + SERVICE_CONFIG_FOLDER_NAME);
+ LOG.info("Listing config files in folder " + serviceConfigFolder);
File[] configFiles = serviceConfigFolder.listFiles();
- for (File config : configFiles) {
- if (config.getName().endsWith(SERVICE_CONFIG_FILE_NAME_POSTFIX)) {
- serviceInfo.getProperties().addAll(getProperties(config));
+ if (configFiles != null) {
+ for (File config : configFiles) {
+ if (config.getName().endsWith(SERVICE_CONFIG_FILE_NAME_POSTFIX)) {
+ LOG.info("Reading Metadata Info from config filename " +
+ config.getAbsolutePath());
+ serviceInfo.getProperties().addAll(getProperties(config));
+ }
}
}
}
-
+ }
}
}
}
+ /**
+ *
+ * @param node
+ * @return
+ * @throws TransformerException
+ */
+ private String nodeToString(Node node) throws TransformerException {
+ // Set up the output transformer
+ TransformerFactory transfac = TransformerFactory.newInstance();
+ Transformer trans = transfac.newTransformer();
+ trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ trans.setOutputProperty(OutputKeys.INDENT, "yes");
+ StringWriter sw = new StringWriter();
+ StreamResult result = new StreamResult(sw);
+ DOMSource source = new DOMSource(node);
+ trans.transform(source, result);
+ String xmlString = sw.toString();
+ return xmlString;
+ }
+
+ /**
+ * Convert a document to string
+ * @param doc
+ * @return string
+ * @throws TransformerException
+ */
+ private String documentToString(Document doc) throws TransformerException {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+ //initialize StreamResult with File object to save to file
+ StreamResult result = new StreamResult(new StringWriter());
+ DOMSource source = new DOMSource(doc);
+ transformer.transform(source, result);
+
+ String xmlString = result.getWriter().toString();
+ return xmlString;
+ }
private List<RepositoryInfo> getRepository(File repositoryFile) {
@@ -214,21 +497,49 @@ public class AmbariMetaInfo {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(repositoryFile);
- doc.getDocumentElement().normalize();
- NodeList propertyNodes = doc.getElementsByTagName(REPOSITORY_XML_MAIN_BLOCK_NAME);
+ NodeList osNodes = doc
+ .getElementsByTagName(REPOSITORY_XML_MAIN_BLOCK_NAME);
- for (int index = 0; index < propertyNodes.getLength(); index++) {
+ for (int index = 0; index < osNodes.getLength(); index++) {
+ Node osNode = osNodes.item(index);
- Node node = propertyNodes.item(index);
- if (node.getNodeType() == Node.ELEMENT_NODE) {
+ if (osNode.getNodeType() == Node.ELEMENT_NODE) {
+ if (!osNode.getNodeName().equals(REPOSITORY_XML_MAIN_BLOCK_NAME)) {
+ continue;
+ }
+ NamedNodeMap attrs = osNode.getAttributes();
+ Node osAttr = attrs.getNamedItem(REPOSITORY_XML_ATTRIBUTE_OS_TYPE);
+ if (osAttr == null) {
+ continue;
+ }
+ String osType = osAttr.getNodeValue();
- Element property = (Element) node;
- RepositoryInfo repositoryInfo = new RepositoryInfo();
- repositoryInfo.setUrl(getTagValue(REPOSITORY_XML_PROPERTY_URL, property));
- repositoryInfo.setOs(getTagValue(REPOSITORY_XML_PROPERTY_OS, property));
- repositoryInfo.setDescription(getTagValue(REPOSITORY_XML_PROPERTY_DESCRIPTION, property));
- repositorysInfo.add(repositoryInfo);
+ NodeList repoNodes = osNode.getChildNodes();
+ for (int j = 0; j < repoNodes.getLength(); j++) {
+ Node repoNode = repoNodes.item(j);
+ if (repoNode.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+ Element property = (Element) repoNode;
+ RepositoryInfo repositoryInfo = new RepositoryInfo();
+ repositoryInfo.setOsType(osType);
+ repositoryInfo.setRepoId(getTagValue(REPOSITORY_XML_PROPERTY_REPOID,
+ property));
+ repositoryInfo.setRepoName(
+ getTagValue(REPOSITORY_XML_PROPERTY_REPONAME, property));
+
+ repositoryInfo.setBaseUrl(getTagValue(
+ REPOSITORY_XML_PROPERTY_BASEURL, property));
+ repositoryInfo.setMirrorsList(getTagValue(
+ REPOSITORY_XML_PROPERTY_MIRRORSLIST, property));
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding repo to stack"
+ + ", repoInfo=" + repositoryInfo.toString());
+ }
+ repositorysInfo.add(repositoryInfo);
+ }
}
}
@@ -239,7 +550,6 @@ public class AmbariMetaInfo {
return repositorysInfo;
}
-
private void setMetaInfo(File metainfoFile, ServiceInfo serviceInfo) {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
@@ -250,16 +560,17 @@ public class AmbariMetaInfo {
dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(metainfoFile);
} catch (SAXException e) {
- log.error("Error while parsing metainf.xml", e);
+ LOG.error("Error while parsing metainf.xml", e);
} catch (IOException e) {
- log.error("Error while open metainf.xml", e);
+ LOG.error("Error while open metainf.xml", e);
} catch (ParserConfigurationException e) {
- log.error("Error while parsing metainf.xml", e);
+ LOG.error("Error while parsing metainf.xml", e);
}
doc.getDocumentElement().normalize();
- NodeList metaInfoNodes = doc.getElementsByTagName(METAINFO_XML_MAIN_BLOCK_NAME);
+ NodeList metaInfoNodes = doc
+ .getElementsByTagName(METAINFO_XML_MAIN_BLOCK_NAME);
if (metaInfoNodes.getLength() > 0) {
Node metaInfoNode = metaInfoNodes.item(0);
@@ -267,14 +578,36 @@ public class AmbariMetaInfo {
Element metaInfoElem = (Element) metaInfoNode;
- serviceInfo.setVersion(getTagValue(METAINFO_XML_PROPERTY_VERSION, metaInfoElem));
- serviceInfo.setUser(getTagValue(METAINFO_XML_PROPERTY_USER, metaInfoElem));
- serviceInfo.setComment(getTagValue(METAINFO_XML_PROPERTY_COMMENT, metaInfoElem));
+ serviceInfo.setVersion(getTagValue(METAINFO_XML_PROPERTY_VERSION,
+ metaInfoElem));
+ serviceInfo.setUser(getTagValue(METAINFO_XML_PROPERTY_USER,
+ metaInfoElem));
+ serviceInfo.setComment(getTagValue(METAINFO_XML_PROPERTY_COMMENT,
+ metaInfoElem));
}
}
- }
+ NodeList componentInfoNodes = doc
+ .getElementsByTagName(METAINFO_XML_PROPERTY_COMPONENT_MAIN);
+
+ if (componentInfoNodes.getLength() > 0) {
+ for (int index = 0; index < componentInfoNodes.getLength(); index++) {
+ Node componentInfoNode = componentInfoNodes.item(index);
+ if (componentInfoNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element componentInfoElem = (Element) componentInfoNode;
+
+ ComponentInfo componentInfo = new ComponentInfo();
+ componentInfo.setName(getTagValue(
+ METAINFO_XML_PROPERTY_COMPONENT_NAME, componentInfoElem));
+ componentInfo.setCategory(getTagValue(
+ METAINFO_XML_PROPERTY_COMPONENT_CATEGORY, componentInfoElem));
+ serviceInfo.getComponents().add(componentInfo);
+ }
+ }
+ }
+
+ }
private List<PropertyInfo> getProperties(File propertyFile) {
@@ -285,18 +618,22 @@ public class AmbariMetaInfo {
Document doc = dBuilder.parse(propertyFile);
doc.getDocumentElement().normalize();
- NodeList propertyNodes = doc.getElementsByTagName(PROPERTY_XML_MAIN_BLOCK_NAME);
+ NodeList propertyNodes = doc
+ .getElementsByTagName(PROPERTY_XML_MAIN_BLOCK_NAME);
for (int index = 0; index < propertyNodes.getLength(); index++) {
Node node = propertyNodes.item(index);
if (node.getNodeType() == Node.ELEMENT_NODE) {
-
Element property = (Element) node;
PropertyInfo propertyInfo = new PropertyInfo();
- propertyInfo.setName(getTagValue(PROPERTY_XML_PROPERTY_NAME, property));
- propertyInfo.setValue(getTagValue(PROPERTY_XML_PROPERTY_VALUE, property));
- propertyInfo.setDescription(getTagValue(PROPERTY_XML_PROPERTY_DESCRIPTION, property));
+ propertyInfo
+ .setName(getTagValue(PROPERTY_XML_PROPERTY_NAME, property));
+ propertyInfo.setValue(getTagValue(PROPERTY_XML_PROPERTY_VALUE,
+ property));
+
+ propertyInfo.setDescription(getTagValue(
+ PROPERTY_XML_PROPERTY_DESCRIPTION, property));
propertyInfo.setFilename(propertyFile.getName());
if (propertyInfo.getName() == null || propertyInfo.getValue() == null)
@@ -312,15 +649,17 @@ public class AmbariMetaInfo {
return resultPropertyList;
}
-
private String getTagValue(String sTag, Element rawElement) {
String result = null;
try {
- NodeList element = rawElement.getElementsByTagName(sTag).item(0).getChildNodes();
+ NodeList element = rawElement.getElementsByTagName(sTag).item(0)
+ .getChildNodes();
Node value = (Node) element.item(0);
result = value.getNodeValue();
- } catch (NullPointerException e) {
- log.debug("There is no field like " + sTag + "in this DOM element.", e);
+ } catch (Exception e) {
+// LOG.info("Error in getting tag value " , e);
+ // log.debug("There is no field like " + sTag + "in this DOM element.",
+ // e);
} finally {
return result;
}
@@ -328,5 +667,3 @@ public class AmbariMetaInfo {
}
}
-
-
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaService.java?rev=1406489&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaService.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaService.java Wed Nov 7 08:13:12 2012
@@ -0,0 +1,116 @@
+/**
+ * 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.api.services;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBException;
+
+import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.StackInfo;
+import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+import org.codehaus.jackson.map.ser.FilterProvider;
+import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter;
+import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider;
+
+import com.google.inject.Inject;
+
+@Path("/stacks/")
+public class AmbariMetaService {
+ private static AmbariMetaInfo ambariMetainfo;
+ private static Log LOG = LogFactory.getLog(AmbariMetaService.class);
+
+ @Inject
+ public static void init(AmbariMetaInfo instance) {
+ ambariMetainfo = instance;
+ }
+
+ /**
+ * Filter properties from the service info and others
+ * @param object
+ * @return
+ * @throws IOException
+ * @throws JsonMappingException
+ * @throws JsonGenerationException
+ */
+ public String filterProperties(Object object, boolean ignoreConfigs) throws
+ JsonGenerationException, JsonMappingException, IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true);
+ if (ignoreConfigs) {
+ FilterProvider filters = new SimpleFilterProvider().addFilter(
+ "propertiesfilter",
+ SimpleBeanPropertyFilter.serializeAllExcept("properties"));
+ mapper.setFilters(filters);
+ } else {
+ FilterProvider filters = new SimpleFilterProvider().addFilter(
+ "propertiesfilter", SimpleBeanPropertyFilter.serializeAllExcept());
+ mapper.setFilters(filters);
+ }
+ String json = mapper.writeValueAsString(object);
+ return json;
+ }
+
+ @GET
+ @Produces("text/plain")
+ public Response getStacks() throws JsonGenerationException,
+ JsonMappingException, JAXBException, IOException {
+ List<StackInfo> stackInfos = ambariMetainfo.getSupportedStacks();
+ String output = filterProperties(stackInfos, true);
+ return Response.status(Response.Status.OK).entity(output).build();
+ }
+
+ @GET
+ @Path("{stackName}/version/{versionNumber}")
+ @Produces("text/plain")
+ public Response getStack(@PathParam("stackName") String stackName,
+ @PathParam("versionNumber") String versionNumber) throws
+ JsonGenerationException, JsonMappingException, JAXBException, IOException {
+ StackInfo stackInfo = ambariMetainfo.getStackInfo(stackName, versionNumber);
+ String output = filterProperties(stackInfo, true);
+ return Response.status(Response.Status.OK).entity(output).build();
+ }
+
+ @GET
+ @Path("{stackName}/version/{versionNumber}/services/{serviceName}")
+ @Produces("text/plain")
+ public Response getServiceInfo(@PathParam("stackName") String stackName,
+ @PathParam("versionNumber") String versionNumber,
+ @PathParam("serviceName") String serviceName) throws
+ JsonGenerationException, JsonMappingException, JAXBException, IOException {
+ ServiceInfo serviceInfo = ambariMetainfo.getServiceInfo(stackName,
+ versionNumber, serviceName);
+ String output = filterProperties(serviceInfo, false);
+ return Response.status(Response.Status.OK).entity(output).build();
+ }
+
+}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java Wed Nov 7 08:13:12 2012
@@ -37,13 +37,12 @@ public abstract class BaseService {
* This consists of creating a {@link Request} instance, invoking the correct {@link RequestHandler} and
* applying the proper {@link ResultSerializer} to the result.
*
- *
- *
* @param headers http headers
- * @param body
+ * @param body http body
* @param uriInfo uri information
* @param requestType http request type
* @param resourceDefinition resource definition that is being acted on
+ *
* @return the response of the operation in serialized form
*/
protected Response handleRequest(HttpHeaders headers, String body, UriInfo uriInfo, Request.Type requestType,
@@ -52,7 +51,9 @@ public abstract class BaseService {
Request request = getRequestFactory().createRequest(headers, body, uriInfo, requestType, resourceDefinition);
Result result = getRequestHandler().handleRequest(request);
- return getResponseFactory().createResponse(request.getResultSerializer().serialize(result, uriInfo));
+ return getResponseFactory().createResponse(requestType,
+ request.getResultSerializer().serialize(result, uriInfo),
+ result.isSynchronous());
}
/**
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java Wed Nov 7 08:13:12 2012
@@ -64,7 +64,7 @@ public class ClusterService extends Base
}
/**
- * Handles: PUT /clusters/{clusterID}
+ * Handles: POST /clusters/{clusterID}
* Create a specific cluster.
*
* @param headers http headers
@@ -72,17 +72,17 @@ public class ClusterService extends Base
* @param clusterName cluster id
* @return information regarding the created cluster
*/
- @PUT
+ @POST
@Path("{clusterName}")
@Produces("text/plain")
public Response createCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("clusterName") String clusterName) {
- return handleRequest(headers, body, ui, Request.Type.PUT, createResourceDefinition(clusterName));
+ return handleRequest(headers, body, ui, Request.Type.POST, createResourceDefinition(clusterName));
}
/**
- * Handles: POST /clusters/{clusterID}
+ * Handles: PUT /clusters/{clusterID}
* Update a specific cluster.
*
* @param headers http headers
@@ -90,13 +90,13 @@ public class ClusterService extends Base
* @param clusterName cluster id
* @return information regarding the updated cluster
*/
- @POST
+ @PUT
@Path("{clusterName}")
@Produces("text/plain")
public Response updateCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("clusterName") String clusterName) {
- return handleRequest(headers, body, ui, Request.Type.POST, createResourceDefinition(clusterName));
+ return handleRequest(headers, body, ui, Request.Type.PUT, createResourceDefinition(clusterName));
}
/**
@@ -148,6 +148,14 @@ public class ClusterService extends Base
}
/**
+ * Gets the requests sub-resource.
+ */
+ @Path("{clusterName}/requests")
+ public RequestService getRequestHandler(@PathParam("clusterName") String clusterName) {
+ return new RequestService(clusterName);
+ }
+
+ /**
* Create a cluster resource definition.
*
* @param clusterName cluster name
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ComponentService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ComponentService.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ComponentService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ComponentService.java Wed Nov 7 08:13:12 2012
@@ -84,7 +84,7 @@ public class ComponentService extends Ba
}
/**
- * Handles: PUT /clusters/{clusterID}/services/{serviceID}/components/{componentID}
+ * Handles: POST /clusters/{clusterID}/services/{serviceID}/components/{componentID}
* Create a specific component.
*
* @param body http body
@@ -94,38 +94,56 @@ public class ComponentService extends Ba
*
* @return information regarding the created component
*/
- @PUT
+ @POST
@Path("{componentName}")
@Produces("text/plain")
public Response createComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("componentName") String componentName) {
- return handleRequest(headers, body, ui, Request.Type.PUT,
+ return handleRequest(headers, body, ui, Request.Type.POST,
createResourceDefinition(componentName, m_clusterName, m_serviceName));
}
/**
- * Handles: POST /clusters/{clusterID}/services/{serviceID}/components/{componentID}
+ * Handles: PUT /clusters/{clusterID}/services/{serviceID}/components/{componentID}
* Update a specific component.
*
- * @param body http body
+ * @param body http body
* @param headers http headers
* @param ui uri info
* @param componentName component id
*
* @return information regarding the updated component
*/
- @POST
+ @PUT
@Path("{componentName}")
@Produces("text/plain")
public Response updateComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
@PathParam("componentName") String componentName) {
- return handleRequest(headers, body, ui, Request.Type.POST, createResourceDefinition(
+ return handleRequest(headers, body, ui, Request.Type.PUT, createResourceDefinition(
componentName, m_clusterName, m_serviceName));
}
/**
+ * Handles: PUT /clusters/{clusterID}/services/{serviceID}/components
+ * Update multiple components.
+ *
+ * @param body http body
+ * @param headers http headers
+ * @param ui uri info
+ *
+ * @return information regarding the updated component
+ */
+ @PUT
+ @Produces("text/plain")
+ public Response updateComponents(String body, @Context HttpHeaders headers, @Context UriInfo ui) {
+
+ return handleRequest(headers, body, ui, Request.Type.PUT, createResourceDefinition(
+ null, m_clusterName, m_serviceName));
+ }
+
+ /**
* Handles: DELETE /clusters/{clusterID}/services/{serviceID}/components/{componentID}
* Delete a specific component.
*
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/ConfigurationService.java Wed Nov 7 08:13:12 2012
@@ -19,7 +19,7 @@
package org.apache.ambari.server.api.services;
import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
+import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
@@ -82,19 +82,21 @@ public class ConfigurationService extend
* @param ui uri info
* @return service collection resource representation
*/
- @PUT
+ @POST
@Produces("text/plain")
public Response createConfigurations(String body,@Context HttpHeaders headers, @Context UriInfo ui) {
- return handleRequest(headers, body, ui, Request.Type.PUT,
+ return handleRequest(headers, body, ui, Request.Type.POST,
createResourceDefinition(null, null, m_clusterName));
}
/**
* Create a service resource definition.
*
- * @param serviceName host name
+ * @param configType configuration type
+ * @param configTag tag applied to the configuration
* @param clusterName cluster name
+ *
* @return a service resource definition
*/
ResourceDefinition createResourceDefinition(String configType, String configTag, String clusterName) {
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/CreatePersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/CreatePersistenceManager.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/CreatePersistenceManager.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/CreatePersistenceManager.java Wed Nov 7 08:13:12 2012
@@ -21,6 +21,7 @@ package org.apache.ambari.server.api.ser
import org.apache.ambari.server.api.resources.ResourceDefinition;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.controller.spi.ClusterController;
+import org.apache.ambari.server.controller.spi.RequestStatus;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.Schema;
@@ -31,7 +32,7 @@ import java.util.Map;
*/
public class CreatePersistenceManager extends BasePersistenceManager {
@Override
- public void persist(ResourceDefinition resource) {
+ public RequestStatus persist(ResourceDefinition resource) {
ClusterController controller = getClusterController();
Map<Resource.Type, String> mapResourceIds = resource.getResourceIds();
Resource.Type type = resource.getType();
@@ -41,11 +42,10 @@ public class CreatePersistenceManager ex
resource.setProperty(schema.getKeyPropertyId(entry.getKey()), entry.getValue());
}
try {
- controller.createResources(type, createControllerRequest(resource.getProperties()));
+ return controller.createResources(type, createControllerRequest(resource.getProperties()));
} catch (AmbariException e) {
//todo: handle exception
throw new RuntimeException("Create of resource failed: " + e, e);
-
}
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/DeletePersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/DeletePersistenceManager.java?rev=1406489&r1=1406488&r2=1406489&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/DeletePersistenceManager.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/api/services/DeletePersistenceManager.java Wed Nov 7 08:13:12 2012
@@ -20,15 +20,18 @@ package org.apache.ambari.server.api.ser
import org.apache.ambari.server.api.resources.ResourceDefinition;
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+
/**
* Responsible for persisting the deletion of a resource in the back end.
*/
public class DeletePersistenceManager extends BasePersistenceManager {
@Override
- public void persist(ResourceDefinition resource) {
+ public RequestStatus persist(ResourceDefinition resource) {
try {
- getClusterController().deleteResources(resource.getType(),
+ //todo: need to account for multiple resources and user predicate
+ return getClusterController().deleteResources(resource.getType(),
resource.getQuery().getInternalPredicate());
} catch (AmbariException e) {
//todo: handle exception