Skip to content

Commit

Permalink
AMBARI-8687. Fix ignored unit tests for AMBARI-8661 and few productio…
Browse files Browse the repository at this point in the history
…n code fixes/improvements (Dmitri Lisnichenko via ncole)
  • Loading branch information
Nate Cole committed Dec 12, 2014
1 parent 71e1377 commit 3cb6f6a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.ActionExecutionContext;
import org.apache.ambari.server.controller.AmbariActionExecutionHelper;
import org.apache.ambari.server.controller.AmbariManagementController;
Expand Down Expand Up @@ -146,6 +147,9 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
@Inject
private static RequestFactory requestFactory;

@Inject
private static Configuration configuration;

/**
* Constructor.
*/
Expand Down Expand Up @@ -355,7 +359,7 @@ public RequestStatus createResources(Request request) throws SystemException,
cluster.getClusterName(), INSTALL_PACKAGES_ACTION,
Collections.singletonList(filter),
params);
actionContext.setTimeout((short) 600);
actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout()));

try {
actionExecutionHelper.get().addExecutionCommandsToStage(actionContext, stage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.actionmanager.RequestFactory;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.ActionExecutionContext;
import org.apache.ambari.server.controller.AmbariActionExecutionHelper;
import org.apache.ambari.server.controller.AmbariManagementController;
Expand All @@ -58,6 +59,7 @@
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.RepositoryVersionState;
import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.ServiceOsSpecific;
Expand Down Expand Up @@ -142,6 +144,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
@Inject
private static Provider<AmbariActionExecutionHelper> actionExecutionHelper;

@Inject
private static Configuration configuration;


/**
* Constructor.
Expand Down Expand Up @@ -318,6 +323,20 @@ public RequestStatus createResources(Request request) throws SystemException,
desiredRepoVersion, stackId));
}

HostVersionEntity hostVersEntity = hostVersionDAO.findByClusterStackVersionAndHost(clName, stackId,
desiredRepoVersion, hostName);
if (hostVersEntity == null) {
throw new IllegalArgumentException(String.format(
"Repo version %s for stack %s is not available for host %s",
desiredRepoVersion, stackId, hostName));
}
if (hostVersEntity.getState() != RepositoryVersionState.INSTALLED &&
hostVersEntity.getState() != RepositoryVersionState.INSTALL_FAILED) {
throw new UnsupportedOperationException(String.format("Repo version %s for stack %s " +
"for host %s is in %s state. Can not transition to INSTALLING state",
desiredRepoVersion, stackId, hostName, hostVersEntity.getState().toString()));
}

List<OperatingSystemEntity> operatingSystems = repoVersionEnt.getOperatingSystems();
Map<String, List<RepositoryEntity>> perOsRepos = new HashMap<String, List<RepositoryEntity>>();
for (OperatingSystemEntity operatingSystem : operatingSystems) {
Expand Down Expand Up @@ -368,7 +387,7 @@ public RequestStatus createResources(Request request) throws SystemException,
cluster.getClusterName(), INSTALL_PACKAGES_ACTION,
Collections.singletonList(filter),
params);
actionContext.setTimeout((short) 600);
actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout()));

String caption = String.format(INSTALL_PACKAGES_FULL_NAME + " on host %s", hostName);
RequestStageContainer req = createRequest(caption);
Expand Down Expand Up @@ -399,6 +418,8 @@ public RequestStatus createResources(Request request) throws SystemException,
}

try {
hostVersEntity.setState(RepositoryVersionState.INSTALLING);
hostVersionDAO.merge(hostVersEntity);
req.persist();
} catch (AmbariException e) {
throw new SystemException("Can not persist request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
* UPGRADE_FAILED -> UPGRADING
* UPGRADED -> CURRENT
* INSTALLING -> INSTALLED | INSTALL_FAILED
* INSTALLED -> INSTALLED
* INSTALLED -> INSTALLING
* INSTALL_FAILED -> INSTALLING
* CURRENT -> INSTALLED
* INSTALLED -> UPGRADING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,12 +1237,14 @@ public void recalculateClusterVersionState(String repositoryVersion) throws Amba
stackId, repositoryVersion);

if (clusterVersion == null) {
throw new AmbariException("Repository version is null");
throw new AmbariException(String.format("Repository version %s not found for cluster %s",
repositoryVersion, getClusterName()));
}

RepositoryVersionState worstState;
if (clusterVersion.getState() != RepositoryVersionState.INSTALL_FAILED &&
clusterVersion.getState() != RepositoryVersionState.INSTALLING) {
clusterVersion.getState() != RepositoryVersionState.INSTALLING &&
clusterVersion.getState() != RepositoryVersionState.INSTALLED) {
// anything else is not supported as of now
return;
}
Expand Down Expand Up @@ -1356,6 +1358,8 @@ public void transitionClusterVersion(String stack, String version, RepositoryVer
case INSTALL_FAILED:
allowedStates.add(RepositoryVersionState.INSTALLING);
case INSTALLED:
allowedStates.add(RepositoryVersionState.INSTALLED); // To allow reinstall
allowedStates.add(RepositoryVersionState.INSTALLING); // To allow reinstall
allowedStates.add(RepositoryVersionState.UPGRADING);
case UPGRADING:
allowedStates.add(RepositoryVersionState.CURRENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
import org.codehaus.jackson.JsonGenerationException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1058,7 +1057,6 @@ public void testStateCommandsAtRegistration() throws AmbariException, InvalidSta
assertTrue(registrationResponse.getStatusCommands().get(0).equals(statusCmd1));
}

@Ignore
@Test
@SuppressWarnings("unchecked")
public void testTaskInProgressHandling() throws AmbariException, InvalidStateTransitionException {
Expand Down Expand Up @@ -1097,6 +1095,7 @@ public void testTaskInProgressHandling() throws AmbariException, InvalidStateTra
cr.setClusterName(DummyCluster);
cr.setServiceName(HDFS);
cr.setRole(DATANODE);
cr.setRoleCommand("INSTALL");
cr.setStatus("IN_PROGRESS");
cr.setStdErr("none");
cr.setStdOut("dummy output");
Expand All @@ -1106,7 +1105,7 @@ public void testTaskInProgressHandling() throws AmbariException, InvalidStateTra
hb.setComponentStatus(new ArrayList<ComponentStatus>());

final HostRoleCommand command = new HostRoleCommand(DummyHostname1,
Role.DATANODE, null, null);
Role.DATANODE, null, RoleCommand.INSTALL);

ActionManager am = getMockActionManager();
expect(am.getTasks(anyObject(List.class))).andReturn(
Expand All @@ -1121,7 +1120,6 @@ public void testTaskInProgressHandling() throws AmbariException, InvalidStateTra
assertEquals("Host state should still be installing", State.INSTALLING, componentState1);
}

@Ignore
@Test
@SuppressWarnings("unchecked")
public void testOPFailedEventForAbortedTask() throws AmbariException, InvalidStateTransitionException {
Expand Down Expand Up @@ -1173,6 +1171,7 @@ public void testOPFailedEventForAbortedTask() throws AmbariException, InvalidSta
cr.setClusterName(DummyCluster);
cr.setServiceName(HDFS);
cr.setRole(DATANODE);
cr.setRoleCommand("INSTALL");
cr.setStatus("FAILED");
cr.setStdErr("none");
cr.setStdOut("dummy output");
Expand Down Expand Up @@ -1330,7 +1329,6 @@ public void testCommandReportOnHeartbeatUpdatedState()
State.INSTALLED, serviceComponentHost1.getState());
}

@Ignore
@Test
@SuppressWarnings("unchecked")
public void testUpgradeSpecificHandling() throws AmbariException, InvalidStateTransitionException {
Expand Down Expand Up @@ -1365,6 +1363,7 @@ public void testUpgradeSpecificHandling() throws AmbariException, InvalidStateTr
cr.setClusterName(DummyCluster);
cr.setServiceName(HDFS);
cr.setRole(DATANODE);
cr.setRoleCommand("INSTALL");
cr.setStatus(HostRoleStatus.IN_PROGRESS.toString());
cr.setStdErr("none");
cr.setStdOut("dummy output");
Expand Down Expand Up @@ -1595,7 +1594,6 @@ public void testComponentUpgradeCompleteReport() throws AmbariException, Invalid
stack122, serviceComponentHost2.getStackVersion());
}

@Ignore
@Test
@SuppressWarnings("unchecked")
public void testComponentUpgradeInProgressReport() throws AmbariException, InvalidStateTransitionException {
Expand Down Expand Up @@ -1643,6 +1641,7 @@ public void testComponentUpgradeInProgressReport() throws AmbariException, Inval
cr1.setClusterName(DummyCluster);
cr1.setServiceName(HDFS);
cr1.setRole(DATANODE);
cr1.setRoleCommand("INSTALL");
cr1.setStatus(HostRoleStatus.IN_PROGRESS.toString());
cr1.setStdErr("none");
cr1.setStdOut("dummy output");
Expand All @@ -1654,6 +1653,7 @@ public void testComponentUpgradeInProgressReport() throws AmbariException, Inval
cr2.setClusterName(DummyCluster);
cr2.setServiceName(HDFS);
cr2.setRole(NAMENODE);
cr2.setRoleCommand("INSTALL");
cr2.setStatus(HostRoleStatus.IN_PROGRESS.toString());
cr2.setStdErr("none");
cr2.setStdOut("dummy output");
Expand Down Expand Up @@ -1686,7 +1686,6 @@ public void testComponentUpgradeInProgressReport() throws AmbariException, Inval
}


@Ignore
@Test
@SuppressWarnings("unchecked")
public void testComponentUpgradeFailReport() throws AmbariException, InvalidStateTransitionException {
Expand Down Expand Up @@ -1765,6 +1764,7 @@ public void testComponentUpgradeFailReport() throws AmbariException, InvalidStat
cr1.setClusterName(DummyCluster);
cr1.setServiceName(HDFS);
cr1.setRole(DATANODE);
cr1.setRoleCommand("INSTALL");
cr1.setStatus(HostRoleStatus.FAILED.toString());
cr1.setStdErr("none");
cr1.setStdOut("dummy output");
Expand All @@ -1776,6 +1776,7 @@ public void testComponentUpgradeFailReport() throws AmbariException, InvalidStat
cr2.setClusterName(DummyCluster);
cr2.setServiceName(HDFS);
cr2.setRole(NAMENODE);
cr2.setRoleCommand("INSTALL");
cr2.setStatus(HostRoleStatus.FAILED.toString());
cr2.setStdErr("none");
cr2.setStdOut("dummy output");
Expand Down Expand Up @@ -2004,7 +2005,6 @@ public void testProcessStatusReports() throws Exception {
assertEquals(HostHealthStatus.HealthStatus.ALERT.name(), hostObject.getStatus());
}

@Ignore
@Test
@SuppressWarnings("unchecked")
public void testIgnoreCustomActionReport() throws AmbariException, InvalidStateTransitionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@
import org.apache.ambari.server.controller.utilities.PropertyHelper;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.dao.HostVersionDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.RepositoryVersionState;
import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.ServiceOsSpecific;
Expand Down Expand Up @@ -77,6 +80,7 @@ public class HostStackVersionResourceProviderTest {
private Injector injector;
private AmbariMetaInfo ambariMetaInfo;
private RepositoryVersionDAO repositoryVersionDAOMock;
private HostVersionDAO hostVersionDAOMock;

private String operatingSystemsJson = "[\n" +
" {\n" +
Expand All @@ -100,6 +104,7 @@ public class HostStackVersionResourceProviderTest {
public void setup() throws Exception {
// Create instances of mocks
repositoryVersionDAOMock = createNiceMock(RepositoryVersionDAO.class);
hostVersionDAOMock = createNiceMock(HostVersionDAO.class);
// Initialize injector
InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
injector = Guice.createInjector(Modules.override(module).with(new MockModule()));
Expand Down Expand Up @@ -147,6 +152,8 @@ public void testCreateResources() throws Exception {
ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);

HostVersionEntity hostVersionEntityMock = createNiceMock(HostVersionEntity.class);

AbstractControllerResourceProvider.init(resourceProviderFactory);

expect(managementController.getClusters()).andReturn(clusters).anyTimes();
Expand All @@ -170,11 +177,16 @@ public void testCreateResources() throws Exception {
expect(repositoryVersionDAOMock.findByStackAndVersion(anyObject(String.class),
anyObject(String.class))).andReturn(repoVersion);


expect(hostVersionDAOMock.findByClusterStackVersionAndHost(anyObject(String.class),
anyObject(String.class), anyObject(String.class), anyObject(String.class))).andReturn(hostVersionEntityMock);
expect(hostVersionEntityMock.getState()).andReturn(RepositoryVersionState.INSTALL_FAILED).anyTimes();

expect(actionManager.getRequestTasks(anyLong())).andReturn(Collections.<HostRoleCommand>emptyList()).anyTimes();

// replay
replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
cluster, repositoryVersionDAOMock, sch, actionManager);
cluster, repositoryVersionDAOMock, sch, actionManager, hostVersionEntityMock, hostVersionDAOMock);

ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
Expand Down Expand Up @@ -211,6 +223,7 @@ public class MockModule extends AbstractModule {
@Override
protected void configure() {
bind(RepositoryVersionDAO.class).toInstance(repositoryVersionDAOMock);
bind(HostVersionDAO.class).toInstance(hostVersionDAOMock);
}
}
}
Loading

0 comments on commit 3cb6f6a

Please sign in to comment.