http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestEntity.java index 7944d21..f19aa72 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestEntity.java @@ -69,9 +69,28 @@ public class RequestEntity { @Enumerated(value = EnumType.STRING) private RequestType requestType; - @Column(name = "status") + /** + * This is the logical status of the request and + * represents if the intent of the request has been accomplished or not + * + * Status calculated by calculating {@link StageEntity#status} of all belonging stages + * + */ + @Column(name = "status", nullable = false) @Enumerated(value = EnumType.STRING) - private HostRoleStatus status; + private HostRoleStatus status = HostRoleStatus.PENDING; + + /** + * This status informs if any of the underlying tasks + * have faced any type of failures {@link HostRoleStatus#isFailedState()} + * + * Status calculated by only taking into account + * all belonging {@link HostRoleCommandEntity#status} (or {@link StageEntity#status}) + * + */ + @Column(name = "display_status", nullable = false) + @Enumerated(value = EnumType.STRING) + private HostRoleStatus displayStatus = HostRoleStatus.PENDING; @Basic @Column(name = "create_time", nullable = false) @@ -89,7 +108,7 @@ public class RequestEntity { @Column(name = "exclusive_execution", insertable = true, updatable = true, nullable = false) private Integer exclusive = 0; - @OneToMany(mappedBy = "request") + @OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE) private Collection<StageEntity> stages; @OneToMany(mappedBy = "requestEntity", cascade = CascadeType.ALL) @@ -207,14 +226,38 @@ public class RequestEntity { this.commandName = commandName; } + /** + * get status for the request + * @return {@link HostRoleStatus} + */ public HostRoleStatus getStatus() { return status; } + /** + * sets status for the request + * @param status {@link HostRoleStatus} + */ public void setStatus(HostRoleStatus status) { this.status = status; } + /** + * get display status for the request + * @return {@link HostRoleStatus} + */ + public HostRoleStatus getDisplayStatus() { + return displayStatus; + } + + /** + * sets display status for the request + * @param displayStatus {@link HostRoleStatus} + */ + public void setDisplayStatus(HostRoleStatus displayStatus) { + this.displayStatus = displayStatus; + } + public RequestScheduleEntity getRequestScheduleEntity() { return requestScheduleEntity; }
http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java index f9c8810..f68338f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java @@ -39,17 +39,21 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import org.apache.ambari.server.actionmanager.CommandExecutionType; +import org.apache.ambari.server.actionmanager.HostRoleStatus; @Entity @Table(name = "stage") @IdClass(org.apache.ambari.server.orm.entities.StageEntityPK.class) @NamedQueries({ @NamedQuery( - name = "StageEntity.findByCommandStatuses", - query = "SELECT stage from StageEntity stage WHERE stage.stageId IN (SELECT roleCommand.stageId from HostRoleCommandEntity roleCommand WHERE roleCommand.status IN :statuses AND roleCommand.stageId = stage.stageId AND roleCommand.requestId = stage.requestId ) ORDER BY stage.requestId, stage.stageId"), + name = "StageEntity.findByStatuses", + query = "SELECT stage from StageEntity stage WHERE stage.status IN :statuses ORDER BY stage.requestId, stage.stageId"), + @NamedQuery( + name = "StageEntity.findByPK", + query = "SELECT stage from StageEntity stage WHERE stage.requestId = :requestId AND stage.stageId = :stageId"), @NamedQuery( name = "StageEntity.findByRequestIdAndCommandStatuses", - query = "SELECT stage from StageEntity stage WHERE stage.stageId IN (SELECT roleCommand.stageId from HostRoleCommandEntity roleCommand WHERE roleCommand.requestId = :requestId AND roleCommand.status IN :statuses AND roleCommand.stageId = stage.stageId AND roleCommand.requestId = stage.requestId ) ORDER BY stage.stageId"), + query = "SELECT stage from StageEntity stage WHERE stage.status IN :statuses AND stage.requestId = :requestId ORDER BY stage.stageId"), @NamedQuery( name = "StageEntity.findIdsByRequestId", query = "SELECT stage.stageId FROM StageEntity stage WHERE stage.requestId = :requestId ORDER BY stage.stageId ASC") }) @@ -110,6 +114,32 @@ public class StageEntity { @Basic private byte[] hostParamsStage; + /** + * This status informs if the advanced criteria for the stage success + * as established at the time of stage creation has been accomplished or not + * + * Status calculated by taking into account following + * a) {@link #roleSuccessCriterias} + * b) {@link #skippable} + * c) {@link HostRoleCommandEntity#autoSkipOnFailure} + * d) {@link HostRoleCommandEntity#status} + * + */ + @Column(name = "status", nullable = false) + @Enumerated(EnumType.STRING) + private HostRoleStatus status = HostRoleStatus.PENDING; + + /** + * This status informs if any of the underlying tasks + * have faced any type of failures {@link HostRoleStatus#isFailedState()} + * + * Status calculated by only taking into account {@link HostRoleCommandEntity#status} + * + */ + @Column(name = "display_status", nullable = false) + @Enumerated(EnumType.STRING) + private HostRoleStatus displayStatus = HostRoleStatus.PENDING; + @ManyToOne @JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false) private RequestEntity request; @@ -195,6 +225,40 @@ public class StageEntity { this.commandExecutionType = commandExecutionType; } + /** + * get status for the stage + * @return {@link HostRoleStatus} + */ + public HostRoleStatus getStatus() { + return status; + } + + /** + * sets status for the stage + * @param status {@link HostRoleStatus} + */ + public void setStatus(HostRoleStatus status) { + this.status = status; + } + + /** + * get display status for the stage + * @return {@link HostRoleStatus} + */ + public HostRoleStatus getDisplayStatus() { + return displayStatus; + } + + + /** + * sets display status for the stage + * @param displayStatus {@link HostRoleStatus} + */ + public void setDisplayStatus(HostRoleStatus displayStatus) { + this.displayStatus = displayStatus; + } + + @Override public boolean equals(Object o) { if (this == o) { http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java index 9ca0470..34d175c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntityPK.java @@ -68,4 +68,16 @@ public class StageEntityPK implements Serializable { result = 31 * result + (stageId != null ? stageId.hashCode() : 0); return result; } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder buffer = new StringBuilder("StageEntityPK{"); + buffer.append("stageId=").append(getStageId()); + buffer.append("requestId=").append(getRequestId()); + buffer.append("}"); + return buffer.toString(); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java index 4f90ef3..0267a5e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog300.java @@ -19,11 +19,25 @@ package org.apache.ambari.server.upgrade; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Map; +import javax.persistence.EntityManager; + import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.actionmanager.HostRoleCommand; +import org.apache.ambari.server.actionmanager.HostRoleStatus; +import org.apache.ambari.server.actionmanager.Stage; +import org.apache.ambari.server.actionmanager.StageFactory; import org.apache.ambari.server.controller.AmbariManagementController; +import org.apache.ambari.server.controller.internal.CalculatedStatus; +import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.dao.DaoUtils; +import org.apache.ambari.server.orm.dao.RequestDAO; +import org.apache.ambari.server.orm.entities.RequestEntity; +import org.apache.ambari.server.orm.entities.StageEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; @@ -41,6 +55,12 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog { */ private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog300.class); + private static final String STAGE_TABLE = "stage"; + private static final String STAGE_STATUS_COLUMN = "status"; + private static final String STAGE_DISPLAY_STATUS_COLUMN = "display_status"; + private static final String REQUEST_TABLE = "request"; + private static final String REQUEST_DISPLAY_STATUS_COLUMN = "display_status"; + @Inject DaoUtils daoUtils; @@ -83,6 +103,16 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog { */ @Override protected void executeDDLUpdates() throws AmbariException, SQLException { + updateStageTable(); + } + + protected void updateStageTable() throws SQLException { + dbAccessor.addColumn(STAGE_TABLE, + new DBAccessor.DBColumnInfo(STAGE_STATUS_COLUMN, String.class, 255, HostRoleStatus.PENDING, false)); + dbAccessor.addColumn(STAGE_TABLE, + new DBAccessor.DBColumnInfo(STAGE_DISPLAY_STATUS_COLUMN, String.class, 255, HostRoleStatus.PENDING, false)); + dbAccessor.addColumn(REQUEST_TABLE, + new DBAccessor.DBColumnInfo(REQUEST_DISPLAY_STATUS_COLUMN, String.class, 255, HostRoleStatus.PENDING, false)); } /** @@ -99,6 +129,7 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog { protected void executeDMLUpdates() throws AmbariException, SQLException { addNewConfigurationsFromXml(); showHcatDeletedUserMessage(); + setStatusOfStagesAndRequests(); } protected void showHcatDeletedUserMessage() { @@ -122,4 +153,43 @@ public class UpgradeCatalog300 extends AbstractUpgradeCatalog { } + protected void setStatusOfStagesAndRequests() { + executeInTransaction(new Runnable() { + @Override + public void run() { + try { + RequestDAO requestDAO = injector.getInstance(RequestDAO.class); + StageFactory stageFactory = injector.getInstance(StageFactory.class); + EntityManager em = getEntityManagerProvider().get(); + List<RequestEntity> requestEntities= requestDAO.findAll(); + for (RequestEntity requestEntity: requestEntities) { + Collection<StageEntity> stageEntities= requestEntity.getStages(); + List <HostRoleStatus> stageDisplayStatuses = new ArrayList<>(); + List <HostRoleStatus> stageStatuses = new ArrayList<>(); + for (StageEntity stageEntity: stageEntities) { + Stage stage = stageFactory.createExisting(stageEntity); + List<HostRoleCommand> hostRoleCommands = stage.getOrderedHostRoleCommands(); + Map<HostRoleStatus, Integer> statusCount = CalculatedStatus.calculateStatusCountsForTasks(hostRoleCommands); + HostRoleStatus stageDisplayStatus = CalculatedStatus.calculateSummaryDisplayStatus(statusCount, hostRoleCommands.size(), stage.isSkippable()); + HostRoleStatus stageStatus = CalculatedStatus.calculateStageStatus(hostRoleCommands, statusCount, stage.getSuccessFactors(), stage.isSkippable()); + stageEntity.setStatus(stageStatus); + stageStatuses.add(stageStatus); + stageEntity.setDisplayStatus(stageDisplayStatus); + stageDisplayStatuses.add(stageDisplayStatus); + em.merge(stageEntity); + } + HostRoleStatus requestStatus = CalculatedStatus.getOverallStatusForRequest(stageStatuses); + requestEntity.setStatus(requestStatus); + HostRoleStatus requestDisplayStatus = CalculatedStatus.getOverallDisplayStatusForRequest(stageDisplayStatuses); + requestEntity.setDisplayStatus(requestDisplayStatus); + em.merge(requestEntity); + } + } catch (Exception e) { + LOG.warn("Setting status for stages and Requests threw exception. ", e); + } + } + }); + + } + } http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql index f007b53..6c7cb09 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql @@ -345,7 +345,8 @@ CREATE TABLE request ( request_type VARCHAR(255), request_schedule_id BIGINT, start_time BIGINT NOT NULL, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_request PRIMARY KEY (request_id), CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id)); @@ -361,6 +362,8 @@ CREATE TABLE stage ( command_params BLOB, host_params BLOB, command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE', + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id), CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id)); @@ -378,7 +381,7 @@ CREATE TABLE host_role_command ( start_time BIGINT NOT NULL, original_start_time BIGINT NOT NULL, end_time BIGINT, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', auto_skip_on_failure SMALLINT DEFAULT 0 NOT NULL, std_error BLOB, std_out BLOB, http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql index f6cb896..ebb0da0 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -356,7 +356,8 @@ CREATE TABLE request ( request_context VARCHAR(255), request_type VARCHAR(255), start_time BIGINT NOT NULL, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_request PRIMARY KEY (request_id), CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id)); @@ -372,6 +373,8 @@ CREATE TABLE stage ( command_params LONGBLOB, host_params LONGBLOB, command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE', + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id), CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id)); @@ -390,7 +393,7 @@ CREATE TABLE host_role_command ( start_time BIGINT NOT NULL, original_start_time BIGINT NOT NULL, end_time BIGINT, - status VARCHAR(100), + status VARCHAR(100) NOT NULL DEFAULT 'PENDING', auto_skip_on_failure SMALLINT DEFAULT 0 NOT NULL, std_error LONGBLOB, std_out LONGBLOB, http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql index 19253e8..884eb06 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -336,7 +336,8 @@ CREATE TABLE request ( request_context VARCHAR(255), request_type VARCHAR(255), start_time NUMBER(19) NOT NULL, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_request PRIMARY KEY (request_id), CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id)); @@ -352,6 +353,8 @@ CREATE TABLE stage ( command_params BLOB, host_params BLOB, command_execution_type VARCHAR2(32) DEFAULT 'STAGE' NOT NULL, + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id), CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id)); @@ -370,7 +373,7 @@ CREATE TABLE host_role_command ( start_time NUMBER(19) NOT NULL, original_start_time NUMBER(19) NOT NULL, end_time NUMBER(19), - status VARCHAR2(255) NULL, + status VARCHAR2(255) NOT NULL DEFAULT 'PENDING', auto_skip_on_failure NUMBER(1) DEFAULT 0 NOT NULL, std_error BLOB NULL, std_out BLOB NULL, http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index b13a9e3..7e57d9f 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -345,7 +345,8 @@ CREATE TABLE request ( request_type VARCHAR(255), request_schedule_id BIGINT, start_time BIGINT NOT NULL, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_request PRIMARY KEY (request_id), CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id)); @@ -361,6 +362,8 @@ CREATE TABLE stage ( command_params BYTEA, host_params BYTEA, command_execution_type VARCHAR(32) DEFAULT 'STAGE' NOT NULL, + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id), CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id)); @@ -378,7 +381,7 @@ CREATE TABLE host_role_command ( start_time BIGINT NOT NULL, original_start_time BIGINT NOT NULL, end_time BIGINT, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', auto_skip_on_failure SMALLINT DEFAULT 0 NOT NULL, std_error BYTEA, std_out BYTEA, http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql index cf2954a..2c4bd55 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql @@ -334,7 +334,8 @@ CREATE TABLE request ( request_context VARCHAR(255), request_type VARCHAR(255), start_time NUMERIC(19) NOT NULL, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_request PRIMARY KEY (request_id), CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id)); @@ -350,6 +351,8 @@ CREATE TABLE stage ( command_params IMAGE, host_params IMAGE, command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE', + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id), CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id)); @@ -368,7 +371,7 @@ CREATE TABLE host_role_command ( start_time NUMERIC(19) NOT NULL, original_start_time NUMERIC(19) NOT NULL, end_time NUMERIC(19), - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', auto_skip_on_failure SMALLINT DEFAULT 0 NOT NULL, std_error IMAGE, std_out IMAGE, http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index 16c269a..a86a767 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -350,7 +350,8 @@ CREATE TABLE request ( request_type VARCHAR(255), request_schedule_id BIGINT, start_time BIGINT NOT NULL, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_request PRIMARY KEY CLUSTERED (request_id), CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id)); @@ -366,6 +367,8 @@ CREATE TABLE stage ( command_params VARBINARY(MAX), host_params VARBINARY(MAX), command_execution_type VARCHAR(32) NOT NULL DEFAULT 'STAGE', + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', + display_status VARCHAR(255) NOT NULL DEFAULT 'PENDING', CONSTRAINT PK_stage PRIMARY KEY CLUSTERED (stage_id, request_id), CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id)); @@ -383,7 +386,7 @@ CREATE TABLE host_role_command ( start_time BIGINT NOT NULL, original_start_time BIGINT NOT NULL, end_time BIGINT, - status VARCHAR(255), + status VARCHAR(255) NOT NULL DEFAULT 'PENDING', auto_skip_on_failure SMALLINT DEFAULT 0 NOT NULL, std_error VARBINARY(max), std_out VARBINARY(max), http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java index 177ac70..edc5683 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java @@ -55,6 +55,7 @@ import org.apache.ambari.server.utils.CommandUtils; import org.apache.ambari.server.utils.StageUtils; import org.easymock.EasyMock; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; @@ -67,8 +68,6 @@ import com.google.inject.Injector; import com.google.inject.Singleton; import com.google.inject.util.Modules; -import junit.framework.Assert; - public class TestActionDBAccessorImpl { private static final Logger log = LoggerFactory.getLogger(TestActionDBAccessorImpl.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java index 6519126..526ca7c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java @@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyCollectionOf; +import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -100,9 +101,11 @@ import org.apache.ambari.server.utils.StageUtils; import org.easymock.Capture; import org.easymock.EasyMock; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.slf4j.Logger; @@ -119,8 +122,6 @@ import com.google.inject.Injector; import com.google.inject.Provider; import com.google.inject.persist.UnitOfWork; -import junit.framework.Assert; - public class TestActionScheduler { private static final Logger log = LoggerFactory.getLogger(TestActionScheduler.class); @@ -207,6 +208,8 @@ public class TestActionScheduler { when(host.getHostName()).thenReturn(hostname); ActionDBAccessor db = mock(ActionDBAccessorImpl.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); List<Stage> stages = new ArrayList<Stage>(); Stage s = StageUtils.getATestStage(1, 977, hostname, CLUSTER_HOST_INFO, "{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}"); @@ -222,7 +225,7 @@ public class TestActionScheduler { //Keep large number of attempts so that the task is not expired finally //Small action timeout to test rescheduling ActionScheduler scheduler = new ActionScheduler(100, 5, db, aq, fsm, - 10000, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, null, null); + 10000, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, hostRoleCommandDAOMock, null); scheduler.setTaskTimeoutAdjustment(false); List<AgentCommand> ac = waitForQueueSize(hostname, aq, 1, scheduler); @@ -314,6 +317,8 @@ public class TestActionScheduler { stages.add(s); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); when(db.getCommandsInProgressCount()).thenReturn(stages.size()); when(db.getStagesInProgress()).thenReturn(stages); @@ -335,7 +340,7 @@ public class TestActionScheduler { //Small action timeout to test rescheduling ActionScheduler scheduler = new ActionScheduler(100, 0, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, null, null); + new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, hostRoleCommandDAOMock, null); scheduler.setTaskTimeoutAdjustment(false); // Start the thread @@ -405,6 +410,8 @@ public class TestActionScheduler { when(db.getCommandsInProgressCount()).thenReturn(stages.size()); when(db.getStagesInProgress()).thenReturn(stages); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); doAnswer(new Answer<Void>() { @Override @@ -508,6 +515,8 @@ public class TestActionScheduler { when(db.getCommandsInProgressCount()).thenReturn(stages.size()); when(db.getStagesInProgress()).thenReturn(stages); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); doAnswer(new Answer<Collection<HostRoleCommandEntity>>() { @Override @@ -543,7 +552,7 @@ public class TestActionScheduler { // Make sure the NN install doesn't timeout ActionScheduler scheduler = new ActionScheduler(100, 50000, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); scheduler.setTaskTimeoutAdjustment(false); int cycleCount=0; @@ -606,6 +615,8 @@ public class TestActionScheduler { stages.add(s); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -658,7 +669,7 @@ public class TestActionScheduler { ServerActionExecutor.init(injector); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(null, "AMBARI_SERVER_ACTION") @@ -721,6 +732,8 @@ public class TestActionScheduler { stages.add(stage12); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -735,7 +748,7 @@ public class TestActionScheduler { ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, EasyMock.createNiceMock(AmbariEventPublisher.class), conf, - entityManagerProviderMock, (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + entityManagerProviderMock, hostRoleCommandDAOMock, (HostRoleCommandFactory)null); scheduler.doWork(); @@ -763,6 +776,8 @@ public class TestActionScheduler { stages.add(s); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -816,7 +831,7 @@ public class TestActionScheduler { ServerActionExecutor.init(injector); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(null, "AMBARI_SERVER_ACTION").isCompletedState() @@ -976,6 +991,8 @@ public class TestActionScheduler { stages.add(s); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1028,7 +1045,7 @@ public class TestActionScheduler { ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(null, "AMBARI_SERVER_ACTION") @@ -1124,6 +1141,8 @@ public class TestActionScheduler { RoleCommand.START, Service.Type.GANGLIA, 5, 5, 4)); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1136,7 +1155,7 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null)); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null)); doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString()); @@ -1214,6 +1233,8 @@ public class TestActionScheduler { RoleCommand.START, Service.Type.GANGLIA, 5, 5, 4)); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1228,7 +1249,7 @@ public class TestActionScheduler { ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null)); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null)); doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString()); @@ -1289,6 +1310,8 @@ public class TestActionScheduler { ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1303,7 +1326,7 @@ public class TestActionScheduler { ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null)); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null)); doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString()); @@ -1544,6 +1567,8 @@ public class TestActionScheduler { stage.setLastAttemptTime(host2, Role.HBASE_CLIENT.toString(), now); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1616,7 +1641,7 @@ public class TestActionScheduler { ActionScheduler scheduler = new ActionScheduler(100, 10000, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); scheduler.doWork(); @@ -1729,6 +1754,8 @@ public class TestActionScheduler { "host1", "cluster1", Role.HDFS_CLIENT, RoleCommand.UPGRADE, Service.Type.HDFS, 4, 2, 1)); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1808,7 +1835,7 @@ public class TestActionScheduler { ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); ActionManager am = new ActionManager(db, requestFactory, scheduler); @@ -1976,6 +2003,8 @@ public class TestActionScheduler { when(host.getHostName()).thenReturn(hostname); ActionDBAccessor db = mock(ActionDBAccessorImpl.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -1993,7 +2022,7 @@ public class TestActionScheduler { //Small action timeout to test rescheduling ActionScheduler scheduler = new ActionScheduler(100, 100, db, aq, fsm, 10000, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); scheduler.setTaskTimeoutAdjustment(false); List<AgentCommand> ac = waitForQueueSize(hostname, aq, 1, scheduler); @@ -2135,6 +2164,8 @@ public class TestActionScheduler { stages.add(s); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -2187,7 +2218,7 @@ public class TestActionScheduler { ServerActionExecutor.init(injector); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(null, "AMBARI_SERVER_ACTION") @@ -2467,6 +2498,8 @@ public class TestActionScheduler { when(host3.getHostName()).thenReturn(hostname); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); when(db.getCommandsInProgressCount()).thenReturn(stagesInProgress.size()); when(db.getStagesInProgress()).thenReturn(stagesInProgress); @@ -2542,7 +2575,7 @@ public class TestActionScheduler { ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null)); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null)); doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString()); @@ -2706,6 +2739,8 @@ public class TestActionScheduler { command.setStatus(HostRoleStatus.FAILED); ActionDBAccessor db = mock(ActionDBAccessor.class); + HostRoleCommandDAO hostRoleCommandDAOMock = mock(HostRoleCommandDAO.class); + Mockito.doNothing().when(hostRoleCommandDAOMock).publishTaskCreateEvent(anyListOf(HostRoleCommand.class)); RequestEntity request = mock(RequestEntity.class); when(request.isExclusive()).thenReturn(false); @@ -2776,7 +2811,7 @@ public class TestActionScheduler { ActionScheduler scheduler = spy(new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), unitOfWork, null, conf, entityManagerProviderMock, - (HostRoleCommandDAO)null, (HostRoleCommandFactory)null)); + hostRoleCommandDAOMock, (HostRoleCommandFactory)null)); doReturn(false).when(scheduler).wasAgentRestartedDuringOperation(any(Host.class), any(Stage.class), anyString()); http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnableTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnableTest.java b/ambari-server/src/test/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnableTest.java index 7b1a5a2..facd802 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnableTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/alerts/AmbariPerformanceRunnableTest.java @@ -18,12 +18,13 @@ package org.apache.ambari.server.alerts; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.lang.reflect.Field; import java.util.ArrayList; @@ -34,6 +35,7 @@ import java.util.Map; import javax.persistence.EntityManager; import org.apache.ambari.server.actionmanager.ActionManager; +import org.apache.ambari.server.actionmanager.HostRoleCommandFactory; import org.apache.ambari.server.alerts.AmbariPerformanceRunnable.PerformanceArea; import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.controller.internal.ClusterResourceProvider; @@ -287,6 +289,7 @@ public class AmbariPerformanceRunnableTest { binder.bind(AlertsDAO.class).toInstance(createNiceMock(AlertsDAO.class)); binder.bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class)); binder.bind(ActionManager.class).toInstance(createNiceMock(ActionManager.class)); + binder.bind(HostRoleCommandFactory.class).toInstance(createNiceMock(HostRoleCommandFactory.class)); binder.bind(HostRoleCommandDAO.class).toInstance(createNiceMock(HostRoleCommandDAO.class)); binder.bind(AmbariManagementController.class).toInstance(createNiceMock(AmbariManagementController.class)); binder.bind(AlertDefinitionFactory.class).toInstance(createNiceMock(AlertDefinitionFactory.class)); http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java index a0701b6..f8b57e5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java @@ -624,7 +624,6 @@ public class UpgradeResourceProviderTest { RequestEntity requestEntity = new RequestEntity(); requestEntity.setRequestId(2L); requestEntity.setClusterId(cluster.getClusterId()); - requestEntity.setStatus(HostRoleStatus.PENDING); requestEntity.setStages(new ArrayList<StageEntity>()); requestDao.create(requestEntity); http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java index 619e367..f009767 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java @@ -205,7 +205,6 @@ public class UpgradeSummaryResourceProviderTest { RequestEntity requestEntity = new RequestEntity(); requestEntity.setRequestId(upgradeRequestId); requestEntity.setClusterId(cluster.getClusterId()); - requestEntity.setStatus(HostRoleStatus.PENDING); requestDAO.create(requestEntity); // Create the stage and add it to the request http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java new file mode 100644 index 0000000..64a731b --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListenerTest.java @@ -0,0 +1,164 @@ +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.events.listeners.tasks; + +import static org.easymock.EasyMock.anyLong; +import static org.easymock.EasyMock.anyObject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.ambari.server.Role; +import org.apache.ambari.server.RoleCommand; +import org.apache.ambari.server.actionmanager.ExecutionCommandWrapperFactory; +import org.apache.ambari.server.actionmanager.HostRoleCommand; +import org.apache.ambari.server.actionmanager.HostRoleStatus; +import org.apache.ambari.server.events.TaskCreateEvent; +import org.apache.ambari.server.events.TaskUpdateEvent; +import org.apache.ambari.server.events.publishers.TaskEventPublisher; +import org.apache.ambari.server.orm.dao.ExecutionCommandDAO; +import org.apache.ambari.server.orm.dao.HostDAO; +import org.apache.ambari.server.orm.dao.RequestDAO; +import org.apache.ambari.server.orm.dao.StageDAO; +import org.apache.ambari.server.orm.entities.RequestEntity; +import org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity; +import org.apache.ambari.server.orm.entities.StageEntity; +import org.apache.ambari.server.orm.entities.StageEntityPK; +import org.apache.ambari.server.state.ServiceComponentHostEvent; +import org.easymock.EasyMock; +import org.easymock.EasyMockSupport; +import org.junit.Assert; +import org.junit.Test; + +import com.google.inject.Inject; + + +public class TaskStatusListenerTest extends EasyMockSupport { + + private TaskEventPublisher publisher = new TaskEventPublisher(); + + @Inject + private ExecutionCommandDAO executionCommandDAO; + + @Inject + private ExecutionCommandWrapperFactory ecwFactory; + + + @Test + public void testOnTaskUpdateEvent() { + List<HostRoleCommand> hostRoleCommands = new ArrayList<HostRoleCommand>(); + ServiceComponentHostEvent serviceComponentHostEvent = createNiceMock(ServiceComponentHostEvent.class); + HostDAO hostDAO = createNiceMock(HostDAO.class); + replayAll(); + + int hostRoleCommandSize = 3; + int hrcCounter = 1; + for (int stageCounter = 0; stageCounter < 2; stageCounter++) { + for (int i = 1; i <= hostRoleCommandSize; i++,hrcCounter++) { + String hostname = "hostname-" + hrcCounter; + HostRoleCommand hostRoleCommand = new HostRoleCommand(hostname, Role.DATANODE, + serviceComponentHostEvent, RoleCommand.EXECUTE, hostDAO, executionCommandDAO, ecwFactory); + hostRoleCommand.setStatus(HostRoleStatus.PENDING); + hostRoleCommand.setRequestId(1L); + hostRoleCommand.setStageId(stageCounter); + hostRoleCommand.setTaskId(hrcCounter); + hostRoleCommands.add(hostRoleCommand); + } + } + + HostRoleStatus hostRoleStatus = HostRoleStatus.PENDING; + StageDAO stageDAO = createNiceMock(StageDAO.class); + RequestDAO requestDAO = createNiceMock(RequestDAO.class); + StageEntity stageEntity = createNiceMock(StageEntity.class); + RequestEntity requestEntity = createNiceMock(RequestEntity.class); + EasyMock.expect(stageEntity.getStatus()).andReturn(hostRoleStatus).anyTimes();; + EasyMock.expect(stageEntity.getDisplayStatus()).andReturn(hostRoleStatus).anyTimes(); + EasyMock.expect(stageEntity.isSkippable()).andReturn(Boolean.FALSE).anyTimes();; + EasyMock.expect(stageEntity.getRoleSuccessCriterias()).andReturn(Collections.<RoleSuccessCriteriaEntity>emptyList()).anyTimes(); + EasyMock.expect(stageDAO.findByPK(anyObject(StageEntityPK.class))).andReturn(stageEntity).anyTimes(); + EasyMock.expect(requestEntity.getStatus()).andReturn(hostRoleStatus).anyTimes();; + EasyMock.expect(requestEntity.getDisplayStatus()).andReturn(hostRoleStatus).anyTimes(); + EasyMock.expect(requestDAO.findByPK(anyLong())).andReturn(requestEntity).anyTimes(); + + requestDAO.updateStatus(1L,HostRoleStatus.COMPLETED,HostRoleStatus.SKIPPED_FAILED); + EasyMock.expectLastCall().times(1); + + + + EasyMock.replay(stageEntity); + EasyMock.replay(requestEntity); + EasyMock.replay(stageDAO); + EasyMock.replay(requestDAO); + + TaskCreateEvent event = new TaskCreateEvent(hostRoleCommands); + TaskStatusListener listener = new TaskStatusListener(publisher,stageDAO,requestDAO); + + Assert.assertTrue(listener.getActiveTasksMap().isEmpty()); + Assert.assertTrue(listener.getActiveStageMap().isEmpty()); + Assert.assertTrue(listener.getActiveRequestMap().isEmpty()); + + listener.onTaskCreateEvent(event); + Assert.assertEquals(listener.getActiveTasksMap().size(),6); + Assert.assertEquals(listener.getActiveStageMap().size(),2); + Assert.assertEquals(listener.getActiveRequestMap().size(),1); + Assert.assertEquals(listener.getActiveRequestMap().get(1L).getStatus(), hostRoleStatus); + + + + // update of a task status of IN_PROGRESS should cascade into an update of request status + String hostname = "hostname-1"; + HostRoleCommand hostRoleCommand = new HostRoleCommand(hostname, Role.DATANODE, + serviceComponentHostEvent, RoleCommand.EXECUTE, hostDAO, executionCommandDAO, ecwFactory); + hostRoleCommand.setStatus(HostRoleStatus.IN_PROGRESS); + hostRoleCommand.setRequestId(1L); + hostRoleCommand.setStageId(0); + hostRoleCommand.setTaskId(1L); + listener.onTaskUpdateEvent(new TaskUpdateEvent(Collections.singletonList(hostRoleCommand))); + Assert.assertEquals(HostRoleStatus.IN_PROGRESS, listener.getActiveRequestMap().get(1L).getStatus()); + + // update of all tasks status of skip_failed and completed states should cascade into request status of completed + // and request display status to be of skip_failed + hrcCounter = 1; + List<HostRoleCommand> finalHostRoleCommands = new ArrayList<HostRoleCommand>(); + HostRoleStatus finalHostRoleStatus = HostRoleStatus.COMPLETED; + for (int stageCounter = 0; stageCounter < 2; stageCounter++) { + for (int i = 1; i <= hostRoleCommandSize; i++,hrcCounter++) { + String finalHostname = "hostname-" + hrcCounter; + HostRoleCommand finalHostRoleCommand = new HostRoleCommand(finalHostname, Role.DATANODE, + serviceComponentHostEvent, RoleCommand.EXECUTE, hostDAO, executionCommandDAO, ecwFactory); + finalHostRoleCommand.setStatus(finalHostRoleStatus); + finalHostRoleCommand.setRequestId(1L); + finalHostRoleCommand.setStageId(stageCounter); + finalHostRoleCommand.setTaskId(hrcCounter); + finalHostRoleCommands.add(finalHostRoleCommand); + } + finalHostRoleStatus = HostRoleStatus.SKIPPED_FAILED; + } + + listener.onTaskUpdateEvent(new TaskUpdateEvent(finalHostRoleCommands)); + + //Once request status and display status are in completed state, it should no longer be tracked by TaskStatusListener + Assert.assertNull(listener.getActiveRequestMap().get(1L)); + + // verify request status = completed and display_status = skip_failed + verifyAll(); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java index b1c10f5..1709da8 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java @@ -38,6 +38,7 @@ import javax.persistence.EntityManager; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.H2DatabaseCleaner; +import org.apache.ambari.server.actionmanager.HostRoleCommandFactory; import org.apache.ambari.server.actionmanager.RequestFactory; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.controller.AmbariCustomCommandExecutionHelper; @@ -980,6 +981,7 @@ public class ConfigHelperTest { bind(Clusters.class).toInstance(createNiceMock(Clusters.class)); bind(ClusterController.class).toInstance(clusterController); bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class)); + bind(HostRoleCommandFactory.class).toInstance(createNiceMock(HostRoleCommandFactory.class)); bind(HostRoleCommandDAO.class).toInstance(createNiceMock(HostRoleCommandDAO.class)); } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java index 9d339e2..d3c8acf 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterEffectiveVersionTest.java @@ -24,6 +24,7 @@ import java.util.List; import javax.persistence.EntityManager; import org.apache.ambari.server.actionmanager.ActionManager; +import org.apache.ambari.server.actionmanager.HostRoleCommandFactory; import org.apache.ambari.server.actionmanager.RequestFactory; import org.apache.ambari.server.actionmanager.StageFactory; import org.apache.ambari.server.api.services.AmbariMetaInfo; @@ -68,6 +69,7 @@ import org.apache.ambari.server.state.stack.upgrade.UpgradeType; import org.easymock.EasyMock; import org.easymock.EasyMockSupport; import org.eclipse.jetty.server.SessionManager; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -83,8 +85,6 @@ import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.assistedinject.FactoryModuleBuilder; -import junit.framework.Assert; - /** * Tests that cluster effective version is calcualted correctly during upgrades. */ @@ -256,6 +256,7 @@ public class ClusterEffectiveVersionTest extends EasyMockSupport { binder.bind(DBAccessor.class).toInstance(EasyMock.createNiceMock(DBAccessor.class)); binder.bind(EntityManager.class).toInstance(EasyMock.createNiceMock(EntityManager.class)); binder.bind(ActionManager.class).toInstance(EasyMock.createNiceMock(ActionManager.class)); + binder.bind(HostRoleCommandFactory.class).toInstance(EasyMock.createNiceMock(HostRoleCommandFactory.class)); binder.bind(HostRoleCommandDAO.class).toInstance(EasyMock.createNiceMock(HostRoleCommandDAO.class)); binder.bind(AmbariManagementController.class).toInstance(EasyMock.createNiceMock(AmbariManagementController.class)); binder.bind(ClusterController.class).toInstance(EasyMock.createNiceMock(ClusterController.class)); http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java index ed95b0b..e699e49 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java @@ -251,7 +251,6 @@ public class RetryUpgradeActionServiceTest { RequestEntity requestEntity = new RequestEntity(); requestEntity.setRequestId(upgradeRequestId); requestEntity.setClusterId(cluster.getClusterId()); - requestEntity.setStatus(HostRoleStatus.PENDING); requestDAO.create(requestEntity); // Create the stage and add it to the request http://git-wip-us.apache.org/repos/asf/ambari/blob/0fc7a667/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java index d7979e8..ec001ec 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java @@ -31,15 +31,18 @@ public class UpgradeCatalog300Test { public void testExecuteDMLUpdates() throws Exception { Method addNewConfigurationsFromXml = AbstractUpgradeCatalog.class.getDeclaredMethod("addNewConfigurationsFromXml"); Method showHcatDeletedUserMessage = UpgradeCatalog300.class.getDeclaredMethod("showHcatDeletedUserMessage"); + Method setStatusOfStagesAndRequests = UpgradeCatalog300.class.getDeclaredMethod("setStatusOfStagesAndRequests"); UpgradeCatalog300 upgradeCatalog300 = createMockBuilder(UpgradeCatalog300.class) .addMockedMethod(showHcatDeletedUserMessage) .addMockedMethod(addNewConfigurationsFromXml) + .addMockedMethod(setStatusOfStagesAndRequests) .createMock(); upgradeCatalog300.addNewConfigurationsFromXml(); upgradeCatalog300.showHcatDeletedUserMessage(); + upgradeCatalog300.setStatusOfStagesAndRequests(); replay(upgradeCatalog300); @@ -49,4 +52,21 @@ public class UpgradeCatalog300Test { verify(upgradeCatalog300); } + @Test + public void testExecuteDDLUpdates() throws Exception { + Method updateStageTable = UpgradeCatalog300.class.getDeclaredMethod("updateStageTable"); + UpgradeCatalog300 upgradeCatalog300 = createMockBuilder(UpgradeCatalog300.class) + .addMockedMethod(updateStageTable) + .createMock(); + + upgradeCatalog300.updateStageTable(); + + replay(upgradeCatalog300); + + upgradeCatalog300.executeDDLUpdates(); + + verify(upgradeCatalog300); + } + + }
