Browse Source

AMBARI-712. Action manager skeleton.

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1383106 13f79535-47bb-0310-9956-ffa450edef68
Jitendra Nath Pandey 12 years ago
parent
commit
aeb482b35d

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-712. Action manager skeleton. (jitendra)
+
   AMBARI-710. Basic registration and heartbeat protocol implementation between
   the server and the agent. (mahadev)
 

+ 34 - 0
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java

@@ -0,0 +1,34 @@
+/**
+ * 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.actionmanager;
+
+import java.util.List;
+
+public class ActionDBAccessor {
+  public void persistAction(HostAction ha) {
+    
+  }
+  
+  public Stage getAction(String actionId) {
+    return null;
+  }
+  
+  public List<Stage> getAllStages(String requestId) {
+    return null;
+  }
+}

+ 44 - 0
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java

@@ -0,0 +1,44 @@
+/**
+ * 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.actionmanager;
+
+import java.util.List;
+
+import org.apache.ambari.server.agentprotocol.CommandReport;
+
+/**
+ * This class acts as the interface for action manager with other components.
+ */
+public class ActionManager {
+  public void sendActions(List<Stage> stages) {
+    //Store all these actions to the db
+  }
+  
+  public List<Stage> getRequestStatus(String requestId) {
+    return null;
+  }
+  
+  public Stage getActionStatus(String actionId) {
+    //fetch the action information from the db
+    return null;
+  }
+  
+  public void actionResponse(String hostname, List<CommandReport> report) {
+    //persist the action response into the db.
+  }
+}

+ 43 - 0
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java

@@ -0,0 +1,43 @@
+/**
+ * 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.actionmanager;
+
+//This class encapsulates the action scheduler thread. 
+//Action schedule frequently looks at action database and determines if
+//there is an action that can be scheduled.
+public class ActionScheduler implements Runnable {
+  
+  private final long actionTimeout;
+  private final long sleepTime;
+  
+  public ActionScheduler(long sleepTimeMilliSec, long actionTimeoutMilliSec) {
+    this.sleepTime = sleepTimeMilliSec;
+    this.actionTimeout = actionTimeoutMilliSec;
+  }
+  
+  @Override
+  public void run() {
+    try {
+      //Check db for any pending actions and determine if something can be scheduled.
+      Thread.sleep(sleepTime);
+    } catch (InterruptedException ex) {
+      //Shutting down;
+      return;
+    }
+  }
+}

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/agentprotocol/CommandReport.java

@@ -22,5 +22,5 @@ public class CommandReport {
   String stdout;
   String stderr;
   String status;
-  String exitCode;
+  int exitCode;
 }

+ 5 - 0
ambari-server/src/main/java/org/apache/ambari/server/agentprotocol/HeartbeatHandler.java

@@ -23,4 +23,9 @@ package org.apache.ambari.server.agentprotocol;
  */
 public class HeartbeatHandler {
   private String lastCompletedActionId;
+  
+  public HeartbeatResponse handleHeartBeat(Heartbeat heartbeat) {
+    System.out.println(heartbeat.toString());
+    return null;
+  }
 }