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/10/10 07:45:28 UTC
svn commit: r1396477 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/
ambari-server/src/main/java/org/apache/ambari/server/controller/
Author: mahadev
Date: Wed Oct 10 05:45:28 2012
New Revision: 1396477
URL: http://svn.apache.org/viewvc?rev=1396477&view=rev
Log:
AMBARI-838. HACK: Add a thread in server to inject requests for testing. (Jitendra via mahadev)
Added:
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestInjectorForTest.java
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1396477&r1=1396476&r2=1396477&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Wed Oct 10 05:45:28 2012
@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-838. HACK: Add a thread in server to inject requests for testing.
+ (Jitendra via mahadev)
+
AMBARI-835. Update JMXPropertyProvider. (Tom Beerbower via hitesh)
AMBARI-832. Merge ambari-api with ambari-server (mahadev)
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java?rev=1396477&r1=1396476&r2=1396477&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java Wed Oct 10 05:45:28 2012
@@ -88,19 +88,6 @@ public class ActionDBInMemoryImpl implem
l.add(s);
}
}
- // TODO: Remove this code
- // HACK to add a stage so that something is sent to the agent
- if (l.isEmpty()) {
- long requestId = 1;
- long stageId = 1;
- if (!stageList.isEmpty()) {
- requestId = stageList.get(stageList.size() - 1).getRequestId() + 1;
- stageId = stageList.get(stageList.size() - 1).getStageId() + 1;
- }
- Stage s = StageUtils.getATestStage(requestId, stageId);
- stageList.add(s);
- l.add(s);
- }
return l;
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java?rev=1396477&r1=1396476&r2=1396477&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java Wed Oct 10 05:45:28 2012
@@ -68,27 +68,6 @@ class ActionScheduler implements Runnabl
this.actionQueue = actionQueue;
this.fsmObject = fsmObject;
this.maxAttempts = (short) maxAttempts;
- //HACK Initialize
- try {
- if (fsmObject != null) {
- String hostname = InetAddress.getLocalHost().getHostName();
- fsmObject.addCluster("cluster1");
- fsmObject.getCluster("cluster1").addService(
- new ServiceImpl(fsmObject.getCluster("cluster1"), "HDFS"));
- Map<String, ServiceComponent> svcComps = new TreeMap<String, ServiceComponent>();
- ServiceComponent svcComponent = new ServiceComponentImpl(fsmObject
- .getCluster("cluster1").getService("HDFS"), "NAMENODE");
- svcComps.put("NAMENODE", svcComponent);
- fsmObject.getCluster("cluster1").getService("HDFS")
- .addServiceComponents(svcComps);
- Map<String, ServiceComponentHost> hostComponents = new TreeMap<String, ServiceComponentHost>();
- hostComponents.put(hostname, new ServiceComponentHostImpl(svcComponent,
- hostname, false));
- svcComponent.addServiceComponentHosts(hostComponents);
- }
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
}
public void start() {
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java?rev=1396477&r1=1396476&r2=1396477&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java Wed Oct 10 05:45:28 2012
@@ -211,6 +211,10 @@ public class AmbariServer {
manager.start();
LOG.info("********* Started ActionManager **********");
+ RequestInjectorForTest testInjector = new RequestInjectorForTest(controller, clusters);
+ Thread testInjectorThread = new Thread(testInjector);
+ testInjectorThread.start();
+
server.join();
LOG.info("Joined the Server");
} catch (Exception e) {
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestInjectorForTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestInjectorForTest.java?rev=1396477&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestInjectorForTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestInjectorForTest.java Wed Oct 10 05:45:28 2012
@@ -0,0 +1,129 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.controller;
+
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.State;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RequestInjectorForTest implements Runnable {
+
+ private AmbariManagementController controller;
+ private static final Logger LOG =
+ LoggerFactory.getLogger(RequestInjectorForTest.class);
+ private Clusters clusters;
+
+ public RequestInjectorForTest(AmbariManagementController controller,
+ Clusters clusters) {
+ this.controller = controller;
+ this.clusters = clusters;
+ }
+
+ @Override
+ public void run() {
+ int counter = 0;
+ while (true) {
+ try {
+ sendAction(++counter);
+ Thread.sleep(60000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (AmbariException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void createCluster(String clusterName) throws AmbariException {
+ ClusterRequest r = new ClusterRequest(null, clusterName, "1.0.0", null);
+ controller.createCluster(r);
+ }
+
+ private void createService(String clusterName,
+ String serviceName) throws AmbariException {
+ ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
+ State.INIT.toString());
+ controller.createService(r);
+ }
+
+ private void createServiceComponent(String clusterName,
+ String serviceName, String componentName)
+ throws AmbariException {
+ ServiceComponentRequest r = new ServiceComponentRequest(clusterName,
+ serviceName, componentName, null, State.INIT.toString());
+ controller.createComponent(r);
+ }
+
+ private void createServiceComponentHost(String clusterName,
+ String serviceName, String componentName, String hostname) throws AmbariException {
+ ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName,
+ serviceName, componentName, hostname, null, State.INIT.toString());
+ controller.createHostComponent(r);
+ }
+
+
+ private void sendAction(int clusterId) throws AmbariException, UnknownHostException {
+ String clusterName = "foo" + clusterId;
+ createCluster(clusterName);
+ LOG.info("Created cluster " + clusterName);
+
+ String serviceName = "HDFS";
+ createService(clusterName, serviceName);
+ LOG.info("Created service " + serviceName);
+
+ String componentName1 = "NAMENODE";
+ String componentName2 = "DATANODE";
+ createServiceComponent(clusterName, serviceName, componentName1);
+ LOG.info("Created ServiceComponent " + componentName1);
+ createServiceComponent(clusterName, serviceName, componentName2);
+ LOG.info("Created ServiceComponent " + componentName2);
+
+ String host1 = InetAddress.getLocalHost().getHostName();
+ createServiceComponentHost(clusterName, serviceName, componentName1,
+ host1);
+ LOG.info("Created ServiceComponentHost " + componentName1 + " " + host1);
+ createServiceComponentHost(clusterName, serviceName, componentName2,
+ host1);
+ LOG.info("Created ServiceComponentHost " + componentName2 + " " + host1);
+
+ ServiceRequest r1 = new ServiceRequest(clusterName, serviceName, null,
+ State.INSTALLED.toString());
+
+ StringBuilder sb = new StringBuilder();
+ clusters.debugDump(sb);
+ LOG.info("Dump current cluster state: \n" + sb.toString());
+
+ LOG.info("***** Trying to install service now *******");
+ controller.updateService(r1);
+
+ sb = new StringBuilder();
+ clusters.debugDump(sb);
+ LOG.info("Dump current cluster state: \n" + sb.toString());
+ }
+
+}