You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by js...@apache.org on 2013/03/19 21:20:28 UTC
svn commit: r1458497 [1/4] - in /incubator/ambari/trunk: ./
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/
ambari-server/src/main/java/org/apache/ambari/server/api/handlers/
ambari-server/src/main/java/org/apache/ambari/server/api/...
Author: jspeidel
Date: Tue Mar 19 20:20:27 2013
New Revision: 1458497
URL: http://svn.apache.org/r1458497
Log:
AMBARI-1422. Allow client to specify a context value for asynchronous requests
Added:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/StageEntityTest.java
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/StageFactory.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/CreateHandler.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/DeleteHandler.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/QueryCreateHandler.java
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/BaseRequest.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/Request.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestBody.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/RequestBodyParser.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManager.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.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/RequestStatusResponse.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.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/controller/internal/RequestImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Request.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
incubator/ambari/trunk/ambari-server/src/main/resources/properties.json
incubator/ambari/trunk/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/CreateHandlerTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/DeleteHandlerTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/QueryCreateHandlerTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/handlers/UpdateHandlerTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/BaseRequestTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistenceManagerImplTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/RequestBodyTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParserTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerComponentProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigurationResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/FeedResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/InstanceResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TargetClusterResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/TaskResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UserResourceProviderTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue Mar 19 20:20:27 2013
@@ -14,6 +14,8 @@ Trunk (unreleased changes):
AMBARI-1658. Implement API/Service Provider for HDFS mirroring. (tbeerbower)
+ AMBARI-1422. Allow client to specify a "context" value for asynchronous requests (jspeidel)
+
AMBARI-1599. Add ability to report actual configuration applied to a host. (ncole)
AMBARI-1647. Integrate server and agent changes for upgrade on cluster.
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java Tue Mar 19 20:20:27 2013
@@ -43,7 +43,6 @@ public class ActionManager {
private final ActionScheduler scheduler;
private final ActionDBAccessor db;
private final ActionQueue actionQueue;
- private final HostsMap hostsMap;
private static Logger LOG = LoggerFactory.getLogger(ActionManager.class);
private final AtomicLong requestCounter;
@@ -54,7 +53,6 @@ public class ActionManager {
ServerActionManager serverActionManager) {
this.actionQueue = aq;
this.db = db;
- this.hostsMap = hostsMap;
scheduler = new ActionScheduler(schedulerSleepTime, actionTimeout, db,
actionQueue, fsm, 2, hostsMap, serverActionManager);
requestCounter = new AtomicLong(
@@ -92,6 +90,16 @@ public class ActionManager {
}
/**
+ * Get all actions(stages) for a request.
+ *
+ * @param requestId the request id
+ * @return list of all stages associated with the given request id
+ */
+ public List<Stage> getActions(long requestId) {
+ return db.getAllStages(requestId);
+ }
+
+ /**
* Persists command reports into the db
*/
public void processTaskResponse(String hostname, List<CommandReport> reports) {
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java Tue Mar 19 20:20:27 2013
@@ -52,6 +52,7 @@ public class Stage {
private final String clusterName;
private long stageId = -1;
private final String logDir;
+ private final String requestContext;
private int taskTimeout = -1;
private int perTaskTimeFactor = 60000;
@@ -65,10 +66,12 @@ public class Stage {
new TreeMap<String, List<ExecutionCommandWrapper>>();
@AssistedInject
- public Stage(@Assisted long requestId, @Assisted("logDir") String logDir, @Assisted("clusterName") String clusterName) {
+ public Stage(@Assisted long requestId, @Assisted("logDir") String logDir, @Assisted("clusterName") String clusterName,
+ @Assisted("requestContext") String requestContext) {
this.requestId = requestId;
this.logDir = logDir;
this.clusterName = clusterName;
+ this.requestContext = requestContext == null ? "" : requestContext;
}
/**
@@ -90,6 +93,7 @@ public class Stage {
stageId = stageEntity.getStageId();
logDir = stageEntity.getLogInfo();
clusterName = stageEntity.getCluster().getClusterName();
+ requestContext = stageEntity.getRequestContext();
for (HostEntity hostEntity : hostDAO.findByStage(stageEntity)) {
List<HostRoleCommandEntity> commands = hostRoleCommandDAO.findSortedCommandsByStageAndHost(stageEntity, hostEntity);
@@ -116,6 +120,7 @@ public class Stage {
stageEntity.setRequestId(requestId);
stageEntity.setStageId(getStageId());
stageEntity.setLogInfo(logDir);
+ stageEntity.setRequestContext(requestContext);
stageEntity.setHostRoleCommands(new ArrayList<HostRoleCommandEntity>());
stageEntity.setRoleSuccessCriterias(new ArrayList<RoleSuccessCriteriaEntity>());
@@ -294,6 +299,10 @@ public class Stage {
return clusterName;
}
+ public String getRequestContext() {
+ return requestContext;
+ }
+
public long getLastAttemptTime(String host, String role) {
return this.hostRoleCommands.get(host).get(role).getLastAttemptTime();
}
@@ -455,6 +464,7 @@ public class Stage {
builder.append("stageId="+stageId+"\n");
builder.append("clusterName="+clusterName+"\n");
builder.append("logDir=" + logDir+"\n");
+ builder.append("requestContext="+requestContext+"\n");
builder.append("Success Factors:\n");
for (Role r : successFactors.keySet()) {
builder.append(" role: "+r+", factor: "+successFactors.get(r)+"\n");
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/StageFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/StageFactory.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/StageFactory.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/StageFactory.java Tue Mar 19 20:20:27 2013
@@ -23,7 +23,8 @@ import org.apache.ambari.server.orm.enti
public interface StageFactory {
- Stage createNew(long requestId, @Assisted("logDir") String logDir, @Assisted("clusterName") String clusterName);
+ Stage createNew(long requestId, @Assisted("logDir") String logDir, @Assisted("clusterName") String clusterName,
+ @Assisted("requestContext") String requestContext);
Stage createExisting(String actionId);
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/BaseManagementHandler.java Tue Mar 19 20:20:27 2013
@@ -18,11 +18,8 @@
package org.apache.ambari.server.api.handlers;
-import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.NamedPropertySet;
-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.resources.*;
+import org.apache.ambari.server.api.services.*;
import org.apache.ambari.server.api.services.persistence.PersistenceManager;
import org.apache.ambari.server.api.services.persistence.PersistenceManagerImpl;
import org.apache.ambari.server.api.util.TreeNode;
@@ -31,11 +28,10 @@ import org.apache.ambari.server.controll
import org.apache.ambari.server.controller.spi.RequestStatus;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
/**
@@ -63,20 +59,18 @@ public abstract class BaseManagementHand
@Override
public Result handleRequest(Request request) {
- ResourceInstance resource = request.getResource();
- Predicate queryPredicate = request.getQueryPredicate();
+ Predicate queryPredicate = request.getQueryPredicate();
if (queryPredicate != null) {
- resource.getQuery().setUserPredicate(queryPredicate);
+ request.getResource().getQuery().setUserPredicate(queryPredicate);
}
-
- return persist(resource, getHttpBodyProperties(request));
+ return persist(request.getResource(), request.getBody());
}
/**
* Create a result from a request status.
*
- * @param requestStatus the request stats to build the result from.
+ * @param requestStatus the request status to build the result from.
*
* @return a Result instance for the provided request status
*/
@@ -104,24 +98,6 @@ public abstract class BaseManagementHand
return result;
}
- /**
- * Obtain a set of property maps from the request.
- * Convenience method that converts a Set<NamedPropertySet> from the request to a Set<Map<String, Object>>.
- *
- * @param request the current request
- *
- * @return a set of property maps for the request
- */
- protected Set<Map<String, Object>> getHttpBodyProperties(Request request) {
- Set<NamedPropertySet> setNamedProps = request.getHttpBodyProperties();
- Set<Map<String, Object>> setProps = new HashSet<Map<String, Object>>(setNamedProps.size());
-
- for (NamedPropertySet namedProps : setNamedProps) {
- setProps.add(namedProps.getProperties());
- }
-
- return setProps;
- }
//todo: inject ClusterController, PersistenceManager
@@ -146,10 +122,10 @@ public abstract class BaseManagementHand
/**
* Persist the operation to the back end.
*
- * @param request the requests resource instance
- * @param setProperties request properties
+ * @param resource associated resource
+ * @param body associated request body
*
* @return the result of the persist operation
*/
- protected abstract Result persist(ResourceInstance request, Set<Map<String, Object>> setProperties);
+ protected abstract Result persist(ResourceInstance resource, RequestBody body);
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/CreateHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/CreateHandler.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/CreateHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/CreateHandler.java Tue Mar 19 20:20:27 2013
@@ -18,14 +18,11 @@
package org.apache.ambari.server.api.handlers;
-import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.resources.*;
import org.apache.ambari.server.api.services.*;
import org.apache.ambari.server.api.services.ResultStatus;
import org.apache.ambari.server.controller.spi.*;
-import java.util.Map;
-import java.util.Set;
-
/**
* Responsible for create requests.
@@ -33,10 +30,10 @@ import java.util.Set;
public class CreateHandler extends BaseManagementHandler {
@Override
- protected Result persist(ResourceInstance request, Set<Map<String, Object>> setProperties) {
+ protected Result persist(ResourceInstance resource, RequestBody body) {
Result result;
try {
- RequestStatus status = getPersistenceManager().create(request, setProperties);
+ RequestStatus status = getPersistenceManager().create(resource, body);
result = createResult(status);
@@ -67,7 +64,6 @@ public class CreateHandler extends BaseM
//result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.SERVER_ERROR, e.getMessage()));
throw e;
}
-
return result;
}
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/DeleteHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/DeleteHandler.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/DeleteHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/DeleteHandler.java Tue Mar 19 20:20:27 2013
@@ -19,13 +19,12 @@
package org.apache.ambari.server.api.handlers;
import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.ResultStatus;
-import org.apache.ambari.server.api.services.Result;
-import org.apache.ambari.server.api.services.ResultImpl;
-import org.apache.ambari.server.controller.spi.*;
-
-import java.util.Map;
-import java.util.Set;
+import org.apache.ambari.server.api.services.*;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
/**
* Responsible for delete requests.
@@ -33,10 +32,11 @@ import java.util.Set;
public class DeleteHandler extends BaseManagementHandler implements RequestHandler {
@Override
- protected Result persist(ResourceInstance request, Set<Map<String, Object>> setProperties) {
+ protected Result persist(ResourceInstance resource, RequestBody body) {
Result result;
try {
- RequestStatus status = getPersistenceManager().delete(request, setProperties);
+
+ RequestStatus status = getPersistenceManager().delete(resource, body);
result = createResult(status);
if (result.isSynchronous()) {
@@ -49,7 +49,7 @@ public class DeleteHandler extends BaseM
} catch (NoSuchParentResourceException e) {
result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.NOT_FOUND, e));
} catch (NoSuchResourceException e) {
- if (request.isCollectionResource()) {
+ if (resource.isCollectionResource()) {
//todo: The query didn't match any resource so no resources were updated.
//todo: 200 may be ok but we need to return a collection
//todo: of resources that were updated.
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/QueryCreateHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/QueryCreateHandler.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/QueryCreateHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/handlers/QueryCreateHandler.java Tue Mar 19 20:20:27 2013
@@ -42,7 +42,7 @@ public class QueryCreateHandler extends
if (queryResult.getStatus().isErrorState() ||
queryResult.getResultTree().getChildren().isEmpty()) {
- //if query result has error state or contains no resources return it
+ // if query result has error state or contains no resources just return it.
// currently returns 200 for case where query returns no rows
return queryResult;
}
@@ -60,11 +60,19 @@ public class QueryCreateHandler extends
"Multiple sub-resource types may not be created in the same request.");
}
- Map.Entry<Resource.Type, Set<Map<String, Object>>> entry = mapProperties.entrySet().iterator().next();
+ // only get first element because we currently only support creation of a single sub-resource type
+ final Map.Entry<Resource.Type, Set<Map<String, Object>>> entry = mapProperties.entrySet().iterator().next();
ResourceInstance createResource = getResourceFactory().createResource(
entry.getKey(), request.getResource().getIds());
- return persist(createResource, entry.getValue());
+ return persist(createResource,
+ new RequestBody() {
+ @Override
+ public Set<Map<String, Object>> getPropertySets() {
+ return entry.getValue();
+ }
+ }
+ );
}
/**
@@ -82,7 +90,7 @@ public class QueryCreateHandler extends
private Map<Resource.Type, Set<Map<String, Object>>> buildCreateSet(Request request, Result queryResult)
throws IllegalArgumentException {
- Set<NamedPropertySet> setRequestProps = request.getHttpBodyProperties();
+ Set<NamedPropertySet> setRequestProps = request.getBody().getNamedPropertySets();
HashMap<Resource.Type, Set<Map<String, Object>>> mapProps =
new HashMap<Resource.Type, Set<Map<String, Object>>>();
@@ -115,7 +123,7 @@ public class QueryCreateHandler extends
}
/**
- * Determine the sub-resurce type(s) to be created.
+ * Determine the sub-resource type(s) to be created.
*
* @param resource the requests resource instance
* @param subResourceName the name of the sub-resource to be created
@@ -149,10 +157,10 @@ public class QueryCreateHandler extends
}
@Override
- protected Result persist(ResourceInstance request, Set<Map<String, Object>> setProperties) {
+ protected Result persist(ResourceInstance resource, RequestBody body) {
Result result;
try {
- RequestStatus status = getPersistenceManager().create(request, setProperties);
+ RequestStatus status = getPersistenceManager().create(resource, body);
result = createResult(status);
if (result.isSynchronous()) {
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=1458497&r1=1458496&r2=1458497&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 Tue Mar 19 20:20:27 2013
@@ -19,11 +19,15 @@
package org.apache.ambari.server.api.handlers;
import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.api.services.*;
-import org.apache.ambari.server.controller.spi.*;
-
-import java.util.Map;
-import java.util.Set;
+import org.apache.ambari.server.api.services.RequestBody;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultImpl;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
/**
@@ -32,10 +36,10 @@ import java.util.Set;
public class UpdateHandler extends BaseManagementHandler {
@Override
- protected Result persist(ResourceInstance request, Set<Map<String, Object>> setProperties) {
+ protected Result persist(ResourceInstance resource, RequestBody body) {
Result result;
try {
- RequestStatus status = getPersistenceManager().update(request, setProperties);
+ RequestStatus status = getPersistenceManager().update(resource, body);
result = createResult(status);
if (result.isSynchronous()) {
@@ -49,7 +53,7 @@ public class UpdateHandler extends BaseM
} catch (NoSuchParentResourceException e) {
result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.NOT_FOUND, e));
} catch (NoSuchResourceException e) {
- if (request.isCollectionResource()) {
+ if (resource.isCollectionResource()) {
//todo: what is the correct status code here. The query didn't match any resource
//todo: so no resource were updated. 200 may be ok but we would need to return a collection
//todo: of resources that were updated.
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java Tue Mar 19 20:20:27 2013
@@ -181,14 +181,10 @@ public abstract class BaseRequest implem
}
@Override
- public String getHttpBody() {
- return m_body.getBody();
+ public RequestBody getBody() {
+ return m_body;
}
- @Override
- public Set<NamedPropertySet> getHttpBodyProperties() {
- return m_body.getPropertySets();
- }
/**
* Obtain the result post processor for the request.
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/Request.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/Request.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/Request.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/Request.java Tue Mar 19 20:20:27 2013
@@ -25,7 +25,6 @@ import org.apache.ambari.server.controll
import java.util.List;
import java.util.Map;
-import java.util.Set;
/**
* Provides information on the current request.
@@ -97,26 +96,14 @@ public interface Request {
public Map<String, TemporalInfo> getFields();
/**
- * Obtain the http headers associated with the request.
- *
- * @return the http headers
+ * Obtain the request body data.
*/
- public Map<String, List<String>> getHttpHeaders();
+ public RequestBody getBody();
/**
- * Obtain the http body associated with the request.
- * If query or partial response fields exist in the original body,
- * they are not included in the returned body. Query and partial
- * response data are available via the corresponding getters.
- *
- * @return the http body
- */
- public String getHttpBody();
-
- /**
- * Obtain the properties which have been parsed from the http body.
+ * Obtain the http headers associated with the request.
*
- * @return a set of maps containing the properties contained in the http body
+ * @return the http headers
*/
- public Set<NamedPropertySet> getHttpBodyProperties();
+ public Map<String, List<String>> getHttpHeaders();
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestBody.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestBody.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestBody.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestBody.java Tue Mar 19 20:20:27 2013
@@ -18,7 +18,9 @@
package org.apache.ambari.server.api.services;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -46,6 +48,11 @@ public class RequestBody {
*/
private String m_body;
+ /**
+ * Request properties.
+ */
+ private Map<String, String> m_requestInfoProps = new HashMap<String, String>();
+
/**
* Set the query string.
@@ -100,17 +107,50 @@ public class RequestBody {
*
* @return all property sets or an empty set
*/
- public Set<NamedPropertySet> getPropertySets() {
+ public Set<NamedPropertySet> getNamedPropertySets() {
return m_propertySets;
}
/**
+ * Obtain all property sets as a set of maps.
+ * Convenience method that converts a Set<NamedPropertySet> to a Set<Map<String, Object>>.
+ *
+ * @return a set of property maps for the request
+ */
+ public Set<Map<String, Object>> getPropertySets() {
+ Set<NamedPropertySet> setNamedProps = getNamedPropertySets();
+ Set<Map<String, Object>> setProps = new HashSet<Map<String, Object>>(setNamedProps.size());
+
+ for (NamedPropertySet namedProps : setNamedProps) {
+ setProps.add(namedProps.getProperties());
+ }
+
+ return setProps;
+ }
+
+ /**
+ * Return a map of request info properties. These properties are meta-data for the request.
+ */
+ public Map<String, String> getRequestInfoProperties() {
+ return m_requestInfoProps;
+ }
+
+ /**
+ * Add a request info property.
+ */
+ public void addRequestInfoProperty(String key, String val) {
+ m_requestInfoProps.put(key, val);
+ }
+
+ /**
* Set the body from the request.
*
* @param body the request body
*/
public void setBody(String body) {
- m_body = body;
+ if (body != null && ! body.isEmpty()) {
+ m_body = body;
+ }
}
/**
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonRequestBodyParser.java Tue Mar 19 20:20:27 2013
@@ -38,12 +38,10 @@ public class JsonRequestBodyParser imple
*/
private final static Logger LOG = LoggerFactory.getLogger(JsonRequestBodyParser.class);
- private String m_body;
-
@Override
public RequestBody parse(String s) throws BodyParseException {
- m_body = s;
RequestBody body = new RequestBody();
+ body.setBody(s);
if (s != null && s.length() != 0) {
s = ensureArrayFormat(s);
@@ -58,7 +56,7 @@ public class JsonRequestBodyParser imple
JsonNode node = iter.next();
processNode(node, "", propertySet, body);
- String query = (String) mapProperties.remove(QUERY_FIELD_PATH);
+ String query = body.getRequestInfoProperties().get(QUERY_FIELD_NAME);
if (query != null) {
body.setQueryString(query);
}
@@ -66,10 +64,6 @@ public class JsonRequestBodyParser imple
body.addPropertySet(propertySet);
}
}
-
- if (body.getPropertySets().size() != 0) {
- body.setBody(m_body);
- }
} catch (IOException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Caught exception parsing msg body.");
@@ -99,13 +93,19 @@ public class JsonRequestBodyParser imple
// object
if (name.equals(BODY_TITLE)) {
name = "";
- m_body = child.toString();
}
processNode(child, path.isEmpty() ? name : path + '/' + name, propertySet, body);
} else {
// field
- propertySet.getProperties().put(PropertyHelper.getPropertyId(
- path.equals(BODY_TITLE) ? "" : path, name), child.asText());
+ if (path.startsWith(REQUEST_INFO_PATH)) {
+ body.addRequestInfoProperty(PropertyHelper.getPropertyId(
+ path.substring(REQUEST_INFO_PATH.length()), name), child.asText());
+
+ } else {
+ propertySet.getProperties().put(PropertyHelper.getPropertyId(
+ path.equals(BODY_TITLE) ? "" : path, name), child.asText());
+ }
+
}
}
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/RequestBodyParser.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/RequestBodyParser.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/RequestBodyParser.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/RequestBodyParser.java Tue Mar 19 20:20:27 2013
@@ -24,10 +24,15 @@ import org.apache.ambari.server.api.serv
* Parse the provided String into a map of properties and associated values.
*/
public interface RequestBodyParser {
+
+ /**
+ * RequestInfo category path.
+ */
+ public static final String REQUEST_INFO_PATH = "RequestInfo";
/**
- * Path to the query property.
+ * Name of the query property which may exist under REQUEST_INFO_PATH.
*/
- public static final String QUERY_FIELD_PATH = "RequestInfo/query";
+ public static final String QUERY_FIELD_NAME = "query";
/**
* Path to the body object.
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManager.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManager.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManager.java Tue Mar 19 20:20:27 2013
@@ -19,10 +19,13 @@
package org.apache.ambari.server.api.services.persistence;
import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.spi.*;
-
-import java.util.Map;
-import java.util.Set;
+import org.apache.ambari.server.api.services.RequestBody;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
/**
* Persistence manager which is responsible for persisting a resource state to the back end.
@@ -30,16 +33,49 @@ import java.util.Set;
*/
public interface PersistenceManager {
- public RequestStatus create(ResourceInstance resource, Set<Map<String, Object>> setProperties)
+ /**
+ * Create resources.
+ *
+ * @param resource associated resource representation
+ * @param requestBody body of the current request
+ * @return a request status
+ *
+ * @throws UnsupportedPropertyException
+ * @throws ResourceAlreadyExistsException
+ * @throws NoSuchParentResourceException
+ * @throws SystemException
+ */
+ public RequestStatus create(ResourceInstance resource, RequestBody requestBody)
throws UnsupportedPropertyException,
ResourceAlreadyExistsException,
NoSuchParentResourceException,
SystemException;
- public RequestStatus update(ResourceInstance resource, Set<Map<String, Object>> setProperties)
+ /**
+ *
+ * @param resource associated resource representation
+ * @param requestBody body of the current request
+ * @return a request status
+ *
+ * @throws UnsupportedPropertyException
+ * @throws SystemException
+ * @throws NoSuchParentResourceException
+ * @throws NoSuchResourceException
+ */
+ public RequestStatus update(ResourceInstance resource, RequestBody requestBody)
throws UnsupportedPropertyException, SystemException, NoSuchParentResourceException, NoSuchResourceException;
-
- public RequestStatus delete(ResourceInstance resource, Set<Map<String, Object>> setProperties)
+ /**
+ *
+ * @param resource associated resource representation
+ * @param requestBody body of the current request
+ * @return a request status
+ *
+ * @throws UnsupportedPropertyException
+ * @throws SystemException
+ * @throws NoSuchParentResourceException
+ * @throws NoSuchResourceException
+ */
+ public RequestStatus delete(ResourceInstance resource, RequestBody requestBody)
throws UnsupportedPropertyException, SystemException, NoSuchParentResourceException, NoSuchResourceException;
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/api/services/persistence/PersistenceManagerImpl.java Tue Mar 19 20:20:27 2013
@@ -19,7 +19,9 @@
package org.apache.ambari.server.api.services.persistence;
import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.services.*;
import org.apache.ambari.server.controller.spi.*;
+import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import java.util.HashMap;
@@ -46,7 +48,7 @@ public class PersistenceManagerImpl impl
}
@Override
- public RequestStatus create(ResourceInstance resource, Set<Map<String, Object>> setProperties)
+ public RequestStatus create(ResourceInstance resource, RequestBody requestBody)
throws UnsupportedPropertyException,
SystemException,
ResourceAlreadyExistsException,
@@ -56,31 +58,33 @@ public class PersistenceManagerImpl impl
Resource.Type type = resource.getResourceDefinition().getType();
Schema schema = m_controller.getSchema(type);
+ Set<NamedPropertySet> setProperties = requestBody.getNamedPropertySets();
if (setProperties.size() == 0) {
- setProperties.add(new HashMap<String, Object>());
+ requestBody.addPropertySet(new NamedPropertySet("", new HashMap<String, Object>()));
}
- for (Map<String, Object> mapProperties : setProperties) {
+ for (NamedPropertySet propertySet : setProperties) {
for (Map.Entry<Resource.Type, String> entry : mapResourceIds.entrySet()) {
+ Map<String, Object> mapProperties = propertySet.getProperties();
String property = schema.getKeyPropertyId(entry.getKey());
if (! mapProperties.containsKey(property)) {
mapProperties.put(property, entry.getValue());
}
}
}
- return m_controller.createResources(type, createControllerRequest(setProperties));
+ return m_controller.createResources(type, createControllerRequest(requestBody));
}
@Override
- public RequestStatus update(ResourceInstance resource, Set<Map<String, Object>> setProperties)
+ public RequestStatus update(ResourceInstance resource, RequestBody requestBody)
throws UnsupportedPropertyException, SystemException, NoSuchParentResourceException, NoSuchResourceException {
return m_controller.updateResources(resource.getResourceDefinition().getType(),
- createControllerRequest(setProperties), resource.getQuery().getPredicate());
+ createControllerRequest(requestBody), resource.getQuery().getPredicate());
}
@Override
- public RequestStatus delete(ResourceInstance resource, Set<Map<String, Object>> setProperties)
+ public RequestStatus delete(ResourceInstance resource, RequestBody requestBody)
throws UnsupportedPropertyException, SystemException, NoSuchParentResourceException, NoSuchResourceException {
//todo: need to account for multiple resources and user predicate
return m_controller.deleteResources(resource.getResourceDefinition().getType(),
@@ -88,7 +92,7 @@ public class PersistenceManagerImpl impl
}
- protected Request createControllerRequest(Set<Map<String, Object>> setProperties) {
- return PropertyHelper.getCreateRequest(setProperties);
+ protected Request createControllerRequest(RequestBody body) {
+ return PropertyHelper.getCreateRequest(body.getPropertySets(), body.getRequestInfoProperties());
}
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java Tue Mar 19 20:20:27 2013
@@ -230,43 +230,50 @@ public interface AmbariManagementControl
* Update the cluster identified by the given request object with the
* values carried by the given request object.
*
- * @param request the request object which defines which cluster to
- * update and the values to set
+ *
+ * @param request request object which defines which cluster to
+ * update and the values to set
+ * @param requestProperties request specific properties independent of resource
*
* @return a track action response
*
* @throws AmbariException thrown if the resource cannot be updated
*/
- public RequestStatusResponse updateCluster(ClusterRequest request)
+ public RequestStatusResponse updateCluster(ClusterRequest request,
+ Map<String, String> requestProperties)
throws AmbariException;
/**
* Update the service identified by the given request object with the
* values carried by the given request object.
*
+ *
* @param requests the request object which defines which service to
* update and the values to set
*
+ * @param requestProperties
* @return a track action response
*
* @throws AmbariException thrown if the resource cannot be updated
*/
- public RequestStatusResponse updateServices(Set<ServiceRequest> requests)
+ public RequestStatusResponse updateServices(Set<ServiceRequest> requests, Map<String, String> requestProperties)
throws AmbariException;
/**
* Update the component identified by the given request object with the
* values carried by the given request object.
*
+ *
* @param requests the request object which defines which component to
* update and the values to set
*
+ * @param requestProperties
* @return a track action response
*
* @throws AmbariException thrown if the resource cannot be updated
*/
public RequestStatusResponse updateComponents(
- Set<ServiceComponentRequest> requests) throws AmbariException;
+ Set<ServiceComponentRequest> requests, Map<String, String> requestProperties) throws AmbariException;
/**
* Update the host identified by the given request object with the
@@ -284,15 +291,17 @@ public interface AmbariManagementControl
* Update the host component identified by the given request object with the
* values carried by the given request object.
*
+ *
* @param requests the request object which defines which host component to
* update and the values to set
*
+ * @param requestProperties
* @return a track action response
*
* @throws AmbariException thrown if the resource cannot be updated
*/
public RequestStatusResponse updateHostComponents(
- Set<ServiceComponentHostRequest> requests) throws AmbariException;
+ Set<ServiceComponentHostRequest> requests, Map<String, String> requestProperties) throws AmbariException;
/**
* Updates the users specified.
@@ -385,7 +394,7 @@ public interface AmbariManagementControl
/**
* Get the actions identified by the given request objects.
*
- * @param requests the request objects which identify the actions to be returned
+ * @param request the request objects which identify the actions to be returned
*
* @return a set of actions responses
*
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=1458497&r1=1458496&r2=1458497&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 Tue Mar 19 20:20:27 2013
@@ -102,6 +102,11 @@ public class AmbariManagementControllerI
private final static Logger LOG =
LoggerFactory.getLogger(AmbariManagementControllerImpl.class);
+ /**
+ * Property name of request context.
+ */
+ private static final String REQUEST_CONTEXT_PROPERTY = "context";
+
private final Clusters clusters;
private String baseLogDir = "/tmp/ambari";
@@ -892,9 +897,9 @@ public class AmbariManagementControllerI
}
}
- private Stage createNewStage(Cluster cluster, long requestId) {
+ private Stage createNewStage(Cluster cluster, long requestId, String requestContext) {
String logDir = baseLogDir + File.pathSeparator + requestId;
- Stage stage = new Stage(requestId, logDir, cluster.getClusterName());
+ Stage stage = new Stage(requestId, logDir, cluster.getClusterName(), requestContext);
return stage;
}
@@ -1378,7 +1383,8 @@ public class AmbariManagementControllerI
}
@Override
- public synchronized RequestStatusResponse updateCluster(ClusterRequest request)
+ public synchronized RequestStatusResponse updateCluster(ClusterRequest request,
+ Map<String, String> requestProperties)
throws AmbariException {
if (request.getClusterName() == null
|| request.getClusterName().isEmpty()) {
@@ -1526,8 +1532,8 @@ public class AmbariManagementControllerI
requestParameters.put(Configuration.UPGRADE_FROM_STACK, gson.toJson(currentVersion));
LOG.info("Creating stages for upgrade.");
- List<Stage> stages = doStageCreation(cluster, changedServices,
- changedComps, changedScHosts, requestParameters);
+ List<Stage> stages = doStageCreation(cluster, changedServices, changedComps, changedScHosts,
+ requestParameters, requestProperties.get(REQUEST_CONTEXT_PROPERTY));
if (stages == null || stages.isEmpty()) {
return null;
@@ -1547,7 +1553,7 @@ public class AmbariManagementControllerI
private void addFinalizeUpgradeAction(Cluster cluster, List<Stage> stages) throws AmbariException {
// Add server side action as the last Stage
Stage lastStage = stages.get(stages.size() - 1);
- Stage newStage = createNewStage(cluster, lastStage.getRequestId());
+ Stage newStage = createNewStage(cluster, lastStage.getRequestId(), "finalize upgrade");
newStage.setStageId(lastStage.getStageId() + 1);
// Add an arbitrary host name as server actions are executed on the server
@@ -1710,7 +1716,7 @@ public class AmbariManagementControllerI
Map<State, List<Service>> changedServices,
Map<State, List<ServiceComponent>> changedComps,
Map<String, Map<State, List<ServiceComponentHost>>> changedScHosts,
- Map<String, String> requestParameters)
+ Map<String, String> requestParameters, String requestContext)
throws AmbariException {
// TODO handle different transitions?
@@ -1811,7 +1817,7 @@ public class AmbariManagementControllerI
// FIXME cannot work with a single stage
// multiple stages may be needed for reconfigure
long stageId = 0;
- Stage stage = createNewStage(cluster, requestId.longValue());
+ Stage stage = createNewStage(cluster, requestId.longValue(), requestContext);
stage.setStageId(stageId);
//HACK
String jobtrackerHost = this.getJobTrackerHost(cluster);
@@ -2209,7 +2215,8 @@ public class AmbariManagementControllerI
@Override
public synchronized RequestStatusResponse updateServices(
- Set<ServiceRequest> requests) throws AmbariException {
+ Set<ServiceRequest> requests, Map<String, String> requestProperties)
+ throws AmbariException {
if (requests.isEmpty()) {
LOG.warn("Received an empty requests set");
@@ -2485,7 +2492,7 @@ public class AmbariManagementControllerI
Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
List<Stage> stages = doStageCreation(cluster, changedServices,
- changedComps, changedScHosts, null);
+ changedComps, changedScHosts, null, requestProperties.get(REQUEST_CONTEXT_PROPERTY));
persistStages(stages);
updateServiceStates(changedServices, changedComps, changedScHosts);
if (stages == null || stages.isEmpty()) {
@@ -2496,8 +2503,9 @@ public class AmbariManagementControllerI
}
@Override
- public synchronized RequestStatusResponse updateComponents(
- Set<ServiceComponentRequest> requests) throws AmbariException {
+ public synchronized RequestStatusResponse updateComponents(Set<ServiceComponentRequest> requests,
+ Map<String, String> requestProperties)
+ throws AmbariException {
if (requests.isEmpty()) {
LOG.warn("Received an empty requests set");
@@ -2763,7 +2771,7 @@ public class AmbariManagementControllerI
Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
List<Stage> stages = doStageCreation(cluster, null,
- changedComps, changedScHosts, null);
+ changedComps, changedScHosts, null, requestProperties.get(REQUEST_CONTEXT_PROPERTY));
persistStages(stages);
updateServiceStates(null, changedComps, changedScHosts);
if (stages == null || stages.isEmpty()) {
@@ -2844,8 +2852,9 @@ public class AmbariManagementControllerI
}
@Override
- public synchronized RequestStatusResponse updateHostComponents(
- Set<ServiceComponentHostRequest> requests) throws AmbariException {
+ public synchronized RequestStatusResponse updateHostComponents(Set<ServiceComponentHostRequest> requests,
+ Map<String, String> requestProperties)
+ throws AmbariException {
if (requests.isEmpty()) {
LOG.warn("Received an empty requests set");
@@ -3135,7 +3144,8 @@ public class AmbariManagementControllerI
requestParameters.put(Configuration.UPGRADE_TO_STACK, gson.toJson(cluster.getCurrentStackVersion()));
requestParameters.put(Configuration.UPGRADE_FROM_STACK, gson.toJson(fromStackVersion));
}
- List<Stage> stages = doStageCreation(cluster, null, null, changedScHosts, requestParameters);
+ List<Stage> stages = doStageCreation(cluster, null, null, changedScHosts, requestParameters,
+ requestProperties.get(REQUEST_CONTEXT_PROPERTY));
persistStages(stages);
updateServiceStates(null, null, changedScHosts);
if (stages == null || stages.isEmpty()) {
@@ -3464,6 +3474,12 @@ public class AmbariManagementControllerI
RequestStatusResponse response = new RequestStatusResponse(requestId);
List<HostRoleCommand> hostRoleCommands =
actionManager.getRequestTasks(requestId);
+
+ List<Stage> listStages = actionManager.getActions(requestId);
+ if (listStages != null && !listStages.isEmpty()) {
+ //todo: may not be necessary to check list size.
+ response.setRequestContext(listStages.get(0).getRequestContext());
+ }
List<ShortTaskStatus> tasks = new ArrayList<ShortTaskStatus>();
for (HostRoleCommand hostRoleCommand : hostRoleCommands) {
@@ -3916,7 +3932,7 @@ public class AmbariManagementControllerI
}
Stage stage = stageFactory.createNew(actionManager.getNextRequestId(),
- logDir, clusterName);
+ logDir, clusterName, "");
stage.setStageId(0);
for (ActionRequest actionRequest : request) {
if (actionRequest.getActionName().contains("SERVICE_CHECK")) {
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestStatusResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestStatusResponse.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestStatusResponse.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestStatusResponse.java Tue Mar 19 20:20:27 2013
@@ -30,10 +30,14 @@ public class RequestStatusResponse {
// TODO how are logs to be sent back?
private String logs;
+ /**
+ * Request context
+ */
+ private String requestContext;
+
// TODO stage specific information
public RequestStatusResponse(Long requestId) {
- super();
this.requestId = requestId;
}
@@ -66,6 +70,12 @@ public class RequestStatusResponse {
this.tasks = tasks;
}
+ public String getRequestContext() {
+ return requestContext;
+ }
+ public void setRequestContext(String requestContext) {
+ this.requestContext = requestContext;
+ }
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java Tue Mar 19 20:20:27 2013
@@ -139,7 +139,7 @@ class ClusterResourceProvider extends Ab
}
@Override
- public RequestStatus updateResources(Request request, Predicate predicate)
+ public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
RequestStatusResponse response = null;
@@ -152,7 +152,7 @@ class ClusterResourceProvider extends Ab
response = modifyResources(new Command<RequestStatusResponse>() {
@Override
public RequestStatusResponse invoke() throws AmbariException {
- return getManagementController().updateCluster(clusterRequest);
+ return getManagementController().updateCluster(clusterRequest, request.getRequestInfoProperties());
}
});
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java Tue Mar 19 20:20:27 2013
@@ -130,7 +130,7 @@ class ComponentResourceProvider extends
}
@Override
- public RequestStatus updateResources(Request request, Predicate predicate)
+ public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<ServiceComponentRequest> requests = new HashSet<ServiceComponentRequest>();
@@ -154,7 +154,7 @@ class ComponentResourceProvider extends
RequestStatusResponse response = modifyResources(new Command<RequestStatusResponse>() {
@Override
public RequestStatusResponse invoke() throws AmbariException {
- return getManagementController().updateComponents(requests);
+ return getManagementController().updateComponents(requests, request.getRequestInfoProperties());
}
});
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java Tue Mar 19 20:20:27 2013
@@ -160,7 +160,7 @@ class HostComponentResourceProvider exte
}
@Override
- public RequestStatus updateResources(Request request, Predicate predicate)
+ public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<ServiceComponentHostRequest> requests = new HashSet<ServiceComponentHostRequest>();
RequestStatusResponse response = null;
@@ -173,7 +173,7 @@ class HostComponentResourceProvider exte
response = modifyResources(new Command<RequestStatusResponse>() {
@Override
public RequestStatusResponse invoke() throws AmbariException {
- return getManagementController().updateHostComponents(requests);
+ return getManagementController().updateHostComponents(requests, request.getRequestInfoProperties());
}
});
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HttpProxyPropertyProvider.java Tue Mar 19 20:20:27 2013
@@ -115,7 +115,7 @@ public class HttpProxyPropertyProvider e
in = streamProvider.readFrom(url);
//todo: should not use JsonRequestBodyParser as this is intended only for parsing http bodies.
RequestBody body = (new JsonRequestBodyParser().parse(IOUtils.toString(in, "UTF-8")));
- Set<NamedPropertySet> setNamedProps = body.getPropertySets();
+ Set<NamedPropertySet> setNamedProps = body.getNamedPropertySets();
Set<Map<String,Object>> setProps = new HashSet<Map<String, Object>>(setNamedProps.size());
for (NamedPropertySet ps : setNamedProps) {
setProps.add(ps.getProperties());
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=1458497&r1=1458496&r2=1458497&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 Tue Mar 19 20:20:27 2013
@@ -64,7 +64,7 @@ public class RepositoryResourceProvider
.getPropertyId("Repositories", "repo_id");
private static final String REPOSITORY_MIRRORS_LIST_PROPERTY_ID = PropertyHelper
- .getPropertyId("Repositories", "mirrors_list");;
+ .getPropertyId("Repositories", "mirrors_list");
private static Set<String> pkPropertyIds = new HashSet<String>(
Arrays.asList(new String[] { STACK_NAME_PROPERTY_ID,
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestImpl.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestImpl.java Tue Mar 19 20:20:27 2013
@@ -21,8 +21,12 @@ package org.apache.ambari.server.control
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.TemporalInfo;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
/**
* Default request implementation.
@@ -42,6 +46,12 @@ public class RequestImpl implements Requ
private final Set<Map<String, Object>> properties;
/**
+ * Request Info properties. These are properties that are specific to the request
+ * but not to any resource.
+ */
+ private Map<String, String> requestInfoProperties;
+
+ /**
* Map of property to temporal info.
*/
private Map<String, TemporalInfo> m_mapTemporalInfo = new HashMap<String, TemporalInfo>();
@@ -52,12 +62,14 @@ public class RequestImpl implements Requ
/**
* Create a request.
*
- * @param propertyIds the property ids associated with the request; may be null
- * @param properties the properties associated with the request; may be null
- * @param mapTemporalInfo the temporal info
+ * @param propertyIds property ids associated with the request; may be null
+ * @param properties resource properties associated with the request; may be null
+ * @param requestInfoProperties request properties; may be null
+ * @param mapTemporalInfo temporal info
*/
public RequestImpl(Set<String> propertyIds, Set<Map<String, Object>> properties,
- Map<String, TemporalInfo> mapTemporalInfo) {
+ Map<String, String> requestInfoProperties, Map<String,
+ TemporalInfo> mapTemporalInfo) {
this.propertyIds = propertyIds == null ?
Collections.unmodifiableSet(new HashSet<String>()) :
Collections.unmodifiableSet(propertyIds);
@@ -66,6 +78,10 @@ public class RequestImpl implements Requ
Collections.unmodifiableSet(new HashSet<Map<String, Object>>()) :
Collections.unmodifiableSet(properties);
+ this.requestInfoProperties = requestInfoProperties == null ?
+ Collections.unmodifiableMap(new HashMap<String, String>()) :
+ Collections.unmodifiableMap(requestInfoProperties);
+
setTemporalInfo(mapTemporalInfo);
}
@@ -83,6 +99,11 @@ public class RequestImpl implements Requ
}
@Override
+ public Map<String, String> getRequestInfoProperties() {
+ return requestInfoProperties;
+ }
+
+ @Override
public TemporalInfo getTemporalInfo(String id) {
return m_mapTemporalInfo.get(id);
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java Tue Mar 19 20:20:27 2013
@@ -47,6 +47,7 @@ class RequestResourceProvider extends Ab
protected static final String REQUEST_CLUSTER_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("Requests", "cluster_name");
protected static final String REQUEST_ID_PROPERTY_ID = PropertyHelper.getPropertyId("Requests", "id");
protected static final String REQUEST_STATUS_PROPERTY_ID = PropertyHelper.getPropertyId("Requests", "request_status");
+ protected static final String REQUEST_CONTEXT_ID = PropertyHelper.getPropertyId("Requests", "request_context");
private static Set<String> pkPropertyIds =
new HashSet<String>(Arrays.asList(new String[]{
@@ -98,6 +99,7 @@ class RequestResourceProvider extends Ab
Resource resource = new ResourceImpl(Resource.Type.Request);
setResourceProperty(resource, REQUEST_CLUSTER_NAME_PROPERTY_ID, clusterName, requestedIds);
setResourceProperty(resource, REQUEST_ID_PROPERTY_ID, response.getRequestId(), requestedIds);
+ setResourceProperty(resource, REQUEST_CONTEXT_ID, response.getRequestContext(), requestedIds);
resources.add(resource);
}
return resources;
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java Tue Mar 19 20:20:27 2013
@@ -127,7 +127,7 @@ class ServiceResourceProvider extends Ab
}
@Override
- public RequestStatus updateResources(Request request, Predicate predicate)
+ public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
final Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
@@ -141,7 +141,7 @@ class ServiceResourceProvider extends Ab
response = modifyResources(new Command<RequestStatusResponse>() {
@Override
public RequestStatusResponse invoke() throws AmbariException {
- return getManagementController().updateServices(requests);
+ return getManagementController().updateServices(requests, request.getRequestInfoProperties());
}
});
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Request.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Request.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Request.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Request.java Tue Mar 19 20:20:27 2013
@@ -48,6 +48,12 @@ public interface Request {
public Set<Map<String, Object>> getProperties();
/**
+ * Get any request info properties of the request. These are optional properties
+ * that are specific to the request but not related to any resource.
+ */
+ public Map<String, String> getRequestInfoProperties();
+
+ /**
* Get the {@link TemporalInfo temporal information} for the given property
* id for this request, if any.
*
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/PropertyHelper.java Tue Mar 19 20:20:27 2013
@@ -19,7 +19,6 @@ package org.apache.ambari.server.control
import org.apache.ambari.server.controller.internal.PropertyInfo;
import org.apache.ambari.server.controller.internal.RequestImpl;
-import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.TemporalInfo;
@@ -35,7 +34,7 @@ import java.util.Map;
import java.util.Set;
/**
- *
+ * Utility class that provides Property helper methods.
*/
public class PropertyHelper {
@@ -188,10 +187,12 @@ public class PropertyHelper {
* Each map contains the properties to be used to create a resource. Multiple maps in the
* set should result in multiple creates.
*
- * @param properties the properties associated with the request; may be null
+ * @param properties resource properties associated with the request; may be null
+ * @param requestInfoProperties request specific properties; may be null
*/
- public static Request getCreateRequest(Set<Map<String, Object>> properties) {
- return new RequestImpl(null, properties, null);
+ public static Request getCreateRequest(Set<Map<String, Object>> properties,
+ Map<String, String> requestInfoProperties) {
+ return new RequestImpl(null, properties, requestInfoProperties, null);
}
/**
@@ -201,7 +202,7 @@ public class PropertyHelper {
* @param propertyIds the property ids associated with the request; may be null
*/
public static Request getReadRequest(Set<String> propertyIds) {
- return new RequestImpl(propertyIds, null, null);
+ return new RequestImpl(propertyIds, null, null, null);
}
/**
@@ -213,7 +214,7 @@ public class PropertyHelper {
*/
public static Request getReadRequest(Set<String> propertyIds, Map<String,
TemporalInfo> mapTemporalInfo) {
- return new RequestImpl(propertyIds, null, mapTemporalInfo);
+ return new RequestImpl(propertyIds, null, null, mapTemporalInfo);
}
/**
@@ -223,17 +224,19 @@ public class PropertyHelper {
* @param propertyIds the property ids associated with the request; may be null
*/
public static Request getReadRequest(String ... propertyIds) {
- return new RequestImpl(new HashSet<String>(Arrays.asList(propertyIds)), null, null);
+ return new RequestImpl(new HashSet<String>(Arrays.asList(propertyIds)), null, null, null);
}
/**
* Factory method to create an update request from the given map of properties.
* The properties values in the given map are used to update the resource.
*
- * @param properties the properties associated with the request; may be null
+ * @param properties resource properties associated with the request; may be null
+ * @param requestInfoProperties request specific properties; may be null
*/
- public static Request getUpdateRequest(Map<String, Object> properties) {
- return new RequestImpl(null, Collections.singleton(properties), null);
+ public static Request getUpdateRequest(Map<String, Object> properties,
+ Map<String, String> requestInfoProperties) {
+ return new RequestImpl(null, Collections.singleton(properties), requestInfoProperties, null);
}
private static Map<Resource.Type, Map<String, Map<String, PropertyInfo>>> readPropertyProviderIds(String filename) {
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java Tue Mar 19 20:20:27 2013
@@ -73,6 +73,20 @@ public class StageEntity {
this.logInfo = logInfo;
}
+ private String requestContext = "";
+
+ @Column(name = "request_context", nullable = true)
+ @Basic
+ public String getRequestContext() {
+ return requestContext;
+ }
+
+ public void setRequestContext(String requestContext) {
+ if (requestContext != null) {
+ this.requestContext = requestContext;
+ }
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -84,8 +98,8 @@ public class StageEntity {
if (logInfo != null ? !logInfo.equals(that.logInfo) : that.logInfo != null) return false;
if (requestId != null ? !requestId.equals(that.requestId) : that.requestId != null) return false;
if (stageId != null ? !stageId.equals(that.stageId) : that.stageId != null) return false;
+ return !(requestContext != null ? !requestContext.equals(that.requestContext) : that.requestContext != null);
- return true;
}
@Override
@@ -94,6 +108,7 @@ public class StageEntity {
result = 31 * result + (requestId != null ? requestId.hashCode() : 0);
result = 31 * result + (stageId != null ? stageId.hashCode() : 0);
result = 31 * result + (logInfo != null ? logInfo.hashCode() : 0);
+ result = 31 * result + (requestContext != null ? requestContext.hashCode() : 0);
return result;
}
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java Tue Mar 19 20:20:27 2013
@@ -69,9 +69,7 @@ public class RoleGraph {
//Add edges
for (String roleI : graph.keySet()) {
for (String roleJ : graph.keySet()) {
- if (roleI.equals(roleJ)) {
- continue;
- } else {
+ if (!roleI.equals(roleJ)) {
RoleGraphNode rgnI = graph.get(roleI);
RoleGraphNode rgnJ = graph.get(roleJ);
int order = roleDependencies.order(rgnI, rgnJ);
@@ -132,8 +130,10 @@ public class RoleGraph {
private Stage getStageFromGraphNodes(Stage origStage,
List<RoleGraphNode> stageGraphNodes) {
+
Stage newStage = new Stage(origStage.getRequestId(),
- origStage.getLogDir(), origStage.getClusterName());
+ origStage.getLogDir(), origStage.getClusterName(),
+ origStage.getRequestContext());
newStage.setSuccessFactors(origStage.getSuccessFactors());
for (RoleGraphNode rgn : stageGraphNodes) {
for (String host : rgn.getHosts()) {
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java Tue Mar 19 20:20:27 2013
@@ -126,7 +126,7 @@ public class StageUtils {
//For testing only
public static Stage getATestStage(long requestId, long stageId, String hostname) {
- Stage s = new Stage(requestId, "/tmp", "cluster1");
+ Stage s = new Stage(requestId, "/tmp", "cluster1", "context");
s.setStageId(stageId);
long now = System.currentTimeMillis();
String filename = null;
Modified: incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql?rev=1458497&r1=1458496&r2=1458497&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql (original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql Tue Mar 19 20:20:27 2013
@@ -100,7 +100,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hos
CREATE TABLE ambari.role_success_criteria (role VARCHAR(255) NOT NULL, request_id BIGINT NOT NULL, stage_id BIGINT NOT NULL, success_factor FLOAT NOT NULL, PRIMARY KEY (role, request_id, stage_id));
GRANT ALL PRIVILEGES ON TABLE ambari.role_success_criteria TO :username;
-CREATE TABLE ambari.stage (stage_id BIGINT NOT NULL, request_id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, log_info VARCHAR(255) NOT NULL, PRIMARY KEY (stage_id, request_id));
+CREATE TABLE ambari.stage (stage_id BIGINT NOT NULL, request_id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, log_info VARCHAR(255) NOT NULL, request_context VARCHAR(255), PRIMARY KEY (stage_id, request_id));
GRANT ALL PRIVILEGES ON TABLE ambari.stage TO :username;
CREATE TABLE ambari.ClusterHostMapping (cluster_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, host_name));