You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/01/23 19:01:14 UTC

[1/2] git commit: AMBARI-4402. Delete Config Group Host mapping broken due to error introduced by perf patch. (swagle)

Updated Branches:
  refs/heads/trunk 11de6a5c6 -> 33092de45


AMBARI-4402. Delete Config Group Host mapping broken due to error introduced by perf patch. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/33092de4
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/33092de4
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/33092de4

Branch: refs/heads/trunk
Commit: 33092de45a23331b39e855fbcd0d6bbca48d6c99
Parents: cd25d7b
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Thu Jan 23 09:59:05 2014 -0800
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Thu Jan 23 10:00:07 2014 -0800

----------------------------------------------------------------------
 .../orm/dao/ConfigGroupHostMappingDAO.java      | 36 +++++++-------------
 .../ambari/server/state/ConfigGroupTest.java    |  1 -
 2 files changed, 13 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/33092de4/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
index f4ea328..8ff21b5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
@@ -105,29 +105,19 @@ public class ConfigGroupHostMappingDAO {
     }
     
   }
-  
+
+  /**
+   * Return entity object which can be used for operations like remove
+   * directly.
+   * @param configGroupHostMappingEntityPK
+   * @return
+   */
   @Transactional
-  public ConfigGroupHostMapping findByPK(final ConfigGroupHostMappingEntityPK
+  public ConfigGroupHostMappingEntity findByPK(final ConfigGroupHostMappingEntityPK
         configGroupHostMappingEntityPK) {
     
-    populateCache();
-    
-    if (!configGroupHostMappingByHost.containsKey(configGroupHostMappingEntityPK.getHostname()))
-      return null;
-    
-    Set<ConfigGroupHostMapping> set = 
-        new HashSet<ConfigGroupHostMapping>(configGroupHostMappingByHost.get(configGroupHostMappingEntityPK.getHostname()));
-    
-    ConfigGroupHostMapping itemByPk = (ConfigGroupHostMapping) CollectionUtils.find(set, new Predicate() {
-      
-      @Override
-      public boolean evaluate(Object arg0) {
-        return ((ConfigGroupHostMapping) arg0).getConfigGroupId().
-            equals(configGroupHostMappingEntityPK.getConfigGroupId());
-      }
-    });
-    
-    return itemByPk;
+    return entityManagerProvider.get()
+      .find(ConfigGroupHostMappingEntity.class, configGroupHostMappingEntityPK);
   }
 
   @Transactional
@@ -247,10 +237,10 @@ public class ConfigGroupHostMappingDAO {
                          configGroupHostMappingEntityPK) {
     populateCache();
     
-    entityManagerProvider.get().remove(findByPK
-      (configGroupHostMappingEntityPK));
+    entityManagerProvider.get().remove(findByPK(configGroupHostMappingEntityPK));
     
-    Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get(configGroupHostMappingEntityPK.getHostname());
+    Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost
+      .get(configGroupHostMappingEntityPK.getHostname());
     
     if (setByHost != null) {
       CollectionUtils.filter(setByHost, new Predicate() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/33092de4/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
index 96b9421..b67b78e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
@@ -193,7 +193,6 @@ public class ConfigGroupTest {
     Assert.assertNull(cluster.getConfigGroups().get(id));
   }
 
-  @Ignore
   @Test
   public void testRemoveHost() throws Exception {
     ConfigGroup configGroup = createConfigGroup();


[2/2] git commit: AMBARI-4401. Schedule_request with failing batch forever stays in state SCHEDULED. (swagle)

Posted by sw...@apache.org.
AMBARI-4401. Schedule_request with failing batch forever stays in state SCHEDULED. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cd25d7b6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cd25d7b6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cd25d7b6

Branch: refs/heads/trunk
Commit: cd25d7b6b79b0ecd5821226980c47c7fd5ccc8f8
Parents: 11de6a5
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Thu Jan 23 09:56:07 2014 -0800
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Thu Jan 23 10:00:07 2014 -0800

----------------------------------------------------------------------
 .../scheduler/AbstractLinearExecutionJob.java   | 28 ++++++++++----
 .../scheduler/ExecutionScheduleManagerTest.java | 40 ++++++++++++++++++++
 .../state/scheduler/BatchRequestJobTest.java    |  4 ++
 3 files changed, 65 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/cd25d7b6/ambari-server/src/main/java/org/apache/ambari/server/scheduler/AbstractLinearExecutionJob.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/scheduler/AbstractLinearExecutionJob.java b/ambari-server/src/main/java/org/apache/ambari/server/scheduler/AbstractLinearExecutionJob.java
index 5dbe6e1..d4602a2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/scheduler/AbstractLinearExecutionJob.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/scheduler/AbstractLinearExecutionJob.java
@@ -73,6 +73,7 @@ public abstract class AbstractLinearExecutionJob implements ExecutionJob {
   public void execute(JobExecutionContext context) throws JobExecutionException {
     JobKey jobKey = context.getJobDetail().getKey();
     LOG.debug("Executing linear job: " + jobKey);
+    JobDataMap jobDataMap = context.getMergedJobDataMap();
 
     if (!executionScheduleManager.continueOnMisfire(context)) {
       throw new JobExecutionException("Canceled execution based on misfire"
@@ -80,29 +81,43 @@ public abstract class AbstractLinearExecutionJob implements ExecutionJob {
         + ", scheduleTime = " + context.getScheduledFireTime());
     }
 
-    Map<String, Object> properties = context.getMergedJobDataMap()
-      .getWrappedMap();
+    Map<String, Object> properties = jobDataMap.getWrappedMap();
+    boolean finalize = false;
 
     // Perform work and exit if failure reported
     try {
       doWork(properties);
     } catch (AmbariException e) {
-      LOG.error("Exception caught on execution of job " + jobKey + ". Exiting linear chain...", e);
+      LOG.error("Exception caught on execution of job " + jobKey +
+        ". Exiting linear chain...", e);
+
+      finalize = true;
       throw new JobExecutionException(e);
+
     } catch (RuntimeException e) {
       LOG.error("Unexpected exception caught on execution of job " + jobKey + ". " +
           "Exiting linear chain...", e);
+
+      finalize = true;
       throw e;
+
+    } finally {
+      // Finalize before exiting chain
+      if (finalize) {
+        try {
+          finalizeExecution(properties);
+        } catch (AmbariException e) {
+          LOG.warn("Unable to finalize execution for job: " + jobKey);
+        }
+      }
     }
 
     LOG.debug("Finished linear job: " + jobKey);
 
-    JobDataMap jobDataMap = context.getMergedJobDataMap();
-
     String nextJobName = jobDataMap.getString(NEXT_EXECUTION_JOB_NAME_KEY);
     String nextJobGroup = jobDataMap.getString(NEXT_EXECUTION_JOB_GROUP_KEY);
 
-    // If no more jobs left, update status and return
+    // If no more jobs left, finalize and return
     if (nextJobName == null || nextJobName.isEmpty()) {
       LOG.debug("End of linear job chain. Returning with success.");
       try {
@@ -125,5 +140,4 @@ public abstract class AbstractLinearExecutionJob implements ExecutionJob {
 
     executionScheduleManager.scheduleJob(trigger);
   }
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/cd25d7b6/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
index 2f22d25..80c07c8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/scheduler/ExecutionScheduleManagerTest.java
@@ -27,6 +27,7 @@ import com.google.inject.persist.PersistService;
 import com.google.inject.persist.Transactional;
 import com.google.inject.util.Modules;
 import junit.framework.Assert;
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
@@ -46,8 +47,10 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.quartz.CronTrigger;
+import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
 import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
 import org.quartz.JobKey;
 import org.quartz.Scheduler;
 import org.quartz.SchedulerException;
@@ -578,4 +581,41 @@ public class ExecutionScheduleManagerTest {
       executionSchedulerMock, scheduleManager, batchMock, batchRequestMock,
       triggerMock, jobDetailMock, actionDBAccessorMock);
   }
+
+  @Test
+  public void testFinalizeBeforeExit() throws Exception {
+    ExecutionScheduleManager scheduleManagerMock = createMock(ExecutionScheduleManager.class);
+    AbstractLinearExecutionJob executionJob =
+      createMockBuilder(AbstractLinearExecutionJob.class)
+      .addMockedMethods("finalizeExecution", "doWork")
+      .withConstructor(scheduleManagerMock)
+      .createMock();
+    JobExecutionContext context = createMock(JobExecutionContext.class);
+    JobDetail jobDetail = createMock(JobDetail.class);
+    JobDataMap jobDataMap = createMock(JobDataMap.class);
+
+    expect(context.getJobDetail()).andReturn(jobDetail).anyTimes();
+    expect(context.getMergedJobDataMap()).andReturn(jobDataMap).anyTimes();
+    expect(jobDetail.getKey()).andReturn(new JobKey("TestJob"));
+    expect(jobDataMap.getWrappedMap()).andReturn(new HashMap<String,Object>());
+    expect(scheduleManagerMock.continueOnMisfire(context)).andReturn(true);
+
+    executionJob.doWork((Map<String, Object>) anyObject());
+    expectLastCall().andThrow(new AmbariException("Test Exception")).anyTimes();
+
+    executionJob.finalizeExecution((Map<String, Object>) anyObject());
+    expectLastCall().once();
+
+    replay(scheduleManagerMock, executionJob, context, jobDataMap, jobDetail);
+
+    try {
+      executionJob.execute(context);
+    } catch (Exception ae) {
+      assertThat(ae, instanceOf(JobExecutionException.class));
+      JobExecutionException je = (JobExecutionException) ae;
+      Assert.assertEquals("Test Exception", je.getUnderlyingException().getMessage());
+    }
+
+    verify(scheduleManagerMock, executionJob, context, jobDataMap, jobDetail);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/cd25d7b6/ambari-server/src/test/java/org/apache/ambari/server/state/scheduler/BatchRequestJobTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/scheduler/BatchRequestJobTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/scheduler/BatchRequestJobTest.java
index 9a45227..7ed183f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/scheduler/BatchRequestJobTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/scheduler/BatchRequestJobTest.java
@@ -18,12 +18,16 @@
 
 package org.apache.ambari.server.state.scheduler;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.scheduler.AbstractLinearExecutionJob;
 import org.apache.ambari.server.scheduler.ExecutionScheduleManager;
 import org.easymock.Capture;
 import org.junit.Assert;
 import org.junit.Test;
+import org.quartz.JobExecutionContext;
 
+import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;