From 2c844e859952e35aaacbcf62200eb9499db79882 Mon Sep 17 00:00:00 2001 From: Swapan Shridhar Date: Mon, 5 Mar 2018 11:21:08 -0800 Subject: [PATCH] AMBARI-22945. Enhance host components API to support multiple host component instances. --- ...ServiceComponentHostNotFoundException.java | 9 + .../api/services/HostComponentService.java | 228 +++++-- .../services/RootClusterSettingService.java | 3 - .../AmbariManagementController.java | 13 + .../AmbariManagementControllerImpl.java | 81 ++- .../ServiceComponentHostRequest.java | 47 +- .../ServiceComponentHostResponse.java | 40 +- .../controller/ServiceComponentRequest.java | 28 +- .../controller/ServiceComponentResponse.java | 52 +- .../internal/AbstractProviderModule.java | 9 +- .../ClientConfigResourceProvider.java | 5 + .../internal/ComponentResourceProvider.java | 50 +- .../HostComponentResourceProvider.java | 56 +- .../internal/HostResourceProvider.java | 2 + .../controller/internal/HostStatusHelper.java | 8 +- .../internal/ServiceResourceProvider.java | 1 + .../StackDefinedPropertyProvider.java | 16 +- .../MetricsCollectorHAClusterState.java | 34 +- .../ganglia/GangliaPropertyProvider.java | 1 - .../state/DefaultServiceCalculatedState.java | 2 +- .../state/FlumeServiceCalculatedState.java | 2 +- .../state/HBaseServiceCalculatedState.java | 2 +- .../state/HDFSServiceCalculatedState.java | 2 +- .../state/HiveServiceCalculatedState.java | 2 +- .../state/OozieServiceCalculatedState.java | 2 +- .../state/YARNServiceCalculatedState.java | 2 +- .../orm/dao/HostComponentDesiredStateDAO.java | 15 +- .../server/orm/dao/HostComponentStateDAO.java | 15 +- .../dao/ServiceComponentDesiredStateDAO.java | 38 +- .../HostComponentDesiredStateEntity.java | 24 +- .../entities/HostComponentStateEntity.java | 72 ++- .../ServiceComponentDesiredStateEntity.java | 23 +- .../apache/ambari/server/state/Cluster.java | 16 + .../apache/ambari/server/state/Service.java | 2 +- .../ambari/server/state/ServiceComponent.java | 4 + .../server/state/ServiceComponentFactory.java | 5 +- .../server/state/ServiceComponentHost.java | 14 +- .../server/state/ServiceComponentImpl.java | 55 +- .../ambari/server/state/ServiceImpl.java | 61 +- .../server/state/cluster/ClusterImpl.java | 52 ++ .../svccomphost/ServiceComponentHostImpl.java | 34 +- .../ambari/server/topology/AmbariContext.java | 4 +- .../resources/Ambari-DDL-Derby-CREATE.sql | 6 + .../resources/Ambari-DDL-MySQL-CREATE.sql | 6 + .../resources/Ambari-DDL-Oracle-CREATE.sql | 8 +- .../resources/Ambari-DDL-Postgres-CREATE.sql | 6 + .../Ambari-DDL-SQLAnywhere-CREATE.sql | 6 + .../resources/Ambari-DDL-SQLServer-CREATE.sql | 7 + .../src/main/resources/key_properties.json | 2 +- .../server/agent/HeartbeatProcessorTest.java | 48 +- .../server/agent/TestHeartbeatHandler.java | 56 +- .../server/agent/TestHeartbeatMonitor.java | 34 +- .../api/query/render/MinimalRendererTest.java | 8 +- .../RecoveryConfigHelperTest.java | 18 +- ...mbariCustomCommandExecutionHelperTest.java | 46 +- .../AmbariManagementControllerImplTest.java | 452 +++++++++++--- .../AmbariManagementControllerTest.java | 584 +++++++++--------- .../BackgroundCustomCommandExecutionTest.java | 4 +- ...arnCapacitySchedulerReleaseConfigTest.java | 8 +- .../ClientConfigResourceProviderTest.java | 4 +- .../ComponentResourceProviderTest.java | 23 +- .../HostComponentResourceProviderTest.java | 25 +- .../internal/HostResourceProviderTest.java | 26 +- .../internal/JMXHostProviderTest.java | 4 +- ...ServiceDependencyResourceProviderTest.java | 4 +- ...ceGroupDependencyResourceProviderTest.java | 4 +- .../StackDefinedPropertyProviderTest.java | 14 +- .../UpgradeSummaryResourceProviderTest.java | 4 +- .../DefaultServiceCalculatedStateTest.java | 4 +- .../FlumeServiceCalculatedStateTest.java | 2 +- .../HBaseServiceCalculatedStateTest.java | 6 +- .../state/HDFSServiceCalculatedStateTest.java | 6 +- .../state/HiveServiceCalculatedStateTest.java | 10 +- .../OozieServiceCalculatedStateTest.java | 4 +- .../state/YarnServiceCalculatedStateTest.java | 6 +- .../ambari/server/events/EventsTest.java | 2 +- .../HostVersionOutOfSyncListenerTest.java | 4 +- .../ambari/server/orm/OrmTestHelper.java | 6 +- .../ComponentVersionCheckActionTest.java | 2 +- .../CreateAndConfigureActionTest.java | 2 +- .../server/state/ServiceComponentTest.java | 29 +- .../ambari/server/state/ServiceTest.java | 10 +- .../state/cluster/ClusterDeadlockTest.java | 2 +- .../server/state/cluster/ClusterImplTest.java | 8 +- .../server/state/cluster/ClusterTest.java | 58 +- .../state/cluster/ClustersDeadlockTest.java | 2 +- .../server/state/cluster/ClustersTest.java | 25 +- .../ConcurrentServiceConfigVersionTest.java | 2 +- ...ponentHostConcurrentWriteDeadlockTest.java | 14 +- .../svccomphost/ServiceComponentHostTest.java | 18 +- .../controllers/wizard/step8_controller.js | 34 +- 91 files changed, 1898 insertions(+), 896 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java index c870b652d58..af1cd694a50 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java @@ -31,4 +31,13 @@ public ServiceComponentHostNotFoundException(String clusterName, + ", hostName=" + hostName); } + public ServiceComponentHostNotFoundException(String clusterName, + String serviceName, Long serviceComponentId, String hostName) { + super("ServiceComponentHost not found" + + ", clusterName=" + clusterName + + ", serviceName=" + serviceName + + ", serviceComponentId=" + serviceComponentId + + ", hostName=" + hostName); + } + } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostComponentService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostComponentService.java index a5e9aec1783..503c301dabc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostComponentService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/HostComponentService.java @@ -1,4 +1,4 @@ -/* +/** * 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 @@ -35,20 +35,34 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.apache.ambari.annotations.ApiIgnore; import org.apache.ambari.server.api.resources.ResourceInstance; import org.apache.ambari.server.configuration.Configuration; +import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.controller.spi.Resource; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; +import org.apache.http.HttpStatus; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; /** * Service responsible for host_components resource requests. */ +@Api(value = "HostComponents", description = "Endpoint for host component specific operations") public class HostComponentService extends BaseService { + private static final String HOST_COMPONENT_REQUEST_TYPE = "org.apache.ambari.server.controller.ServiceComponentHostRequestSwagger"; + + /** * Parent cluster id. */ @@ -71,19 +85,33 @@ public HostComponentService(String clusterName, String hostName) { } /** - * Handles GET /clusters/{clusterID}/hosts/{hostID}/host_components/{hostComponentID} + * Handles GET /clusters/{clusterName}/hosts/{hostID}/host_components/{hostComponentID} * Get a specific host_component. * * @param headers http headers * @param ui uri info - * @param hostComponentName host_component id - * @return host_component resource representation + * @param hostComponentId host_component id + * @return host_component resource representation */ - @GET @ApiIgnore // until documented - @Path("{hostComponentName}") + @GET + @Path("{hostComponentId}") @Produces("text/plain") + @ApiOperation(value = "Get the details of a given Host Component", + nickname = "HostComponentService#getHostComponent", + notes = "Returns the details of a hostComponent", + response = ServiceComponentHostResponse.ServiceComponentHostResponseSwagger.class, + responseContainer = RESPONSE_CONTAINER_LIST) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "HostRoles/*", + dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY) + }) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR) + }) public Response getHostComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("hostComponentName") String hostComponentName, @QueryParam("format") String format) { + @PathParam("hostComponentId") String hostComponentId, @QueryParam("format") String format) { //todo: needs to be refactored when properly handling exceptions if (m_hostName == null) { @@ -93,11 +121,11 @@ public Response getHostComponent(String body, @Context HttpHeaders headers, @Con } if (format != null && format.equals("client_config_tar")) { - return createClientConfigResource(body, headers, ui, hostComponentName); + return createClientConfigResource(body, headers, ui, hostComponentId); } return handleRequest(headers, body, ui, Request.Type.GET, - createHostComponentResource(m_clusterName, m_hostName, hostComponentName)); + createHostComponentResource(m_clusterName, m_hostName, hostComponentId)); } /** @@ -108,8 +136,30 @@ public Response getHostComponent(String body, @Context HttpHeaders headers, @Con * @param ui uri info * @return host_component collection resource representation */ - @GET @ApiIgnore // until documented - @Produces("text/plain") + @GET + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Get all Host Components", + nickname = "HostComponentService#getHostComponents", + notes = "Returns all Host Components.", + response = ServiceComponentHostResponse.ServiceComponentHostResponseSwagger.class, + responseContainer = RESPONSE_CONTAINER_LIST) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, + defaultValue = "HostRoles/cluster_name, HostRoles/component_name, HostRoles/host_name, HostRoles/id, " + + "HostRoles/service_group_name, HostRoles/service_name", + dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, + defaultValue = "HostRoles/cluster_name.asc, HostRoles/component_name.asc, HostRoles/host_name.asc, " + + "HostRoles/service_group_name.asc, HostRoles/service_name.asc", + dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, dataType = DATA_TYPE_INT, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_FROM, value = QUERY_FROM_DESCRIPTION, defaultValue = DEFAULT_FROM, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), + @ApiImplicitParam(name = QUERY_TO, value = QUERY_TO_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY) + }) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR) + }) public Response getHostComponents(String body, @Context HttpHeaders headers, @Context UriInfo ui, @QueryParam("format") String format) { if (format != null && format.equals("client_config_tar")) { return createClientConfigResource(body, headers, ui, null); @@ -129,35 +179,30 @@ public Response getHostComponents(String body, @Context HttpHeaders headers, @Co * * @return status code only, 201 if successful */ - @POST @ApiIgnore // until documented - @Produces("text/plain") + @POST + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Creates a Host Component", + nickname = "HostComponentService#createHostComponents" + ) + @ApiImplicitParams({ + @ApiImplicitParam(dataType = HOST_COMPONENT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_CREATED, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_CONFLICT, message = MSG_RESOURCE_ALREADY_EXISTS), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response createHostComponents(String body, @Context HttpHeaders headers, @Context UriInfo ui) { return handleRequest(headers, body, ui, Request.Type.POST, createHostComponentResource(m_clusterName, m_hostName, null)); } - /** - * Handles POST /clusters/{clusterID}/hosts/{hostID}/host_components/{hostComponentID} - * Create a specific host_component. - * - * @param body http body - * @param headers http headers - * @param ui uri info - * @param hostComponentName host_component id - * - * @return host_component resource representation - */ - @POST @ApiIgnore // until documented - @Path("{hostComponentName}") - @Produces("text/plain") - public Response createHostComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("hostComponentName") String hostComponentName) { - - return handleRequest(headers, body, ui, Request.Type.POST, - createHostComponentResource(m_clusterName, m_hostName, hostComponentName)); - } - /** * Handles PUT /clusters/{clusterID}/hosts/{hostID}/host_components/{hostComponentID} * Updates a specific host_component. @@ -165,18 +210,33 @@ public Response createHostComponent(String body, @Context HttpHeaders headers, @ * @param body http body * @param headers http headers * @param ui uri info - * @param hostComponentName host_component id + * @param hostComponentId host_component id * * @return information regarding updated host_component */ - @PUT @ApiIgnore // until documented - @Path("{hostComponentName}") - @Produces("text/plain") + @PUT + @Path("{hostComponentId}") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Updates a given Host Component", + nickname = "HostComponentService#updateHostComponent" + ) + @ApiImplicitParams({ + @ApiImplicitParam(dataType = HOST_COMPONENT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response updateHostComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("hostComponentName") String hostComponentName) { + @PathParam("hostComponentId") String hostComponentId) { return handleRequest(headers, body, ui, Request.Type.PUT, - createHostComponentResource(m_clusterName, m_hostName, hostComponentName)); + createHostComponentResource(m_clusterName, m_hostName, hostComponentId)); } /** @@ -189,8 +249,23 @@ public Response updateHostComponent(String body, @Context HttpHeaders headers, @ * * @return information regarding updated host_component resources */ - @PUT @ApiIgnore // until documented - @Produces("text/plain") + @PUT + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Updates multiple Host Components", + nickname = "HostComponentService#updateHostComponents" + ) + @ApiImplicitParams({ + @ApiImplicitParam(dataType = HOST_COMPONENT_REQUEST_TYPE, paramType = PARAM_TYPE_BODY) + }) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_ACCEPTED, message = MSG_REQUEST_ACCEPTED), + @ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response updateHostComponents(String body, @Context HttpHeaders headers, @Context UriInfo ui) { return handleRequest(headers, body, ui, Request.Type.PUT, @@ -203,18 +278,28 @@ public Response updateHostComponents(String body, @Context HttpHeaders headers, * * @param headers http headers * @param ui uri info - * @param hostComponentName host_component id + * @param hostComponentId host_component id * * @return host_component resource representation */ @DELETE @ApiIgnore // until documented - @Path("{hostComponentName}") - @Produces("text/plain") + @Path("{hostComponentId}") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Deletes a hostComponent", + nickname = "HostComponentService#deleteHostComponent" + ) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response deleteHostComponent(@Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("hostComponentName") String hostComponentName) { + @PathParam("hostComponentId") String hostComponentId) { return handleRequest(headers, null, ui, Request.Type.DELETE, - createHostComponentResource(m_clusterName, m_hostName, hostComponentName)); + createHostComponentResource(m_clusterName, m_hostName, hostComponentId)); } /** @@ -227,22 +312,45 @@ public Response deleteHostComponent(@Context HttpHeaders headers, @Context UriIn * @return host_component resource representation */ @DELETE @ApiIgnore // until documented - @Produces("text/plain") + @Produces(MediaType.TEXT_PLAIN) + @ApiOperation(value = "Deletes multiple hostComponents", + nickname = "HostComponentService#deleteHostComponents" + ) + @ApiResponses({ + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_UNAUTHORIZED, message = MSG_NOT_AUTHENTICATED), + @ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR), + }) public Response deleteHostComponents(String body, @Context HttpHeaders headers, @Context UriInfo ui) { return handleRequest(headers, body, ui, Request.Type.DELETE, createHostComponentResource(m_clusterName, m_hostName, null)); } - @GET @ApiIgnore // until documented - @Path("{hostComponentName}/processes") - @Produces("text/plain") + @GET + @Produces(MediaType.TEXT_PLAIN) + @Path("{hostComponentId}/processes") + @ApiOperation(value = "Get details of processes.", + nickname = "HostComponentService#getProcesses", + notes = "Returns the details of a host component processes.", + responseContainer = RESPONSE_CONTAINER_LIST) + @ApiImplicitParams({ + @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, defaultValue = "HostRoles/*", + dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY) + }) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.SC_OK, message = MSG_SUCCESSFUL_OPERATION), + @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = MSG_RESOURCE_NOT_FOUND), + @ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR) + }) public Response getProcesses(@Context HttpHeaders headers, @Context UriInfo ui, - @PathParam("hostComponentName") String hostComponentName) { + @PathParam("hostComponentId") String hostComponentId) { Map mapIds = new HashMap<>(); mapIds.put(Resource.Type.Cluster, m_clusterName); mapIds.put(Resource.Type.Host, m_hostName); - mapIds.put(Resource.Type.HostComponent, hostComponentName); + mapIds.put(Resource.Type.HostComponent, hostComponentId); ResourceInstance ri = createResource(Resource.Type.HostComponentProcess, mapIds); @@ -254,25 +362,25 @@ public Response getProcesses(@Context HttpHeaders headers, @Context UriInfo ui, * * @param clusterName cluster name * @param hostName host name - * @param hostComponentName host_component name + * @param hostComponentId host_component id * * @return a host resource instance */ - ResourceInstance createHostComponentResource(String clusterName, String hostName, String hostComponentName) { + ResourceInstance createHostComponentResource(String clusterName, String hostName, String hostComponentId) { Map mapIds = new HashMap<>(); mapIds.put(Resource.Type.Cluster, clusterName); mapIds.put(Resource.Type.Host, hostName); - mapIds.put(Resource.Type.HostComponent, hostComponentName); + mapIds.put(Resource.Type.HostComponent, hostComponentId); return createResource(Resource.Type.HostComponent, mapIds); } private Response createClientConfigResource(String body, HttpHeaders headers, UriInfo ui, - String hostComponentName) { + String hostComponentId) { Map mapIds = new HashMap<>(); mapIds.put(Resource.Type.Cluster, m_clusterName); mapIds.put(Resource.Type.Host, m_hostName); - mapIds.put(Resource.Type.Component, hostComponentName); + mapIds.put(Resource.Type.Component, hostComponentId); Response response = handleRequest(headers, body, ui, Request.Type.GET, createResource(Resource.Type.ClientConfig, mapIds)); @@ -284,10 +392,10 @@ private Response createClientConfigResource(String body, HttpHeaders headers, Ur String filePrefixName; - if (StringUtils.isEmpty(hostComponentName)) { + if (StringUtils.isEmpty(hostComponentId)) { filePrefixName = m_hostName + "(" + Resource.InternalType.Host.toString().toUpperCase()+")"; } else { - filePrefixName = hostComponentName; + filePrefixName = hostComponentId; } Validate.notNull(filePrefixName, "compressed config file name should not be null"); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/RootClusterSettingService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/RootClusterSettingService.java index d8a37853791..bcc5343a97d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/RootClusterSettingService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/RootClusterSettingService.java @@ -33,7 +33,6 @@ import org.apache.ambari.server.api.resources.ResourceInstance; import org.apache.ambari.server.controller.ReadOnlyConfigurationResponse; -import org.apache.ambari.server.controller.internal.MpackResourceProvider; import org.apache.ambari.server.controller.internal.RootClusterSettingsResourceProvider; import org.apache.ambari.server.controller.spi.Resource; import org.apache.http.HttpStatus; @@ -69,8 +68,6 @@ public RootClusterSettingService() { @ApiOperation(value = "Returns information for all the read only 'cluster settings'", response = ReadOnlyConfigurationResponse.ReadOnlyConfigurationResponseSwagger.class, responseContainer = RESPONSE_CONTAINER_LIST) @ApiImplicitParams({ - @ApiImplicitParam(name = QUERY_FIELDS, value = QUERY_FILTER_DESCRIPTION, dataType = DATA_TYPE_STRING, - paramType = PARAM_TYPE_QUERY, defaultValue = MpackResourceProvider.MPACK_RESOURCE_ID), @ApiImplicitParam(name = QUERY_SORT, value = QUERY_SORT_DESCRIPTION, dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_QUERY), @ApiImplicitParam(name = QUERY_PAGE_SIZE, value = QUERY_PAGE_SIZE_DESCRIPTION, defaultValue = DEFAULT_PAGE_SIZE, diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java index 016648da395..0e5fb727911 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java @@ -509,6 +509,19 @@ RequestStatusResponse createAction(ExecuteActionRequest actionRequest, Map createHostComponents(Set createHostComponents(Set getHostComponents( } if (StringUtils.isBlank(serviceName)) { - LOG.error("Unable to find service for component {}", request.getComponentName()); + LOG.error("Unable to find service for componentName : {}", request.getComponentName()); throw new ServiceComponentHostNotFoundException( cluster.getClusterName(), null, request.getComponentName(), request.getHostname()); } @@ -1310,6 +1333,31 @@ private Set getHostComponents( Map desiredConfigs = cluster.getDesiredConfigs(); Map hosts = clusters.getHostsForCluster(cluster.getClusterName()); + /* + This is a core step in retrieving a given component instance in multi-host component instances world. + We fetch the 'HostComponentStateEntity' based on the 'host component Id' passed-in in the request. if it exists, + we use the service group Id, service Id, componentName and componentType to query the unique ServiceComponentEntity + associated with it. + */ + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = null; + HostComponentStateEntity hostComponentStateEntity = null; + if (request.getComponentId() != null) { + hostComponentStateEntity = hostComponentStateDAO.findById(request.getComponentId()); + if (hostComponentStateEntity == null) { + throw new AmbariException("Could not find Host Component resource for" + + " componentId = "+ request.getComponentId()); + } + serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(hostComponentStateEntity.getClusterId(), + hostComponentStateEntity.getServiceGroupId(), hostComponentStateEntity.getServiceId(), + hostComponentStateEntity.getComponentName(), hostComponentStateEntity.getComponentType()); + if (serviceComponentDesiredStateEntity == null) { + throw new AmbariException("Could not find Service Component resource for" + + " componentId = " + request.getComponentId() + ", serviceGroupId = " + hostComponentStateEntity.getServiceGroupId() + + ", serviceId = " + hostComponentStateEntity.getServiceId() + ", componentName = " + hostComponentStateEntity.getComponentName() + + ", componntType = " + hostComponentStateEntity.getComponentType()); + } + } + for (Service s : services) { // filter on component name if provided Set components = new HashSet<>(); @@ -1318,9 +1366,12 @@ private Set getHostComponents( } else { components.addAll(s.getServiceComponents().values()); } + for (ServiceComponent sc : components) { - if (request.getComponentName() != null) { - if (!sc.getName().equals(request.getComponentName())) { + if (serviceComponentDesiredStateEntity != null && + serviceComponentDesiredStateEntity.getId() != null && + sc.getId() != null) { + if (!sc.getId().equals(serviceComponentDesiredStateEntity.getId())) { continue; } } @@ -1380,7 +1431,7 @@ private Set getHostComponents( response.add(r); } catch (ServiceComponentHostNotFoundException e) { - if (request.getServiceName() == null || request.getComponentName() == null) { + if (request.getServiceName() == null || request.getComponentId() == null) { // Ignore the exception if either the service name or component name are not specified. // This is an artifact of how we get host_components and can happen in the case where // we get all host_components for a host, for example. @@ -1392,7 +1443,7 @@ private Set getHostComponents( // condition. LOG.debug("ServiceComponentHost not found ", e); throw new ServiceComponentHostNotFoundException(cluster.getClusterName(), - request.getServiceName(), request.getComponentName(), request.getHostname()); + request.getServiceName(), request.getComponentId(), request.getHostname()); } } } else { @@ -3512,10 +3563,14 @@ public void validateServiceComponentHostRequest(ServiceComponentHostRequest requ || request.getClusterName().isEmpty() || request.getComponentName() == null || request.getComponentName().isEmpty() + || request.getServiceName() == null + || request.getServiceName().isEmpty() + || request.getServiceGroupName() == null + || request.getServiceGroupName().isEmpty() || request.getHostname() == null || request.getHostname().isEmpty()) { throw new IllegalArgumentException("Invalid arguments" - + ", cluster name, component name and host name should be" + + ", cluster name, component name, service name, service group name and host name should be" + " provided"); } @@ -3545,6 +3600,11 @@ public String findService(Cluster cluster, String componentName) throws AmbariEx return cluster.getServiceByComponentName(componentName).getName(); } + @Override + public String findService(Cluster cluster, Long componentId) throws AmbariException { + return cluster.getServiceByComponentId(componentId).getName(); + } + @Override public synchronized void deleteCluster(ClusterRequest request) throws AmbariException { @@ -3585,8 +3645,8 @@ public DeleteStatusMetaData deleteHostComponents( for (ServiceComponentHost sch : cluster.getServiceComponentHosts(request.getHostname())) { ServiceComponentHostRequest schr = new ServiceComponentHostRequest(request.getClusterName(), - request.getServiceGroupName(), sch.getServiceName(), sch.getServiceComponentName(), - sch.getHostName(), null); + sch.getServiceGroupName(), sch.getServiceName(), sch.getServiceComponentId(), sch.getServiceComponentName(), + sch.getServiceComponentType(), sch.getHostName(), null); expanded.add(schr); } } @@ -3612,6 +3672,7 @@ public DeleteStatusMetaData deleteHostComponents( + ", clusterName=" + request.getClusterName() + ", serviceName=" + request.getServiceName() + ", componentName=" + request.getComponentName() + + ", componentType=" + request.getComponentType() + ", hostname=" + request.getHostname() + ", request=" + request); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java index 0824d5361cf..f9d5c5701fa 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java @@ -26,7 +26,9 @@ public class ServiceComponentHostRequest { private String clusterName; // REF private String serviceGroupName; private String serviceName; + private Long componentId; private String componentName; + private String componentType; private String hostname; private String publicHostname; private String state; @@ -39,17 +41,31 @@ public class ServiceComponentHostRequest { public ServiceComponentHostRequest(String clusterName, String serviceGroupName, String serviceName, + Long componentId, String componentName, + String componentType, String hostname, String desiredState) { this.clusterName = clusterName; this.serviceGroupName = serviceGroupName; this.serviceName = serviceName; + this.componentId = componentId; this.componentName = componentName; + this.componentType = componentType; this.hostname = hostname; this.desiredState = desiredState; } + public ServiceComponentHostRequest(String clusterName, + String serviceGroupName, + String serviceName, + String componentName, + String componentType, + String hostname, + String desiredState) { + this(clusterName, serviceGroupName, serviceName, null, componentName, componentType, hostname, desiredState); + } + /** * @return the service group Name */ @@ -74,6 +90,13 @@ public void setServiceName(String serviceName) { this.serviceName = serviceName; } + /** + * @return the componentd + */ + public Long getComponentId() { + return componentId; + } + /** * @return the componentName */ @@ -88,6 +111,22 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + /** + * @param componentId the componentId to set + */ + public void setComponentId(Long componentId) { + this.componentId = componentId; + } + + /** + * @return the componentType + */ + public String getComponentType() { return componentType; } + + /** + * @param componentType the componenType to set + */ + public void setComponentType(String componentType) { this.componentType = componentType; } /** * @return the hostname */ @@ -162,7 +201,9 @@ public String toString() { sb.append("{" + " clusterName=").append(clusterName) .append(", serviceGroupName=").append(serviceGroupName) .append(", serviceName=").append(serviceName) + .append(", componentId=").append(componentId) .append(", componentName=").append(componentName) + .append(", componentType=").append(componentType) .append(", hostname=").append(hostname) .append(", publicHostname=").append(publicHostname) .append(", desiredState=").append(desiredState) @@ -203,7 +244,9 @@ public boolean equals(Object obj) { return Objects.equals(clusterName, other.clusterName) && Objects.equals(serviceGroupName, other.serviceGroupName) && Objects.equals(serviceName, other.serviceName) && + Objects.equals(componentId, other.componentId) && Objects.equals(componentName, other.componentName) && + Objects.equals(componentType, other.componentType) && Objects.equals(hostname, other.hostname) && Objects.equals(publicHostname, other.publicHostname) && Objects.equals(desiredState, other.desiredState) && @@ -216,7 +259,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(clusterName, serviceGroupName, serviceName, componentName, hostname, publicHostname, - desiredState, state, desiredStackId, staleConfig, adminState, maintenanceState); + return Objects.hash(clusterName, serviceGroupName, serviceName, componentId, componentName, componentType, hostname, + publicHostname, desiredState, state, desiredStackId, staleConfig, adminState, maintenanceState); } } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java index 14f1d471130..76d187dfc4e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java @@ -24,6 +24,8 @@ import org.apache.ambari.server.state.HostConfig; import org.apache.ambari.server.state.UpgradeState; +import io.swagger.annotations.ApiModelProperty; + public class ServiceComponentHostResponse { private Long clusterId; // REF @@ -35,6 +37,7 @@ public class ServiceComponentHostResponse { private String serviceType; private Long hostComponentId; private String componentName; + private String componentType; private String displayName; private String publicHostname; private String hostname; @@ -53,9 +56,10 @@ public class ServiceComponentHostResponse { public ServiceComponentHostResponse(Long clusterId, String clusterName, Long serviceGroupId, String serviceGroupName, Long serviceId, String serviceName, String serviceType, Long hostComponentId, - String componentName, String displayName, String hostname, String publicHostname, - String liveState, String version, String desiredState, String desiredStackVersion, - String desiredRepositoryVersion, HostComponentAdminState adminState) { + String componentName, String componentType, String displayName, String hostname, + String publicHostname, String liveState, String version, String desiredState, + String desiredStackVersion, String desiredRepositoryVersion, + HostComponentAdminState adminState) { this.clusterId = clusterId; this.serviceGroupId = serviceGroupId; this.serviceGroupName = serviceGroupName; @@ -65,6 +69,7 @@ public ServiceComponentHostResponse(Long clusterId, String clusterName, Long ser this.serviceType = serviceType; this.hostComponentId = hostComponentId; this.componentName = componentName; + this.componentType = componentType; this.displayName = displayName; this.hostname = hostname; this.publicHostname = publicHostname; @@ -149,6 +154,13 @@ public String getComponentName() { return componentName; } + /** + * @return the componentType + */ + public String getComponentType() { + return componentType; + } + /** * @param componentName the componentName to set */ @@ -156,6 +168,13 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + /** + * @param componentType the componentType to set + */ + public void setComponentType(String componentType) { + this.componentType = componentType; + } + /** * @return the displayName */ @@ -339,6 +358,11 @@ public boolean equals(Object o) { return false; } + if (componentType != null ? + !componentType.equals(that.componentType) : that.componentType != null) { + return false; + } + if (displayName != null ? !displayName.equals(that.displayName) : that.displayName != null) { return false; @@ -362,6 +386,7 @@ public int hashCode() { result = 71 * result + (serviceName != null ? serviceName.hashCode() : 0); result = 71 * result + (serviceType != null ? serviceType.hashCode() : 0); result = 71 * result + (componentName != null ? componentName.hashCode() : 0); + result = 71 * result + (componentType != null ? componentType.hashCode() : 0); result = 71 * result + (displayName != null ? displayName.hashCode() : 0); result = 71 * result + (hostname != null ? hostname.hashCode() : 0); return result; @@ -437,4 +462,13 @@ public UpgradeState getUpgradeState() { return upgradeState; } + /** + * Interface to help correct Swagger documentation generation + */ + public interface ServiceComponentHostResponseSwagger extends ApiModel { + @ApiModelProperty(name = "HostRoles") + ServiceComponentHostResponse getServiceComponentHostResponse(); + } + + } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java index 0c73933c753..12fa03c26a0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java @@ -27,28 +27,30 @@ public class ServiceComponentRequest { private String serviceGroupName; private String serviceName; // GET/CREATE/UPDATE/DELETE private String componentName; // GET/CREATE/UPDATE/DELETE + private String componentType; private String desiredState; // CREATE/UPDATE private String componentCategory; private String recoveryEnabled; // CREATE/UPDATE public ServiceComponentRequest(String clusterName, String serviceGroupName, String serviceName, - String componentName, String desiredState) { - this(clusterName, serviceGroupName, serviceName, componentName, desiredState, null, null); + String componentName, String componentType, String desiredState) { + this(clusterName, serviceGroupName, serviceName, componentName, componentType, desiredState, null, null); } public ServiceComponentRequest(String clusterName, String serviceGroupName, String serviceName, String componentName, - String desiredState, String recoveryEnabled) { - this(clusterName, serviceGroupName, serviceName, componentName, desiredState, recoveryEnabled, null); + String componentType, String desiredState, String recoveryEnabled) { + this(clusterName, serviceGroupName, serviceName, componentName, componentType, desiredState, recoveryEnabled, null); } public ServiceComponentRequest(String clusterName, String serviceGroupName, - String serviceName, String componentName, + String serviceName, String componentName, String componentType, String desiredState, String recoveryEnabled, String componentCategory) { this.clusterName = clusterName; this.serviceGroupName = serviceGroupName; this.serviceName = serviceName; this.componentName = componentName; + this.componentType = componentType; this.desiredState = desiredState; this.recoveryEnabled = recoveryEnabled; this.componentCategory = componentCategory; @@ -91,6 +93,18 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + /** + * @return the componentType + */ + public String getComponentType() { return componentType; } + + /** + * @param componentType the componentType to set + */ + public void setComponentType(String componentType) { + this.componentType = componentType; + } + /** * @return the desiredState */ @@ -143,9 +157,9 @@ public void setComponentCategory(String componentCategory) { @Override public String toString() { - return String.format("[clusterName=%s, serviceGroupName=%s, serviceName=%s, componentName=%s, " + + return String.format("[clusterName=%s, serviceGroupName=%s, serviceName=%s, componentName=%s, componentType=%s, " + "desiredState=%s, recoveryEnabled=%s, componentCategory=%s]", clusterName, serviceGroupName, - serviceName, clusterName, desiredState, recoveryEnabled, componentCategory); + serviceName, componentName, componentType, desiredState, recoveryEnabled, componentCategory); } @Override diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentResponse.java index d63b33c1ef0..85dc55f33be 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentResponse.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentResponse.java @@ -33,7 +33,9 @@ public class ServiceComponentResponse { private Long serviceId; // REF private String serviceName; private String serviceType; + private Long componentId; private String componentName; + private String componentType; private String displayName; private String desiredStackId; private String desiredState; @@ -44,10 +46,10 @@ public class ServiceComponentResponse { private RepositoryVersionState repoState; public ServiceComponentResponse(Long clusterId, String clusterName, Long serviceGroupId, String serviceGroupName, - Long serviceId, String serviceName, String serviceType, String componentName, - StackId desiredStackId, String desiredState, Map serviceComponentStateCount, - boolean recoveryEnabled, String displayName, String desiredVersion, - RepositoryVersionState repoState) { + Long serviceId, String serviceName, String serviceType, Long componentId, String componentName, + String componentType, StackId desiredStackId, String desiredState, + Map serviceComponentStateCount, boolean recoveryEnabled, + String displayName, String desiredVersion, RepositoryVersionState repoState) { this.clusterId = clusterId; this.clusterName = clusterName; this.serviceGroupId = serviceGroupId; @@ -55,7 +57,9 @@ public ServiceComponentResponse(Long clusterId, String clusterName, Long service this.serviceId = serviceId; this.serviceName = serviceName; this.serviceType = serviceType; + this.componentId = componentId; this.componentName = componentName; + this.componentType = componentType; this.displayName = displayName; this.desiredStackId = desiredStackId.getStackId(); this.desiredState = desiredState; @@ -133,6 +137,34 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + /** + * @param componentId the componentId to set + */ + public void setComponentName(Long componentId) { + this.componentId = componentId; + } + + /** + * @return the componentType + */ + public String getComponentType() { + return componentType; + } + + /** + * @param componentType the componentType to set + */ + public void setComponentType(String componentType) { + this.componentType = componentType; + } + + /** + * @return the componentId + */ + public Long getComponentId() { + return componentId; + } + /** * @return the displayName */ @@ -293,11 +325,21 @@ public boolean equals(Object o) { return false; } + if (componentId != null ? + !componentId.equals(that.componentId) : that.componentId != null) { + return false; + } + if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null){ return false; } + if (componentType != null ? + !componentType.equals(that.componentType) : that.componentType != null){ + return false; + } + if (displayName != null ? !displayName.equals(that.displayName) : that.displayName != null) { return false; @@ -315,7 +357,9 @@ public int hashCode() { result = 71 * result + (serviceId != null ? serviceId.hashCode() : 0); result = 71 * result + (serviceName != null ? serviceName.hashCode() : 0); result = 71 * result + (serviceType != null ? serviceType.hashCode() : 0); + result = 71 * result + (componentId != null ? componentId.hashCode() : 0); result = 71 * result + (componentName != null ? componentName.hashCode():0); + result = 71 * result + (componentType != null ? componentType.hashCode():0); result = 71 * result + (displayName != null ? displayName.hashCode():0); return result; } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java index f385f7ef3fa..b30cd333ee8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractProviderModule.java @@ -505,10 +505,17 @@ public Host getHost(String clusterName, String hostName) { public boolean isCollectorComponentLive(String clusterName, MetricsService service) throws SystemException { final String collectorHostName = getCollectorHostName(clusterName, service); + Long componentId = null; + try { + componentId = managementController.getClusters().getCluster(clusterName).getComponentId(Role.METRICS_COLLECTOR.name()); + } catch (AmbariException e) { + e.printStackTrace(); + } if (service.equals(GANGLIA)) { + // TODO : Multi_Metrics_Changes. Is there is more than one instance of GANGLIA_SERVER, type and name would be different. return HostStatusHelper.isHostComponentLive(managementController, clusterName, collectorHostName, "GANGLIA", - Role.GANGLIA_SERVER.name()); + componentId, Role.GANGLIA_SERVER.name(), Role.GANGLIA_SERVER.name()); } else if (service.equals(TIMELINE_METRICS)) { return metricsCollectorHAManager.isCollectorComponentLive(clusterName); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java index 6de2bfa89c2..4344c2caf52 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java @@ -119,7 +119,9 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv protected static final String COMPONENT_CLUSTER_NAME_PROPERTY_ID = "ServiceComponentInfo/cluster_name"; protected static final String COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID = "ServiceComponentInfo/service_group_name"; protected static final String COMPONENT_SERVICE_NAME_PROPERTY_ID = "ServiceComponentInfo/service_name"; + protected static final String COMPONENT_COMPONENT_ID_PROPERTY_ID = "ServiceComponentInfo/id"; protected static final String COMPONENT_COMPONENT_NAME_PROPERTY_ID = "ServiceComponentInfo/component_name"; + protected static final String COMPONENT_COMPONENT_TYPE_PROPERTY_ID = "ServiceComponentInfo/component_type"; protected static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID = PropertyHelper.getPropertyId("HostRoles", "host_name"); @@ -141,6 +143,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv private static Set propertyIds = Sets.newHashSet( COMPONENT_CLUSTER_NAME_PROPERTY_ID, COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID, + COMPONENT_COMPONENT_ID_PROPERTY_ID, COMPONENT_SERVICE_NAME_PROPERTY_ID, COMPONENT_COMPONENT_NAME_PROPERTY_ID, HOST_COMPONENT_HOST_NAME_PROPERTY_ID); @@ -913,7 +916,9 @@ private ServiceComponentHostRequest getRequest(Map properties) { (String) properties.get(COMPONENT_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID), (String) properties.get(COMPONENT_SERVICE_NAME_PROPERTY_ID), + (Long) properties.get(COMPONENT_COMPONENT_ID_PROPERTY_ID), (String) properties.get(COMPONENT_COMPONENT_NAME_PROPERTY_ID), + (String) properties.get(COMPONENT_COMPONENT_TYPE_PROPERTY_ID), (String) properties.get(HOST_COMPONENT_HOST_NAME_PROPERTY_ID), null); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java index e679e50dbb9..dbe6e70cc4c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java @@ -94,7 +94,9 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide protected static final String COMPONENT_SERVICE_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_id"; protected static final String COMPONENT_SERVICE_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_name"; protected static final String COMPONENT_SERVICE_TYPE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_type"; + protected static final String COMPONENT_COMPONENT_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "id"; protected static final String COMPONENT_COMPONENT_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "component_name"; + protected static final String COMPONENT_COMPONENT_TYPE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "component_type"; protected static final String COMPONENT_DISPLAY_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "display_name"; protected static final String COMPONENT_STATE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "state"; protected static final String COMPONENT_CATEGORY_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "category"; @@ -120,7 +122,9 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide COMPONENT_CLUSTER_NAME_PROPERTY_ID, COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID, COMPONENT_SERVICE_NAME_PROPERTY_ID, - COMPONENT_COMPONENT_NAME_PROPERTY_ID); + COMPONENT_COMPONENT_ID_PROPERTY_ID, + COMPONENT_COMPONENT_NAME_PROPERTY_ID, + COMPONENT_COMPONENT_TYPE_PROPERTY_ID); /** * The property ids for an servce resource. @@ -141,7 +145,9 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide PROPERTY_IDS.add(COMPONENT_SERVICE_ID_PROPERTY_ID); PROPERTY_IDS.add(COMPONENT_SERVICE_NAME_PROPERTY_ID); PROPERTY_IDS.add(COMPONENT_SERVICE_TYPE_PROPERTY_ID); + PROPERTY_IDS.add(COMPONENT_COMPONENT_ID_PROPERTY_ID); PROPERTY_IDS.add(COMPONENT_COMPONENT_NAME_PROPERTY_ID); + PROPERTY_IDS.add(COMPONENT_COMPONENT_TYPE_PROPERTY_ID); PROPERTY_IDS.add(COMPONENT_DISPLAY_NAME_PROPERTY_ID); PROPERTY_IDS.add(COMPONENT_STATE_PROPERTY_ID); PROPERTY_IDS.add(COMPONENT_CATEGORY_PROPERTY_ID); @@ -223,7 +229,9 @@ public Set invoke() throws AmbariException, Authorizat resource.setProperty(COMPONENT_SERVICE_ID_PROPERTY_ID, response.getServiceId()); resource.setProperty(COMPONENT_SERVICE_NAME_PROPERTY_ID, response.getServiceName()); resource.setProperty(COMPONENT_SERVICE_TYPE_PROPERTY_ID, response.getServiceType()); + resource.setProperty(COMPONENT_COMPONENT_ID_PROPERTY_ID, response.getComponentId()); resource.setProperty(COMPONENT_COMPONENT_NAME_PROPERTY_ID, response.getComponentName()); + resource.setProperty(COMPONENT_COMPONENT_TYPE_PROPERTY_ID, response.getComponentType()); resource.setProperty(COMPONENT_DISPLAY_NAME_PROPERTY_ID, response.getDisplayName()); resource.setProperty(COMPONENT_STATE_PROPERTY_ID, response.getDesiredState()); resource.setProperty(COMPONENT_CATEGORY_PROPERTY_ID, response.getCategory()); @@ -270,7 +278,9 @@ public Set invoke() throws AmbariException { setResourceProperty(resource, COMPONENT_SERVICE_ID_PROPERTY_ID, response.getServiceId(), requestedIds); setResourceProperty(resource, COMPONENT_SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, COMPONENT_SERVICE_TYPE_PROPERTY_ID, response.getServiceType(), requestedIds); + setResourceProperty(resource, COMPONENT_COMPONENT_ID_PROPERTY_ID, response.getComponentId(), requestedIds); setResourceProperty(resource, COMPONENT_COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); + setResourceProperty(resource, COMPONENT_COMPONENT_TYPE_PROPERTY_ID, response.getComponentType(), requestedIds); setResourceProperty(resource, COMPONENT_DISPLAY_NAME_PROPERTY_ID, response.getDisplayName(), requestedIds); setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID, response.getDesiredState(), requestedIds); setResourceProperty(resource, COMPONENT_CATEGORY_PROPERTY_ID, response.getCategory(), requestedIds); @@ -363,6 +373,7 @@ private ServiceComponentRequest getRequest(Map properties) { (String) properties.get(COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID), (String) properties.get(COMPONENT_SERVICE_NAME_PROPERTY_ID), (String) properties.get(COMPONENT_COMPONENT_NAME_PROPERTY_ID), + (String) properties.get(COMPONENT_COMPONENT_TYPE_PROPERTY_ID), (String) properties.get(COMPONENT_STATE_PROPERTY_ID), (String) properties.get(COMPONENT_RECOVERY_ENABLED_ID), (String) properties.get(COMPONENT_CATEGORY_PROPERTY_ID)); @@ -392,6 +403,13 @@ public Set createComponents(Set createComponents(Set createComponents(Set re final String serviceGroupName = request.getServiceGroupName(); final String serviceName = request.getServiceName(); final String componentName = request.getComponentName(); + final String componentType = request.getComponentType(); LOG.info("Received a updateComponent request: {}", request); @@ -659,7 +678,7 @@ protected RequestStatusResponse updateComponents(Set re State newState = getValidDesiredState(request); if (! maintenanceStateHelper.isOperationAllowed(reqOpLvl, s)) { - LOG.info("Operations cannot be applied to component " + componentName + LOG.info("Operations cannot be applied to component name : " + componentName + " with type : " + componentType + " because service " + serviceName + " is in the maintenance state of " + s.getMaintenanceState()); continue; @@ -674,8 +693,8 @@ protected RequestStatusResponse updateComponents(Set re boolean newRecoveryEnabled = Boolean.parseBoolean(request.getRecoveryEnabled()); boolean oldRecoveryEnabled = sc.isRecoveryEnabled(); - LOG.info("Component: {}, oldRecoveryEnabled: {}, newRecoveryEnabled {}", - componentName, oldRecoveryEnabled, newRecoveryEnabled); + LOG.info("ComponentName: {}, componentType: {}, oldRecoveryEnabled: {}, newRecoveryEnabled {}", + componentName, componentType, oldRecoveryEnabled, newRecoveryEnabled); if (newRecoveryEnabled != oldRecoveryEnabled) { if (newRecoveryEnabled) { recoveryEnabledComponents.add(sc); @@ -712,6 +731,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + sc.getServiceName() + ", componentName=" + sc.getName() + + ", componentType=" + sc.getType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", currentDesiredState=" + oldScState + ", newDesiredState=" + newState); @@ -725,6 +745,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + serviceName + ", componentName=" + sc.getName() + + ", componentType=" + sc.getType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", currentDesiredState=" + oldScState + ", newDesiredState=" + newState); @@ -740,6 +761,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + serviceName + ", componentName=" + sc.getName() + + ", componentType=" + sc.getType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", hostname=" + sch.getHostName() + ", currentState=" + oldSchState @@ -754,6 +776,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + serviceName + ", componentName=" + sc.getName() + + ", componentType=" + sc.getType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", hostname=" + sch.getHostName() + ", currentState=" + oldSchState @@ -769,6 +792,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + serviceName + ", componentName=" + sc.getName() + + ", componentType=" + sc.getType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", hostname=" + sch.getHostName()); @@ -784,6 +808,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + sch.getServiceName() + ", componentName=" + sch.getServiceComponentName() + + ", componentType=" + sch.getServiceComponentType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", hostname=" + sch.getHostName() + ", currentState=" + oldSchState @@ -801,6 +826,7 @@ protected RequestStatusResponse updateComponents(Set re + ", serviceGroupName=" + serviceGroupName + ", serviceName=" + serviceName + ", componentName=" + sc.getName() + + ", componentType=" + sc.getType() + ", recoveryEnabled=" + sc.isRecoveryEnabled() + ", hostname=" + sch.getHostName() + ", currentState=" + oldSchState @@ -914,14 +940,16 @@ private void setServiceNameIfAbsent(final ServiceComponentRequest request, if (StringUtils.isEmpty(request.getServiceName())) { String componentName = request.getComponentName(); + String componentType = request.getComponentType(); - String serviceName = getManagementController().findService(cluster, componentName); + String serviceName = getManagementController().findService(cluster, componentType); - debug("Looking up service name for component, componentName={}, serviceName={}", componentName, serviceName); + debug("Looking up service name for component, componentType={}, serviceName={}", componentType, serviceName); if (StringUtils.isEmpty(serviceName)) { - throw new AmbariException("Could not find service for component" - + ", componentName=" + request.getComponentName() + throw new AmbariException("Could not find service for component." + + " componentName=" + request.getComponentName() + + " componentType=" + request.getComponentType() + ", clusterName=" + cluster.getClusterName()); } request.setServiceName(serviceName); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java index 8facd21d270..9b0f69bff6e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java @@ -97,6 +97,7 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro public static final String HOST_COMPONENT_SERVICE_TYPE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "service_type"; public static final String HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "id"; public static final String HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "component_name"; + public static final String HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "component_type"; public static final String HOST_COMPONENT_DISPLAY_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "display_name"; public static final String HOST_COMPONENT_HOST_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "host_name"; public static final String HOST_COMPONENT_PUBLIC_HOST_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "public_host_name"; @@ -123,8 +124,10 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro public static Map keyPropertyIds = ImmutableMap.builder() .put(Resource.Type.Cluster, HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID) .put(Resource.Type.Host, HOST_COMPONENT_HOST_NAME_PROPERTY_ID) - .put(Resource.Type.HostComponent, HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID) + .put(Resource.Type.HostComponent, HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID) .put(Resource.Type.Component, HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID) + .put(Resource.Type.Service, HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID) + .put(Resource.Type.ServiceGroup, HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID) .build(); /** @@ -135,7 +138,9 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID, HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID, HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID, + HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID, HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, + HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID, HOST_COMPONENT_DISPLAY_NAME_PROPERTY_ID, HOST_COMPONENT_HOST_NAME_PROPERTY_ID, HOST_COMPONENT_PUBLIC_HOST_NAME_PROPERTY_ID, @@ -215,6 +220,7 @@ public Set invoke() throws AmbariException, Author resource.setProperty(HOST_COMPONENT_SERVICE_TYPE_PROPERTY_ID, response.getServiceType()); resource.setProperty(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID, response.getHostComponentId()); resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, response.getComponentName()); + resource.setProperty(HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID, response.getComponentType()); resource.setProperty(HOST_COMPONENT_DISPLAY_NAME_PROPERTY_ID, response.getDisplayName()); resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, response.getHostname()); resource.setProperty(HOST_COMPONENT_PUBLIC_HOST_NAME_PROPERTY_ID, response.getPublicHostname()); @@ -287,6 +293,7 @@ public Set invoke() throws AmbariException { setResourceProperty(resource, HOST_COMPONENT_SERVICE_TYPE_PROPERTY_ID, response.getServiceType(), requestedIds); setResourceProperty(resource, HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID, response.getHostComponentId(), requestedIds); setResourceProperty(resource, HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); + setResourceProperty(resource, HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID, response.getComponentType(), requestedIds); setResourceProperty(resource, HOST_COMPONENT_DISPLAY_NAME_PROPERTY_ID, response.getDisplayName(), requestedIds); setResourceProperty(resource, HOST_COMPONENT_HOST_NAME_PROPERTY_ID, response.getHostname(), requestedIds); setResourceProperty(resource, HOST_COMPONENT_PUBLIC_HOST_NAME_PROPERTY_ID, response.getPublicHostname(), requestedIds); @@ -357,7 +364,7 @@ public DeleteStatusMetaData invoke() throws AmbariException, AuthorizationExcept notifyDelete(Resource.Type.HostComponent, predicate); for(ServiceComponentHostRequest svcCmpntHostReq : requests) { - deleteStatusMetaData.addDeletedKey("component_name: "+svcCmpntHostReq.getComponentName()); + deleteStatusMetaData.addDeletedKey("component_id: "+svcCmpntHostReq.getComponentId()); } return getRequestStatus(null, null, deleteStatusMetaData); } @@ -677,6 +684,7 @@ protected RequestStageContainer updateHostComponents(RequestStageContainer stage + ", clusterId=" + cluster.getClusterId() + ", serviceName=" + sch.getServiceName() + ", componentName=" + sch.getServiceComponentName() + + ", componentType=" + sch.getServiceComponentType() + ", hostname=" + sch.getHostName() + ", currentState=" + oldSchState + ", newDesiredState=" + newState); @@ -722,13 +730,23 @@ protected Set getPKPropertyIds() { * @return the component request object */ private ServiceComponentHostRequest getRequest(Map properties) { - ServiceComponentHostRequest serviceComponentHostRequest = new ServiceComponentHostRequest( - (String) properties.get(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID), - (String) properties.get(HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID), - (String) properties.get(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID), - (String) properties.get(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID), - (String) properties.get(HOST_COMPONENT_HOST_NAME_PROPERTY_ID), - (String) properties.get(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)); + ServiceComponentHostRequest serviceComponentHostRequest = null; + if (properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID) != null) { + Long hostComponentId = properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID) instanceof String ? + Long.parseLong((String) properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID)) : + (Long) properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID); + + serviceComponentHostRequest = new ServiceComponentHostRequest( + (String) properties.get(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID), + (String) properties.get(HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID), + (String) properties.get(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID), + hostComponentId, + (String) properties.get(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID), + (String) properties.get(HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID), + (String) properties.get(HOST_COMPONENT_HOST_NAME_PROPERTY_ID), + (String) properties.get(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)); + } + serviceComponentHostRequest.setState((String) properties.get(HOST_COMPONENT_STATE_PROPERTY_ID)); if (properties.get(HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID) != null) { serviceComponentHostRequest.setStaleConfig( @@ -760,13 +778,23 @@ private ServiceComponentHostRequest getRequest(Map properties) { * @return the component request object */ private ServiceComponentHostRequest changeRequest(Map properties) { + Long hostComponentId = null; + if (properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID) != null) { + hostComponentId = properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID) instanceof String ? + Long.parseLong((String) properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID)) : + (Long) properties.get(HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID); + + } ServiceComponentHostRequest serviceComponentHostRequest = new ServiceComponentHostRequest( (String) properties.get(HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID), (String) properties.get(HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID), (String) properties.get(HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID), + hostComponentId, (String) properties.get(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID), + (String) properties.get(HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID), (String) properties.get(HOST_COMPONENT_HOST_NAME_PROPERTY_ID), (String) properties.get(HOST_COMPONENT_STATE_PROPERTY_ID)); + if (properties.get(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID) != null) { serviceComponentHostRequest.setDesiredState((String)properties.get(HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID)); } @@ -967,12 +995,13 @@ private void doDirectTransitions(Map directTransiti * @param request the request to log */ private void logRequestInfo(String msg, ServiceComponentHostRequest request) { - LOG.info("{}, clusterName={}, serviceGroupName={}, serviceName={}, componentName={}, hostname={}, request={}", + LOG.info("{}, clusterName={}, serviceGroupName={}, serviceName={}, componentName={}, componentType={}, hostname={}, request={}", msg, request.getClusterName(), request.getServiceGroupName(), request.getServiceName(), request.getComponentName(), + request.getComponentType(), request.getHostname(), request); } @@ -992,6 +1021,7 @@ private String getServiceComponentRequestInfoLogMessage(String msg, ServiceCompo .append(", serviceGroupName=").append(request.getServiceGroupName()) .append(", serviceName=").append(request.getServiceName()) .append(", componentName=").append(request.getComponentName()) + .append(", componentType=").append(request.getComponentType()) .append(", hostname=").append(request.getHostname()) .append(", currentState=").append(oldState == null ? "null" : oldState) .append(", newDesiredState=").append(newDesiredState == null ? "null" : newDesiredState); @@ -1031,10 +1061,14 @@ private void validateServiceComponentHostRequest(ServiceComponentHostRequest req || request.getClusterName().isEmpty() || request.getComponentName() == null || request.getComponentName().isEmpty() + || request.getServiceName() == null + || request.getServiceName().isEmpty() + || request.getServiceGroupName() == null + || request.getServiceGroupName().isEmpty() || request.getHostname() == null || request.getHostname().isEmpty()) { throw new IllegalArgumentException("Invalid arguments" - + ", cluster name, component name and host name should be" + + ", cluster name, component name, service name, service group name and host name should be" + " provided"); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java index 72b4a6a4021..20146e8c874 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java @@ -957,7 +957,9 @@ private void processDeleteHostRequests(List requests, Clusters clu ServiceComponentHostRequest schr = new ServiceComponentHostRequest(cluster.getClusterName(), sch.getServiceGroupName(), sch.getServiceName(), + sch.getHostComponentId(), sch.getServiceComponentName(), + sch.getServiceComponentType(), sch.getHostName(), null); schrs.add(schr); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java index 9c38bff8c10..2cad5f43e73 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java @@ -41,8 +41,8 @@ public class HostStatusHelper { LoggerFactory.getLogger(HostStatusHelper.class); public static boolean isHostComponentLive(AmbariManagementController managementController, - String clusterName, String hostName, - String serviceName, String componentName) { + String clusterName, String hostName, String serviceName, + Long componentId, String componentName, String componentType) { if (clusterName == null) { return false; } @@ -54,8 +54,8 @@ public static boolean isHostComponentLive(AmbariManagementController managementC Cluster cluster = clusters.getCluster(clusterName); Service s = cluster.getService(serviceName); ServiceComponentHostRequest componentRequest = - new ServiceComponentHostRequest(clusterName, s.getServiceGroupName(), serviceName, componentName, hostName, - null); + new ServiceComponentHostRequest(clusterName, s.getServiceGroupName(), serviceName, componentId, componentName, componentType, + hostName, null); Set hostComponents = managementController.getHostComponents(Collections.singleton(componentRequest)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java index 3ae0a31a55e..db31a65c437 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java @@ -668,6 +668,7 @@ protected RequestStageContainer updateServices(RequestStageContainer requestStag LOG.info("Received a updateService request" + ", clusterName=" + request.getClusterName() + + ", serviceGroupName=" + request.getServiceGroupName() + ", serviceName=" + request.getServiceName() + ", request=" + request); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java index 7e95ac2cca2..0641ccb03d2 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java @@ -166,17 +166,23 @@ public Set populateResources(Set resources, Cluster cluster = clusters.getCluster(clusterName); Service service = null; + Long componentId = null; + String componentType = null; try { - service = cluster.getServiceByComponentName(componentName); + // TODO : Multi_Metrics_Changes. Querying by component name is incorrect. We need to pass-in + // SG name and and Service name also. + componentId = cluster.getComponentId(componentName); + componentType = cluster.getComponentType(componentId); + service = cluster.getServiceByComponentId(componentId); } catch (ServiceNotFoundException e) { - LOG.debug("Could not load component {}", componentName); + LOG.debug("Could not load componentName {}", componentName); continue; } StackId stack = service.getDesiredStackId(); List defs = metaInfo.getMetrics( - stack.getStackName(), stack.getStackVersion(), service.getServiceType(), componentName, type.name()); + stack.getStackName(), stack.getStackVersion(), service.getServiceType(), componentType, type.name()); if (null == defs || 0 == defs.size()) { continue; @@ -345,6 +351,8 @@ private PropertyProvider getDelegate(MetricDefinition definition, // use a Factory for the REST provider if (clz.equals(RestMetricsPropertyProvider.class)) { + // TODO : Multi_Metrics_Changes. We need to pass UniqueComponentName like : + // {SG_instance_name}_{service_instance_name}_component_name instead of just 'componentName'. return metricPropertyProviderFactory.createRESTMetricsPropertyProvider( definition.getProperties(), componentMetrics, streamProvider, metricsHostProvider, clusterNamePropertyId, hostNamePropertyId, componentNamePropertyId, statePropertyId, @@ -359,6 +367,8 @@ private PropertyProvider getDelegate(MetricDefinition definition, Constructor ct = clz.getConstructor(Map.class, Map.class, StreamProvider.class, MetricHostProvider.class, String.class, String.class, String.class, String.class, String.class); + // TODO : Multi_Metrics_Changes. Check if we need to pass UniqueComponentName like : + // {SG_instance_name}_{service_instance_name}_component_name instead of just 'componentId'. Object o = ct.newInstance( injector, definition.getProperties(), componentMetrics, diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsCollectorHAClusterState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsCollectorHAClusterState.java index 231d1034ceb..80811d2b27f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsCollectorHAClusterState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsCollectorHAClusterState.java @@ -23,6 +23,7 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.Role; import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.controller.AmbariServer; @@ -60,11 +61,23 @@ public MetricsCollectorHAClusterState(String clusterName) { this.liveCollectorHosts = new CopyOnWriteArraySet<>(); this.deadCollectorHosts = new CopyOnWriteArraySet<>(); collectorDownRefreshCounter = new AtomicInteger(0); + + } + + private Long getComponentId(String componentName) { + Long componentId = null; + try { + componentId = managementController.getClusters().getCluster(clusterName).getComponentId(componentName); + } catch (AmbariException e) { + e.printStackTrace(); + } + return componentId; } public void addMetricsCollectorHost(String collectorHost) { + Long componentId = getComponentId(Role.METRICS_COLLECTOR.name()); if (HostStatusHelper.isHostComponentLive(managementController, clusterName, collectorHost, "AMBARI_METRICS", - Role.METRICS_COLLECTOR.name())) { + componentId, Role.METRICS_COLLECTOR.name(), Role.METRICS_COLLECTOR.name())) { liveCollectorHosts.add(collectorHost); deadCollectorHosts.remove(collectorHost); } else { @@ -73,9 +86,9 @@ public void addMetricsCollectorHost(String collectorHost) { } //If there is no current collector host or the current host is down, this will be a proactive switch. + // TODO : Multi_Metrics_Changes. componentName=Role.METRICS_COLLECTOR.name() may or may not be unique if there are multiple instances. if (currentCollectorHost == null || !HostStatusHelper.isHostComponentLive(managementController, clusterName, - currentCollectorHost, "AMBARI_METRICS", - Role.METRICS_COLLECTOR.name())) { + currentCollectorHost, "AMBARI_METRICS", componentId, Role.METRICS_COLLECTOR.name(), Role.METRICS_COLLECTOR.name())) { refreshCollectorHost(currentCollectorHost); } } @@ -142,11 +155,12 @@ private void testAndAddDeadCollectorsToLiveList() { } private boolean isValidAliveCollectorHost(String clusterName, String collectorHost) { - + Long componentId = getComponentId(Role.METRICS_COLLECTOR.name()); + // TODO : Multi_Metrics_Changes. componentName=Role.METRICS_COLLECTOR.name() may or may not be unique if there are multiple instances. return ((collectorHost != null) && HostStatusHelper.isHostLive(managementController, clusterName, collectorHost) && - HostStatusHelper.isHostComponentLive(managementController, clusterName, collectorHost, "AMBARI_METRICS", - Role.METRICS_COLLECTOR.name())); + HostStatusHelper.isHostComponentLive(managementController, clusterName, collectorHost, + "AMBARI_METRICS", componentId, Role.METRICS_COLLECTOR.name(), Role.METRICS_COLLECTOR.name())); } /* @@ -182,19 +196,21 @@ public boolean isCollectorHostLive() { } public boolean isCollectorComponentAlive() { - + Long componentId = getComponentId(Role.METRICS_COLLECTOR.name()); //Check in live hosts + // TODO : Multi_Metrics_Changes. componentName=Role.METRICS_COLLECTOR.name() may or may not be unique if there are multiple instances. for (String host : liveCollectorHosts) { if (HostStatusHelper.isHostComponentLive(managementController, clusterName, host, "AMBARI_METRICS", - Role.METRICS_COLLECTOR.name())) { + componentId, Role.METRICS_COLLECTOR.name(), Role.METRICS_COLLECTOR.name())) { return true; } } //Check in dead hosts. Don't update live and dead lists. Can be done on refresh call. + // TODO : Multi_Metrics_Changes. componentName=Role.METRICS_COLLECTOR.name() may or may not be unique if there are multiple instances. for (String host : deadCollectorHosts) { if (HostStatusHelper.isHostComponentLive(managementController, clusterName, host, "AMBARI_METRICS", - Role.METRICS_COLLECTOR.name())) { + componentId, Role.METRICS_COLLECTOR.name(), Role.METRICS_COLLECTOR.name())) { return true; } } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaPropertyProvider.java index ac0c590fdae..c94f15f00fc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaPropertyProvider.java @@ -60,7 +60,6 @@ public abstract class GangliaPropertyProvider extends MetricsPropertyProvider { */ static final Map> GANGLIA_CLUSTER_NAME_MAP = new HashMap<>(); - static { GANGLIA_CLUSTER_NAME_MAP.put("NAMENODE", Collections.singletonList("HDPNameNode")); GANGLIA_CLUSTER_NAME_MAP.put("DATANODE", Arrays.asList("HDPDataNode", "HDPSlaves")); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java index 904523058b4..0a352b0acf8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java @@ -89,7 +89,7 @@ public State getState(String clusterName, String serviceName) { StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null, null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java index b34b926fb11..63a01dc5358 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java @@ -52,7 +52,7 @@ public State getState(String clusterName, String serviceName) { if (cluster != null && managementControllerProvider != null) { Service service = cluster.getService(serviceName); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null, null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java index 63456e8c98b..51dd6c3807e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java @@ -54,7 +54,7 @@ public State getState(String clusterName, String serviceName) { StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null, null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java index 05e89040946..6c171136f5a 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java @@ -54,7 +54,7 @@ public State getState(String clusterName, String serviceName) { StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null,null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java index 83d26f0a71d..6881a1f31da 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java @@ -55,7 +55,7 @@ public State getState(String clusterName, String serviceName) { ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null, null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java index 5cd0319e1f8..db2318deeaa 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java @@ -54,7 +54,7 @@ public State getState(String clusterName, String serviceName) { StackId stackId = service.getDesiredStackId(); ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null, null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java index 2530068d69f..adeb74032a3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java @@ -55,7 +55,7 @@ public State getState(String clusterName, String serviceName) { ServiceComponentHostRequest request = new ServiceComponentHostRequest(clusterName, service.getServiceGroupName(), - serviceName, null, null, null); + serviceName, null, null, null, null, null); Set hostComponentResponses = managementControllerProvider.get().getHostComponents(Collections.singleton(request)); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java index 6f6fa43514e..3cb994e82f9 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java @@ -86,24 +86,15 @@ public HostComponentDesiredStateEntity findByServiceComponentAndHost( /** * Retrieve the single Host Component Desired State for the given unique cluster, service, component, and host. * - * @param clusterId Cluster ID - * @param serviceGroupId Service Group ID - * @param serviceId Service ID - * @param componentName Component Name - * @param hostId Host ID + * @param componentId Component Id * @return Return the Host Component Desired State entity that match the criteria. */ @RequiresSession - public HostComponentDesiredStateEntity findByIndex(Long clusterId, Long serviceGroupId, Long serviceId, - String componentName, Long hostId) { + public HostComponentDesiredStateEntity findByIndex(Long componentId) { final TypedQuery query = entityManagerProvider.get() .createNamedQuery("HostComponentDesiredStateEntity.findByIndex", HostComponentDesiredStateEntity.class); - query.setParameter("clusterId", clusterId); - query.setParameter("serviceGroupId", serviceGroupId); - query.setParameter("serviceId", serviceId); - query.setParameter("componentName", componentName); - query.setParameter("hostId", hostId); + query.setParameter("id", componentId); return daoUtils.selectSingle(query); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java index 7115b280a51..dd2e9d085fc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java @@ -42,6 +42,9 @@ public class HostComponentStateDAO { @Inject HostDAO hostDAO; + @Inject + HostComponentDesiredStateDAO hostComponentDesiredStateDAO; + @RequiresSession public HostComponentStateEntity findById(long id) { return entityManagerProvider.get().find(HostComponentStateEntity.class, id); @@ -120,22 +123,18 @@ public List findByServiceAndComponent( * Service Group ID * @param serviceId * Service ID - * @param componentName - * Component Name + * @param componentId + * Component ID * @param hostId * Host ID * @return Return all of the Host Component States that match the criteria. */ @RequiresSession public HostComponentStateEntity findByIndex(Long clusterId, Long serviceGroupId, Long serviceId, - String componentName, Long hostId) { + Long componentId, Long hostId) { final TypedQuery query = entityManagerProvider.get().createNamedQuery( "HostComponentStateEntity.findByIndex", HostComponentStateEntity.class); - query.setParameter("clusterId", clusterId); - query.setParameter("serviceGroupId", serviceGroupId); - query.setParameter("serviceId", serviceId); - query.setParameter("componentName", componentName); - query.setParameter("hostId", hostId); + query.setParameter("id", componentId); return daoUtils.selectSingle(query); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java index 90398f105b7..313eb51bab8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java @@ -82,7 +82,7 @@ public List findAll() { */ @RequiresSession public ServiceComponentDesiredStateEntity findByName(long clusterId, long serviceGroupId, long serviceId, - String componentName) { + String componentName, String componentType) { EntityManager entityManager = entityManagerProvider.get(); TypedQuery query = entityManager.createNamedQuery( "ServiceComponentDesiredStateEntity.findByName", ServiceComponentDesiredStateEntity.class); @@ -91,6 +91,38 @@ public ServiceComponentDesiredStateEntity findByName(long clusterId, long servic query.setParameter("serviceGroupId", serviceGroupId); query.setParameter("serviceId", serviceId); query.setParameter("componentName", componentName); + query.setParameter("componentType", componentType); + + ServiceComponentDesiredStateEntity entity = null; + List entities = daoUtils.selectList(query); + if (null != entities && !entities.isEmpty()) { + entity = entities.get(0); + } + + return entity; + } + + /** + * Finds a {@link ServiceComponentDesiredStateEntity} by a combination of + * cluster, service, and component. + * + * @param clusterId + * the cluster ID + * @param serviceGroupId + * the service group ID + * @param serviceId + * the service ID + * @param componentId + * the component id (not {@code null}) + */ + @RequiresSession + public ServiceComponentDesiredStateEntity findById(long clusterId, long serviceGroupId, long serviceId, + Long componentId) { + EntityManager entityManager = entityManagerProvider.get(); + TypedQuery query = entityManager.createNamedQuery( + "ServiceComponentDesiredStateEntity.findById", ServiceComponentDesiredStateEntity.class); + + query.setParameter("id", componentId); ServiceComponentDesiredStateEntity entity = null; List entities = daoUtils.selectList(query); @@ -122,8 +154,8 @@ public void remove(ServiceComponentDesiredStateEntity serviceComponentDesiredSta } @Transactional - public void removeByName(long clusterId, long serviceGroupId, long serviceId, String componentName) { - ServiceComponentDesiredStateEntity entity = findByName(clusterId, serviceGroupId, serviceId, componentName); + public void removeByName(long clusterId, long serviceGroupId, long serviceId, String componentName, String componentType) { + ServiceComponentDesiredStateEntity entity = findByName(clusterId, serviceGroupId, serviceId, componentName, componentType); if (null != entity) { entityManagerProvider.get().remove(entity); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java index fafec3d77ec..86534f3c01d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java @@ -66,7 +66,7 @@ "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE hcds.clusterId=:clusterId AND hcds.serviceGroupId=:serviceGroupId AND hcds.serviceId=:serviceId AND hcds.componentName=:componentName AND hcds.hostEntity.hostName=:hostName"), @NamedQuery(name = "HostComponentDesiredStateEntity.findByIndex", query = - "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE hcds.clusterId=:clusterId AND hcds.serviceGroupId=:serviceGroupId AND hcds.serviceId=:serviceId AND hcds.componentName=:componentName AND hcds.hostId=:hostId"), + "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE hcds.id=:id") }) public class HostComponentDesiredStateEntity { @@ -91,6 +91,9 @@ public class HostComponentDesiredStateEntity { @Column(name = "component_name", insertable = false, updatable = false) private String componentName = ""; + @Column(name = "component_type", insertable = false, updatable = false) + private String componentType = ""; + @Basic @Column(name = "desired_state", nullable = false, insertable = true, updatable = true) @Enumerated(value = EnumType.STRING) @@ -105,7 +108,8 @@ public class HostComponentDesiredStateEntity { @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false), @JoinColumn(name = "service_group_id", referencedColumnName = "service_group_id", nullable = false), @JoinColumn(name = "service_id", referencedColumnName = "service_id", nullable = false), - @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)}) + @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false), + @JoinColumn(name = "component_type", referencedColumnName = "component_type", nullable = false) }) private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity; @ManyToOne @@ -154,6 +158,14 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + public String getComponentType() { + return defaultString(componentType); + } + + public void setComponentType(String componentType) { + this.componentType = componentType; + } + public State getDesiredState() { return desiredState; } @@ -209,6 +221,10 @@ public boolean equals(Object o) { return false; } + if (!Objects.equal(componentType, that.componentType)) { + return false; + } + if (!Objects.equal(desiredState, that.desiredState)) { return false; } @@ -228,6 +244,7 @@ public int hashCode() { result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0); result = 31 * result + (hostEntity != null ? hostEntity.hashCode() : 0); result = 31 * result + (componentName != null ? componentName.hashCode() : 0); + result = 31 * result + (componentType != null ? componentType.hashCode() : 0); result = 31 * result + (desiredState != null ? desiredState.hashCode() : 0); return result; } @@ -264,6 +281,7 @@ public void setRestartRequired(boolean restartRequired) { public String toString() { return Objects.toStringHelper(this).add("clusterId", clusterId).add( "serviceGroupId", serviceGroupId).add("serviceId", serviceId).add("componentName", - componentName).add("hostId", hostId).add("desiredState", desiredState).toString(); + componentName).add("componentType", componentType).add("hostId", hostId).add("desiredState", + desiredState).toString(); } } \ No newline at end of file diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java index f56df9d2427..34379a8ea41 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java @@ -30,16 +30,23 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; +import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.TableGenerator; +import javax.persistence.UniqueConstraint; + import org.apache.ambari.server.state.State; import org.apache.ambari.server.state.UpgradeState; import com.google.common.base.Objects; @Entity -@Table(name = "hostcomponentstate") +@Table( + name = "hostcomponentstate", + uniqueConstraints = @UniqueConstraint( + name = "UQ_hostcomponentstate_name", + columnNames = { "component_name", "service_id" , "host_id", "service_group_id", "cluster_id" }) ) @TableGenerator( name = "hostcomponentstate_id_generator", table = "ambari_sequences", @@ -76,9 +83,7 @@ "AND hcs.version != :version"), @NamedQuery( name = "HostComponentStateEntity.findByIndex", - query = "SELECT hcs from HostComponentStateEntity hcs WHERE hcs.clusterId=:clusterId " + - "AND hcs.serviceGroupId=:serviceGroupId AND hcs.serviceId=:serviceId AND hcs.componentName=:componentName AND hcs.hostId=:hostId") }) - + query = "SELECT hcs from HostComponentStateEntity hcs WHERE hcs.id=:id") }) public class HostComponentStateEntity { @Id @@ -86,6 +91,9 @@ public class HostComponentStateEntity { @Column(name = "id", nullable = false, insertable = true, updatable = false) private Long id; + @Column(name = "host_component_desired_state_id", nullable = false, insertable = false, updatable = false) + private Long hostComponentDesiredStateId; + @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10) private Long clusterId; @@ -101,6 +109,9 @@ public class HostComponentStateEntity { @Column(name = "component_name", nullable = false, insertable = false, updatable = false) private String componentName; + @Column(name = "component_type", nullable = false, insertable = false, updatable = false) + private String componentType; + /** * Version reported by host component during last status update. */ @@ -120,13 +131,18 @@ public class HostComponentStateEntity { @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false), @JoinColumn(name = "service_group_id", referencedColumnName = "service_group_id", nullable = false), @JoinColumn(name = "service_id", referencedColumnName = "service_id", nullable = false), - @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false) }) + @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false), + @JoinColumn(name = "component_type", referencedColumnName = "component_type", nullable = false) }) private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity; @ManyToOne @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = false) private HostEntity hostEntity; + @OneToOne + @JoinColumn(name = "host_component_desired_state_id", referencedColumnName = "id", nullable = false) + private HostComponentDesiredStateEntity hostComponentDesiredStateEntity; + public Long getId() { return id; } @@ -171,6 +187,26 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + public Long getHostComponentDesiredStateId() { + return hostComponentDesiredStateEntity != null ? hostComponentDesiredStateEntity.getId() : null; + } + + public void setComponentId(Long componentId) { + this.id = componentId; + } + + public Long getComponentId() { + return id; + } + + public void setComponentType(String componentType) { + this.componentType = componentType; + } + + public String getComponentType() { + return componentType; + } + public State getCurrentState() { return currentState; } @@ -228,6 +264,11 @@ public boolean equals(Object o) { return false; } + if (componentType != null ? !componentType.equals(that.componentType) + : that.componentType != null) { + return false; + } + if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) { return false; @@ -242,6 +283,10 @@ public boolean equals(Object o) { return false; } + if (hostComponentDesiredStateEntity != null ? !hostComponentDesiredStateEntity.equals(that.hostComponentDesiredStateEntity) : that.hostComponentDesiredStateEntity != null) { + return false; + } + if (version != null ? !version.equals(that.version) : that.version != null) { return false; } @@ -256,7 +301,9 @@ public int hashCode() { result = 31 * result + (serviceGroupId != null ? serviceGroupId.intValue() : 0); result = 31 * result + (serviceId != null ? serviceId.intValue() : 0); result = 31 * result + (hostEntity != null ? hostEntity.hashCode() : 0); + result = 31 * result + (hostComponentDesiredStateEntity != null ? hostComponentDesiredStateEntity.hashCode() : 0); result = 31 * result + (componentName != null ? componentName.hashCode() : 0); + result = 31 * result + (componentType != null ? componentType.hashCode() : 0); result = 31 * result + (currentState != null ? currentState.hashCode() : 0); result = 31 * result + (upgradeState != null ? upgradeState.hashCode() : 0); result = 31 * result + (version != null ? version.hashCode() : 0); @@ -267,8 +314,7 @@ public ServiceComponentDesiredStateEntity getServiceComponentDesiredStateEntity( return serviceComponentDesiredStateEntity; } - public void setServiceComponentDesiredStateEntity( - ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity) { + public void setServiceComponentDesiredStateEntity(ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity) { this.serviceComponentDesiredStateEntity = serviceComponentDesiredStateEntity; } @@ -280,14 +326,22 @@ public void setHostEntity(HostEntity hostEntity) { this.hostEntity = hostEntity; } + public HostComponentDesiredStateEntity getHostComponentDesiredStateEntity() { + return hostComponentDesiredStateEntity; + } + + public void setHostComponentDesiredStateEntity(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) { + this.hostComponentDesiredStateEntity = hostComponentDesiredStateEntity; + } + /** * {@inheritDoc} */ @Override public String toString() { return Objects.toStringHelper(this).add("clusterId", clusterId).add("serviceGroupId", serviceGroupId).add( - "serviceId", serviceId).add("componentName", componentName).add( - "hostId", hostId).add("state", currentState).toString(); + "serviceId", serviceId).add("componentId", id).add("componentName", componentName).add + ("componentType", componentType).add("hostId", hostId).add("state", currentState).toString(); } } \ No newline at end of file diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java index f3b0184dffb..6ee28f1512f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java @@ -62,7 +62,13 @@ query = "SELECT scds FROM ServiceComponentDesiredStateEntity scds WHERE scds.clusterId = :clusterId " + "AND scds.serviceGroupId = :serviceGroupId " + "AND scds.serviceId = :serviceId " + - "AND scds.componentName = :componentName") }) + "AND scds.componentName = :componentName " + + "AND scds.componentType = :componentType" ), + @NamedQuery( + name = "ServiceComponentDesiredStateEntity.findById", + query = "SELECT scds FROM ServiceComponentDesiredStateEntity scds WHERE scds.id = :id" ) +}) + public class ServiceComponentDesiredStateEntity { @Id @@ -75,6 +81,9 @@ public class ServiceComponentDesiredStateEntity { @Column(name = "component_name", nullable = false, insertable = true, updatable = true) private String componentName; + @Column(name = "component_type", nullable = false, insertable = true, updatable = true) + private String componentType; + @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10) private Long clusterId; @@ -154,6 +163,14 @@ public void setComponentName(String componentName) { this.componentName = componentName; } + public String getComponentType() { + return componentType; + } + + public void setComponentType(String componentType) { + this.componentType = componentType; + } + public State getDesiredState() { return desiredState; } @@ -224,6 +241,9 @@ public boolean equals(Object o) { if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) { return false; } + if (componentType != null ? !componentType.equals(that.componentType) : that.componentType != null) { + return false; + } if (desiredState != null ? !desiredState.equals(that.desiredState) : that.desiredState != null) { return false; } @@ -241,6 +261,7 @@ public int hashCode() { result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() : 0); result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0); result = 31 * result + (componentName != null ? componentName.hashCode() : 0); + result = 31 * result + (componentType != null ? componentType.hashCode() : 0); result = 31 * result + (desiredState != null ? desiredState.hashCode() : 0); result = 31 * result + (desiredRepositoryVersion != null ? desiredRepositoryVersion.hashCode() : 0); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java index 79d5844c3dc..c708ec1565c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java @@ -161,6 +161,22 @@ Service addDependencyToService(String serviceGroupName, String serviceName, */ Service getServiceByComponentName(String componentName) throws AmbariException; + /** + * Gets a service from the given component Id. + * + * @param componentId + * @return + * @throws AmbariException + */ + + Service getServiceByComponentId(Long componentId) throws AmbariException; + + Long getComponentId(String componentName) throws AmbariException; + + String getComponentName(Long componentId) throws AmbariException; + + String getComponentType(Long componentId) throws AmbariException; + /** * Get all services * diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java index b1f18e72e94..000ab361f9b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java @@ -74,7 +74,7 @@ void addServiceComponent(ServiceComponent component) void debugDump(StringBuilder sb); - ServiceComponent addServiceComponent(String serviceComponentName) + ServiceComponent addServiceComponent(String serviceComponentName, String serviceComponentType) throws AmbariException; /** diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java index 8a0eda35b24..6dab235f93e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java @@ -30,6 +30,10 @@ public interface ServiceComponent { String getName(); + String getType(); + + Long getId(); + /** * Get a true or false value specifying * if auto start was enabled for this component. diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentFactory.java index 9c692d6f36e..4c36e7c586f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentFactory.java @@ -19,9 +19,12 @@ import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity; +import com.google.inject.assistedinject.Assisted; + public interface ServiceComponentFactory { - ServiceComponent createNew(Service service, String componentName); + ServiceComponent createNew(Service service, @Assisted("componentName") String componentName, + @Assisted("componentType") String componentType); ServiceComponent createExisting(Service service, ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java index 54c378d51a5..46c704fb138 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java @@ -71,11 +71,23 @@ public interface ServiceComponentHost { String getServiceType(); /** - * Get the ServiceComponent this object maps to + * Get the ServiceComponent's Id this object maps to + * @return Id of the ServiceComponent + */ + public Long getServiceComponentId(); + + /** + * Get the ServiceComponent's Name this object maps to * @return Name of the ServiceComponent */ String getServiceComponentName(); + /** + * Get the ServiceComponent's Type this object maps to + * @return Type of the ServiceComponent + */ + String getServiceComponentType(); + /** * Get the Host this object maps to * @return Host's hostname diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java index 2cfbd45ef9f..77634a0ecbe 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java @@ -66,6 +66,7 @@ public class ServiceComponentImpl implements ServiceComponent { private final Service service; private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); private final String componentName; + private final String componentType; private String displayName; private boolean isClientComponent; private boolean isMasterComponent; @@ -98,8 +99,8 @@ public class ServiceComponentImpl implements ServiceComponent { private MaintenanceStateHelper maintenanceStateHelper; @AssistedInject - public ServiceComponentImpl(@Assisted Service service, @Assisted String componentName, - AmbariMetaInfo ambariMetaInfo, + public ServiceComponentImpl(@Assisted Service service, @Assisted("componentName") String componentName, + @Assisted("componentType") String componentType, AmbariMetaInfo ambariMetaInfo, ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO, ClusterServiceDAO clusterServiceDAO, ServiceComponentHostFactory serviceComponentHostFactory, AmbariEventPublisher eventPublisher) @@ -108,6 +109,7 @@ public ServiceComponentImpl(@Assisted Service service, @Assisted String componen this.ambariMetaInfo = ambariMetaInfo; this.service = service; this.componentName = componentName; + this.componentType = componentType; this.serviceComponentDesiredStateDAO = serviceComponentDesiredStateDAO; this.clusterServiceDAO = clusterServiceDAO; this.serviceComponentHostFactory = serviceComponentHostFactory; @@ -115,6 +117,7 @@ public ServiceComponentImpl(@Assisted Service service, @Assisted String componen ServiceComponentDesiredStateEntity desiredStateEntity = new ServiceComponentDesiredStateEntity(); desiredStateEntity.setComponentName(componentName); + desiredStateEntity.setComponentType(componentType); desiredStateEntity.setDesiredState(State.INIT); desiredStateEntity.setServiceGroupId(service.getServiceGroupId()); desiredStateEntity.setServiceId(service.getServiceId()); @@ -133,7 +136,7 @@ public void updateComponentInfo() throws AmbariException { StackId stackId = service.getDesiredStackId(); try { ComponentInfo compInfo = ambariMetaInfo.getComponent(stackId.getStackName(), - stackId.getStackVersion(), service.getServiceType(), componentName); + stackId.getStackVersion(), service.getServiceType(), componentType); isClientComponent = compInfo.isClient(); isMasterComponent = compInfo.isMaster(); isVersionAdvertised = compInfo.isVersionAdvertised(); @@ -144,6 +147,7 @@ public void updateComponentInfo() throws AmbariException { + ", clusterName=" + service.getCluster().getClusterName() + ", serviceName=" + service.getServiceType() + ", componentName=" + componentName + + ", componentType=" + componentType + ", stackInfo=" + stackId.getStackId()); } } @@ -167,18 +171,14 @@ public ServiceComponentImpl(@Assisted Service service, desiredStateEntityId = serviceComponentDesiredStateEntity.getId(); componentName = serviceComponentDesiredStateEntity.getComponentName(); + componentType = serviceComponentDesiredStateEntity.getComponentType(); updateComponentInfo(); for (HostComponentStateEntity hostComponentStateEntity : serviceComponentDesiredStateEntity.getHostComponentStateEntities()) { HostComponentDesiredStateEntity hostComponentDesiredStateEntity = hostComponentDesiredStateDAO.findByIndex( - hostComponentStateEntity.getClusterId(), - hostComponentStateEntity.getServiceGroupId(), - hostComponentStateEntity.getServiceId(), - hostComponentStateEntity.getComponentName(), - hostComponentStateEntity.getHostId() - ); + hostComponentStateEntity.getHostComponentDesiredStateId()); try { hostComponents.put(hostComponentStateEntity.getHostName(), @@ -186,9 +186,11 @@ public ServiceComponentImpl(@Assisted Service service, hostComponentStateEntity, hostComponentDesiredStateEntity)); } catch(ProvisionException ex) { StackId currentStackId = getDesiredStackId(); - LOG.error(String.format("Can not get host component info: stackName=%s, stackVersion=%s, serviceName=%s, componentName=%s, hostname=%s", - currentStackId.getStackName(), currentStackId.getStackVersion(), - service.getName(),serviceComponentDesiredStateEntity.getComponentName(), hostComponentStateEntity.getHostName())); + LOG.error(String.format("Cannot get host component info: stackName=%s, stackVersion=%s, serviceName=%s, componentName=%s, " + + "componentType=%s, hostname=%s", + currentStackId.getStackName(), currentStackId.getStackVersion(), service.getName(), + serviceComponentDesiredStateEntity.getComponentName(), serviceComponentDesiredStateEntity.getComponentType(), + hostComponentStateEntity.getHostName())); ex.printStackTrace(); } } @@ -199,6 +201,16 @@ public String getName() { return componentName; } + @Override + public String getType() { + return componentType; + } + + @Override + public Long getId() { + return desiredStateEntityId; + } + /** * Get the recoveryEnabled value. * @@ -214,7 +226,7 @@ public boolean isRecoveryEnabled() { } else { LOG.warn("Trying to fetch a member from an entity object that may " + "have been previously deleted, serviceName = " + service.getName() + ", " + - "componentName = " + componentName); + "componentName = " + componentName + ", componentType = " + componentType); } return false; } @@ -227,8 +239,8 @@ public boolean isRecoveryEnabled() { @Override public void setRecoveryEnabled(boolean recoveryEnabled) { if (LOG.isDebugEnabled()) { - LOG.debug("Setting RecoveryEnabled of Component, clusterName={}, clusterId={}, serviceName={}, componentName={}, oldRecoveryEnabled={}, newRecoveryEnabled={}", - service.getCluster().getClusterName(), service.getCluster().getClusterId(), service.getName(), getName(), isRecoveryEnabled(), recoveryEnabled); + LOG.debug("Setting RecoveryEnabled of Component, clusterName={}, clusterId={}, serviceName={}, componentName={}, componentType={}, oldRecoveryEnabled={}, newRecoveryEnabled={}", + service.getCluster().getClusterName(), service.getCluster().getClusterId(), service.getName(), getName(), getType(), isRecoveryEnabled(), recoveryEnabled); } ServiceComponentDesiredStateEntity desiredStateEntity = serviceComponentDesiredStateDAO.findById( @@ -341,7 +353,7 @@ public State getDesiredState() { } else { LOG.warn("Trying to fetch a member from an entity object that may " + "have been previously deleted, serviceName = " + getServiceName() + ", " + - "componentName = " + componentName); + "componentName = " + componentName + ", componentType = " + componentType); } return null; @@ -445,7 +457,7 @@ public ServiceComponentResponse convertToResponse() { ServiceComponentResponse r = new ServiceComponentResponse(getClusterId(), cluster.getClusterName(), sg.getServiceGroupId(), sg.getServiceGroupName(), service.getServiceId(), - serviceName, service.getServiceType(), componentName, sg.getStackId(), getDesiredState().toString(), + serviceName, service.getServiceType(), getId(), getName(), getType(), sg.getStackId(), getDesiredState().toString(), getServiceComponentStateCount(), isRecoveryEnabled(), displayName, moduleComponent.getVersion(), getRepositoryState()); @@ -520,7 +532,7 @@ public boolean canBeRemoved() { if (!sch.canBeRemoved()) { LOG.warn("Found non removable hostcomponent when trying to" + " delete service component" + ", clusterName=" + getClusterName() + ", serviceName=" + getServiceName() - + ", componentName=" + getName() + ", state=" + sch.getState() + ", hostname=" + + ", componentName=" + getName() + ", componentType=" + getType() + ", state=" + sch.getState() + ", hostname=" + sch.getHostName()); return false; } @@ -535,12 +547,12 @@ public void deleteAllServiceComponentHosts() throws AmbariException { try { LOG.info("Deleting all servicecomponenthosts for component" + ", clusterName=" + getClusterName() + ", serviceName=" + getServiceName() + ", componentName=" + getName() - + ", recoveryEnabled=" + isRecoveryEnabled()); + + ", componentType=" + getType() + ", recoveryEnabled=" + isRecoveryEnabled()); for (ServiceComponentHost sch : hostComponents.values()) { if (!sch.canBeRemoved()) { throw new AmbariException("Found non removable hostcomponent " + " when trying to delete" + " all hostcomponents from servicecomponent" + ", clusterName=" + getClusterName() - + ", serviceName=" + getServiceName() + ", componentName=" + getName() + + ", serviceName=" + getServiceName() + ", componentName=" + getName() + ", componentType=" + getType() + ", recoveryEnabled=" + isRecoveryEnabled() + ", hostname=" + sch.getHostName()); } } @@ -561,13 +573,14 @@ public void deleteServiceComponentHosts(String hostname) throws AmbariException try { ServiceComponentHost sch = getServiceComponentHost(hostname); LOG.info("Deleting servicecomponenthost for cluster" + ", clusterName=" + getClusterName() - + ", serviceName=" + getServiceName() + ", componentName=" + getName() + + ", serviceName=" + getServiceName() + ", componentName=" + getName() + ", componentType=" + getType() + ", recoveryEnabled=" + isRecoveryEnabled() + ", hostname=" + sch.getHostName()); if (!sch.canBeRemoved()) { throw new AmbariException("Could not delete hostcomponent from cluster" + ", clusterName=" + getClusterName() + ", serviceName=" + getServiceName() + ", componentName=" + getName() + + ", componentType=" + getType() + ", recoveryEnabled=" + isRecoveryEnabled() + ", hostname=" + sch.getHostName()); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java index 4ed65a769af..72939b123ee 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java @@ -80,7 +80,8 @@ public class ServiceImpl implements Service { private final Cluster cluster; private final ServiceGroup serviceGroup; - private final ConcurrentMap components = new ConcurrentHashMap<>(); + private final ConcurrentMap componentsByName = new ConcurrentHashMap<>(); + private final ConcurrentMap componentsById = new ConcurrentHashMap<>(); private List serviceDependencies = new ArrayList<>(); private boolean isClientOnlyService; private boolean isCredentialStoreSupported; @@ -226,10 +227,12 @@ public class ServiceImpl implements Service { for (ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity : serviceEntity.getServiceComponentDesiredStateEntities()) { try { - components.put(serviceComponentDesiredStateEntity.getComponentName(), - serviceComponentFactory.createExisting(this, - serviceComponentDesiredStateEntity)); - } catch(ProvisionException ex) { + ServiceComponent svcComponent = serviceComponentFactory.createExisting(this, + serviceComponentDesiredStateEntity); + componentsByName.put(serviceComponentDesiredStateEntity.getComponentName(), svcComponent); + componentsById.put(serviceComponentDesiredStateEntity.getId(), svcComponent); + + } catch(ProvisionException ex) { StackId stackId = new StackId(serviceComponentDesiredStateEntity.getDesiredStack()); LOG.error(String.format("Can not get component info: stackName=%s, stackVersion=%s, serviceName=%s, componentName=%s", stackId.getStackName(), stackId.getStackVersion(), @@ -304,13 +307,13 @@ public String getServiceGroupName() { @Override public Map getServiceComponents() { - return new HashMap<>(components); + return new HashMap<>(componentsByName); } @Override public void addServiceComponents( - Map components) throws AmbariException { - for (ServiceComponent sc : components.values()) { + Map componentsByName) throws AmbariException { + for (ServiceComponent sc : componentsByName.values()) { addServiceComponent(sc); } } @@ -326,7 +329,7 @@ public void setServiceDependencies(List serviceDependencies) { @Override public void addServiceComponent(ServiceComponent component) throws AmbariException { - if (components.containsKey(component.getName())) { + if (componentsByName.containsKey(component.getName())) { throw new AmbariException("Cannot add duplicate ServiceComponent" + ", clusterName=" + cluster.getClusterName() + ", clusterId=" + cluster.getClusterId() @@ -335,13 +338,13 @@ public void addServiceComponent(ServiceComponent component) throws AmbariExcepti + ", serviceComponentName=" + component.getName()); } - components.put(component.getName(), component); + componentsByName.put(component.getName(), component); } @Override - public ServiceComponent addServiceComponent(String serviceComponentName) + public ServiceComponent addServiceComponent(String serviceComponentName, String serviceComponentType) throws AmbariException { - ServiceComponent component = serviceComponentFactory.createNew(this, serviceComponentName); + ServiceComponent component = serviceComponentFactory.createNew(this, serviceComponentName, serviceComponentType); addServiceComponent(component); return component; } @@ -349,7 +352,7 @@ public ServiceComponent addServiceComponent(String serviceComponentName) @Override public ServiceComponent getServiceComponent(String componentName) throws AmbariException { - ServiceComponent serviceComponent = components.get(componentName); + ServiceComponent serviceComponent = componentsByName.get(componentName); if (null == serviceComponent) { throw new ServiceComponentNotFoundException(cluster.getClusterName(), getName(), getServiceType(), serviceGroup.getServiceGroupName(), componentName); @@ -468,8 +471,8 @@ public void setDesiredRepositoryVersion(RepositoryVersionEntity repositoryVersio serviceDesiredStateEntity.setDesiredRepositoryVersion(repositoryVersionEntity); serviceDesiredStateDAO.merge(serviceDesiredStateEntity); - Collection components = getServiceComponents().values(); - for (ServiceComponent component : components) { + Collection componentsByName = getServiceComponents().values(); + for (ServiceComponent component : componentsByName) { component.setDesiredRepositoryVersion(repositoryVersionEntity); } } @@ -481,12 +484,12 @@ public void setDesiredRepositoryVersion(RepositoryVersionEntity repositoryVersio @Deprecated @Experimental(feature = ExperimentalFeature.REPO_VERSION_REMOVAL) public RepositoryVersionState getRepositoryState() { - if (components.isEmpty()) { + if (componentsByName.isEmpty()) { return RepositoryVersionState.NOT_REQUIRED; } List states = new ArrayList<>(); - for( ServiceComponent component : components.values() ){ + for( ServiceComponent component : componentsByName.values() ){ states.add(component.getRepositoryState()); } @@ -658,9 +661,9 @@ public void debugDump(StringBuilder sb) { .append(", clusterId=").append(cluster.getClusterId()) .append(", desiredStackVersion=").append(getDesiredStackId()) .append(", desiredState=").append(getDesiredState()) - .append(", components=[ "); + .append(", componentsByName=[ "); boolean first = true; - for (ServiceComponent sc : components.values()) { + for (ServiceComponent sc : componentsByName.values()) { if (!first) { sb.append(" , "); } @@ -711,11 +714,11 @@ void persistEntities(ClusterServiceEntity serviceEntity) { @Override public boolean canBeRemoved() { // - // A service can be deleted if all it's components + // A service can be deleted if all it's componentsByName // can be removed, irrespective of the state of // the service itself. // - for (ServiceComponent sc : components.values()) { + for (ServiceComponent sc : componentsByName.values()) { if (!sc.canBeRemoved()) { LOG.warn("Found non-removable component when trying to delete service" + ", clusterName=" + cluster.getClusterName() + ", serviceName=" + getName() + ", serviceType=" @@ -757,22 +760,22 @@ void deleteAllServiceConfigs() throws AmbariException { public void deleteAllComponents() throws AmbariException { lock.lock(); try { - LOG.info("Deleting all components for service" + ", clusterName=" + cluster.getClusterName() + LOG.info("Deleting all componentsByName for service" + ", clusterName=" + cluster.getClusterName() + ", serviceName=" + getName()); // FIXME check dependencies from meta layer - for (ServiceComponent component : components.values()) { + for (ServiceComponent component : componentsByName.values()) { if (!component.canBeRemoved()) { throw new AmbariException("Found non removable component when trying to" - + " delete all components from service" + ", clusterName=" + cluster.getClusterName() + + " delete all componentsByName from service" + ", clusterName=" + cluster.getClusterName() + ", serviceName=" + getName() + ", componentName=" + component.getName()); } } - for (ServiceComponent serviceComponent : components.values()) { + for (ServiceComponent serviceComponent : componentsByName.values()) { serviceComponent.delete(); } - components.clear(); + componentsByName.clear(); } finally { lock.unlock(); } @@ -795,7 +798,7 @@ public void deleteServiceComponent(String componentName) } component.delete(); - components.remove(componentName); + componentsByName.remove(componentName); } finally { lock.unlock(); } @@ -809,7 +812,7 @@ public boolean isClientOnlyService() { @Override @Transactional public void delete() throws AmbariException { - List components = getComponents(); // XXX temporal coupling, need to call this BEFORE deletingAllComponents + List componentsByName = getComponents(); // XXX temporal coupling, need to call this BEFORE deletingAllComponents deleteAllComponents(); deleteAllServiceConfigs(); @@ -824,7 +827,7 @@ public void delete() throws AmbariException { ServiceRemovedEvent event = new ServiceRemovedEvent(getClusterId(), stackId.getStackName(), stackId.getStackVersion(), getName(), getServiceType(), - serviceGroup.getServiceGroupName(), components); + serviceGroup.getServiceGroupName(), componentsByName); eventPublisher.publish(event); } diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java index 9b0390faba5..23c7489c854 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java @@ -1187,6 +1187,58 @@ public Service getServiceByComponentName(String componentName) throws AmbariExce throw new ServiceNotFoundException(getClusterName(), "component: " + componentName); } + @Override + public Service getServiceByComponentId(Long componentId) throws AmbariException { + for (Service service : services.values()) { + for (ServiceComponent component : service.getServiceComponents().values()) { + if (component.getId().equals(componentId)) { + return service; + } + } + } + + throw new ServiceNotFoundException(getClusterName(), "component Id: " + componentId); + } + + @Override + public String getComponentName(Long componentId) throws AmbariException { + for (Service service : services.values()) { + for (ServiceComponent component : service.getServiceComponents().values()) { + if (component.getId().equals(componentId)) { + return component.getName(); + } + } + } + + throw new ServiceNotFoundException(getClusterName(), "component Id: " + componentId); + } + + + @Override + public String getComponentType(Long componentId) throws AmbariException { + for (Service service : services.values()) { + for (ServiceComponent component : service.getServiceComponents().values()) { + if (component.getId().equals(componentId)) { + return component.getType(); + } + } + } + + throw new ServiceNotFoundException(getClusterName(), "component Id: " + componentId); + } + + @Override + public Long getComponentId(String componentName) throws AmbariException { + for (Service service : services.values()) { + for (ServiceComponent component : service.getServiceComponents().values()) { + if (component.getName().equals(componentName)) { + return component.getId(); + } + } + } + + throw new ServiceNotFoundException(getClusterName(), "component Name: " + componentName); + } @Override public ServiceGroup getServiceGroup(String serviceGroupName) throws ServiceGroupNotFoundException { diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java index 7caef7f672b..afde94a3b8c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java @@ -788,6 +788,7 @@ public ServiceComponentHostImpl(@Assisted ServiceComponent serviceComponent, stateEntity.setServiceGroupId(serviceComponent.getServiceGroupId()); stateEntity.setServiceId(serviceComponent.getServiceId()); stateEntity.setComponentName(serviceComponent.getName()); + stateEntity.setComponentType(serviceComponent.getType()); stateEntity.setVersion(State.UNKNOWN.toString()); stateEntity.setHostEntity(hostEntity); stateEntity.setCurrentState(stateMachine.getCurrentState()); @@ -796,6 +797,8 @@ public ServiceComponentHostImpl(@Assisted ServiceComponent serviceComponent, HostComponentDesiredStateEntity desiredStateEntity = new HostComponentDesiredStateEntity(); desiredStateEntity.setClusterId(serviceComponent.getClusterId()); desiredStateEntity.setComponentName(serviceComponent.getName()); + desiredStateEntity.setComponentType(serviceComponent.getType()); + desiredStateEntity.setServiceGroupId(serviceComponent.getServiceGroupId()); desiredStateEntity.setServiceId(serviceComponent.getServiceId()); desiredStateEntity.setHostEntity(hostEntity); desiredStateEntity.setDesiredState(State.INIT); @@ -993,11 +996,21 @@ public void handleEvent(ServiceComponentHostEvent event) } } + @Override + public Long getServiceComponentId() { + return serviceComponent.getId(); + } + @Override public String getServiceComponentName() { return serviceComponent.getName(); } + @Override + public String getServiceComponentType() { + return serviceComponent.getType(); + } + @Override public String getHostName() { return host.getHostName(); @@ -1183,6 +1196,8 @@ public ServiceComponentHostResponse convertToResponse(Map e.printStackTrace(); } String serviceComponentName = serviceComponent.getName(); + String serviceComponentType = serviceComponent.getType(); + Long hostComponentId = getHostComponentId(); String hostName = getHostName(); String publicHostName = hostEntity.getPublicHostName(); @@ -1210,8 +1225,8 @@ public ServiceComponentHostResponse convertToResponse(Map ServiceComponentHostResponse r = new ServiceComponentHostResponse(clusterId, clusterName, service.getServiceGroupId(), service.getServiceGroupName(), service.getServiceId(), service.getName(), service.getServiceType(), - hostComponentId, serviceComponentName, displayName, hostName, publicHostName, state, getVersion(), - desiredState, desiredStackId, desiredRepositoryVersion, componentAdminState); + hostComponentId, serviceComponentName, serviceComponentType, displayName, hostName, publicHostName, state, + getVersion(), desiredState, desiredStackId, desiredRepositoryVersion, componentAdminState); r.setActualConfigs(actualConfigs); r.setUpgradeState(upgradeState); @@ -1244,6 +1259,8 @@ public void debugDump(StringBuilder sb) { sb.append("ServiceComponentHost={ hostname=").append(getHostName()) .append(", serviceComponentName=") .append(serviceComponent.getName()) + .append(", serviceComponentType=") + .append(serviceComponent.getType()) .append(", clusterName=") .append(serviceComponent.getClusterName()) .append(", serviceName=") @@ -1262,9 +1279,10 @@ public void debugDump(StringBuilder sb) { @Transactional void persistEntities(HostEntity hostEntity, HostComponentStateEntity stateEntity, HostComponentDesiredStateEntity desiredStateEntity) { - ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName( - serviceComponent.getClusterId(), serviceComponent.getServiceGroupId(), serviceComponent.getServiceId(), - serviceComponent.getName()); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = null; + serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName( + serviceComponent.getClusterId(), serviceComponent.getServiceGroupId(), serviceComponent.getServiceId(), + serviceComponent.getName(), serviceComponent.getType()); desiredStateEntity.setServiceComponentDesiredStateEntity(serviceComponentDesiredStateEntity); desiredStateEntity.setHostEntity(hostEntity); @@ -1272,8 +1290,12 @@ void persistEntities(HostEntity hostEntity, HostComponentStateEntity stateEntity stateEntity.setServiceComponentDesiredStateEntity(serviceComponentDesiredStateEntity); stateEntity.setHostEntity(hostEntity); - hostComponentStateDAO.create(stateEntity); hostComponentDesiredStateDAO.create(desiredStateEntity); + stateEntity.setHostComponentDesiredStateEntity(desiredStateEntity); + hostComponentStateDAO.create(stateEntity); + + serviceComponentDesiredStateEntity.getHostComponentStateEntities().add( + stateEntity); serviceComponentDesiredStateEntity.getHostComponentDesiredStateEntities().add( desiredStateEntity); diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java index f53b767fd7e..f298b4b1d43 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java @@ -372,7 +372,7 @@ private void createAmbariServiceAndComponentResources(ClusterTopology topology, .collect(toSet()); Set componentRequests = topology.getComponents() - .map(c -> new ServiceComponentRequest(clusterName, c.effectiveServiceGroupName(), c.effectiveServiceName(), c.componentName(), null, + .map(c -> new ServiceComponentRequest(clusterName, c.effectiveServiceGroupName(), c.effectiveServiceName(), c.componentName(), c.componentName(), topology.getSetting().getRecoveryEnabled(c.effectiveServiceName(), c.componentName()))) // FIXME settings by service type or name? .collect(toSet()); @@ -442,7 +442,7 @@ public void createAmbariHostResources(long clusterId, String hostName, Stream requests = components .filter(component -> !component.componentName().equals(RootComponent.AMBARI_SERVER.name())) - .map(component -> new ServiceComponentHostRequest(clusterName, component.effectiveServiceGroupName(), component.effectiveServiceName(), component.componentName(), hostName, null)) + .map(component -> new ServiceComponentHostRequest(clusterName, component.effectiveServiceGroupName(), component.effectiveServiceName(), component.componentName(), component.componentName(),hostName, null)) .collect(toSet()); try { 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 3b0b5eeea58..e71466571df 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql @@ -283,6 +283,7 @@ CREATE TABLE repo_tags ( CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, service_id BIGINT NOT NULL, @@ -299,6 +300,7 @@ CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, @@ -314,8 +316,10 @@ CREATE TABLE hostcomponentdesiredstate ( CREATE TABLE hostcomponentstate ( id BIGINT NOT NULL, + host_component_desired_state_id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, @@ -323,7 +327,9 @@ CREATE TABLE hostcomponentstate ( service_id BIGINT NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), + CONSTRAINT UQ_hostcomponentstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), + CONSTRAINT FK_hostcomponentstate_ds_id FOREIGN KEY (host_component_desired_state_id) REFERENCES hostcomponentdesiredstate (id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE INDEX idx_host_component_state on hostcomponentstate(host_id, component_name, service_id, cluster_id); 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 1ca41884288..8e87d563a9f 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql @@ -302,6 +302,7 @@ CREATE TABLE repo_tags ( CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(100) NOT NULL, + component_type VARCHAR(100) NOT NULL, cluster_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, service_id BIGINT NOT NULL, @@ -318,6 +319,7 @@ CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(100) NOT NULL, + component_type VARCHAR(100) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, @@ -333,8 +335,10 @@ CREATE TABLE hostcomponentdesiredstate ( CREATE TABLE hostcomponentstate ( id BIGINT NOT NULL, + host_component_desired_state_id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(100) NOT NULL, + component_type VARCHAR(100) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, @@ -342,7 +346,9 @@ CREATE TABLE hostcomponentstate ( service_id BIGINT NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), + CONSTRAINT UQ_hostcomponentstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), + CONSTRAINT FK_hostcomponentstate_ds_id FOREIGN KEY (host_component_desired_state_id) REFERENCES hostcomponentdesiredstate (id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE INDEX idx_host_component_state on hostcomponentstate(host_id, component_name, service_id, cluster_id); 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 975d0202d46..9bb13aaf20c 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql @@ -282,6 +282,7 @@ CREATE TABLE repo_tags ( CREATE TABLE servicecomponentdesiredstate ( id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, + component_type VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, service_group_id NUMBER(19) NOT NULL, service_id NUMBER(19) NOT NULL, @@ -298,6 +299,7 @@ CREATE TABLE hostcomponentdesiredstate ( id NUMBER(19) NOT NULL, cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, + component_type VARCHAR2(255) NOT NULL, desired_state VARCHAR2(255) NOT NULL, host_id NUMBER(19) NOT NULL, service_group_id NUMBER(19) NOT NULL, @@ -306,14 +308,16 @@ CREATE TABLE hostcomponentdesiredstate ( maintenance_state VARCHAR2(32) NOT NULL, restart_required NUMBER(1) DEFAULT 0 NOT NULL, CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (id), - CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_id, host_id, service_group_id, host_id, cluster_id), + CONSTRAINT UQ_hcdesiredstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE TABLE hostcomponentstate ( id NUMBER(19) NOT NULL, + host_component_desired_state_id NUMBER(19) NOT NULL, cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, + component_type VARCHAR2(255) NOT NULL, version VARCHAR2(32) DEFAULT 'UNKNOWN' NOT NULL, current_state VARCHAR2(255) NOT NULL, host_id NUMBER(19) NOT NULL, @@ -321,7 +325,9 @@ CREATE TABLE hostcomponentstate ( service_id NUMBER(19) NOT NULL, upgrade_state VARCHAR2(32) DEFAULT 'NONE' NOT NULL, CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), + CONSTRAINT UQ_hostcomponentstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), + CONSTRAINT FK_hostcomponentstate_ds_id FOREIGN KEY (host_component_desired_state_id) REFERENCES hostcomponentdesiredstate (id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE INDEX idx_host_component_state on hostcomponentstate(host_id, component_name, service_name, cluster_id); 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 2fcfaa72090..b0907a3b8e5 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -284,6 +284,7 @@ CREATE TABLE repo_tags ( CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, service_id BIGINT NOT NULL, @@ -300,6 +301,7 @@ CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, @@ -314,8 +316,10 @@ CREATE TABLE hostcomponentdesiredstate ( CREATE TABLE hostcomponentstate ( id BIGINT NOT NULL, + host_component_desired_state_id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, @@ -323,7 +327,9 @@ CREATE TABLE hostcomponentstate ( service_id BIGINT NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id), + CONSTRAINT UQ_hostcomponentstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), + CONSTRAINT FK_hostcomponentstate_ds_id FOREIGN KEY (host_component_desired_state_id) REFERENCES hostcomponentdesiredstate (id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE INDEX idx_host_component_state on hostcomponentstate(host_id, component_name, service_id, cluster_id); 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 7f0373adef5..ad0b71f4621 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql @@ -281,6 +281,7 @@ CREATE TABLE repo_tags ( CREATE TABLE servicecomponentdesiredstate ( id NUMERIC(19) NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, cluster_id NUMERIC(19) NOT NULL, service_group_id NUMERIC(19) NOT NULL, service_id NUMERIC(19) NOT NULL, @@ -297,6 +298,7 @@ CREATE TABLE hostcomponentdesiredstate ( id NUMERIC(19) NOT NULL, cluster_id NUMERIC(19) NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id NUMERIC(19) NOT NULL, service_group_id BIGINT NOT NULL, @@ -311,8 +313,10 @@ CREATE TABLE hostcomponentdesiredstate ( CREATE TABLE hostcomponentstate ( id NUMERIC(19) NOT NULL, + host_component_desired_state_id NUMERIC(19) NOT NULL, cluster_id NUMERIC(19) NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_state VARCHAR(255) NOT NULL, host_id NUMERIC(19) NOT NULL, @@ -320,7 +324,9 @@ CREATE TABLE hostcomponentstate ( service_id BIGINT NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', CONSTRAINT PK_hostcomponentstate PRIMARY KEY (id), + CONSTRAINT UQ_hostcomponentstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), + CONSTRAINT FK_hostcomponentstate_ds_id FOREIGN KEY (host_component_desired_state_id) REFERENCES hostcomponentdesiredstate (id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE INDEX idx_host_component_state on hostcomponentstate(host_id, component_name, service_name, cluster_id); 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 fdf6e470504..041011c75ca 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -147,6 +147,7 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, + stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id), @@ -295,6 +296,7 @@ CREATE TABLE repo_tags ( CREATE TABLE servicecomponentdesiredstate ( id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, service_id BIGINT NOT NULL, @@ -311,6 +313,7 @@ CREATE TABLE hostcomponentdesiredstate ( id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, service_group_id BIGINT NOT NULL, @@ -325,8 +328,10 @@ CREATE TABLE hostcomponentdesiredstate ( CREATE TABLE hostcomponentstate ( id BIGINT NOT NULL, + host_component_desired_state_id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, + component_type VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_state VARCHAR(255) NOT NULL, host_id BIGINT NOT NULL, @@ -334,7 +339,9 @@ CREATE TABLE hostcomponentstate ( service_id BIGINT NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', CONSTRAINT PK_hostcomponentstate PRIMARY KEY CLUSTERED (id), + CONSTRAINT UQ_hostcomponentstate_name UNIQUE (component_name, service_id, host_id, service_group_id, cluster_id), CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id), + CONSTRAINT FK_hostcomponentstate_ds_id FOREIGN KEY (host_component_desired_state_id) REFERENCES hostcomponentdesiredstate (id), CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_id, service_group_id, cluster_id) REFERENCES servicecomponentdesiredstate (component_name, service_id, service_group_id, cluster_id)); CREATE NONCLUSTERED INDEX idx_host_component_state on hostcomponentstate(host_id, component_name, service_name, cluster_id); diff --git a/ambari-server/src/main/resources/key_properties.json b/ambari-server/src/main/resources/key_properties.json index 6e2463bdef6..c45136cb30e 100644 --- a/ambari-server/src/main/resources/key_properties.json +++ b/ambari-server/src/main/resources/key_properties.json @@ -11,7 +11,7 @@ "ServiceGroup": "HostRoles/service_group_name", "Host": "HostRoles/host_name", "Service": "HostRoles/service_name", - "HostComponent": "HostRoles/component_name", + "HostComponent": "HostRoles/id", "Component": "HostRoles/component_name" }, "Action": { diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java index 53e09844683..e5a7fbd5bbb 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java @@ -155,11 +155,11 @@ public void teardown() throws AmbariException, SQLException { public void testHeartbeatWithConfigs() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); hdfs.getServiceComponent(SECONDARY_NAMENODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -223,7 +223,7 @@ public void testHeartbeatWithConfigs() throws Exception { public void testRestartRequiredAfterInstallClient() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(HDFS_CLIENT); + hdfs.addServiceComponent(HDFS_CLIENT, HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -287,11 +287,11 @@ public void testRestartRequiredAfterInstallClient() throws Exception { public void testHeartbeatCustomCommandWithConfigs() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); hdfs.getServiceComponent(SECONDARY_NAMENODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -370,11 +370,11 @@ public void testHeartbeatCustomCommandWithConfigs() throws Exception { public void testHeartbeatCustomStartStop() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); hdfs.getServiceComponent(SECONDARY_NAMENODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -453,11 +453,11 @@ public void testHeartbeatCustomStartStop() throws Exception { public void testStatusHeartbeat() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); hdfs.getServiceComponent(SECONDARY_NAMENODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -574,7 +574,7 @@ public void testCommandReportOnHeartbeatUpdatedState() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -692,7 +692,7 @@ public void testCommandReportOnHeartbeatUpdatedState() public void testUpgradeSpecificHandling() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -785,7 +785,7 @@ public void testUpgradeSpecificHandling() throws Exception { public void testCommandStatusProcesses() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); @@ -863,11 +863,11 @@ public void testCommandStatusProcesses() throws Exception { public void testComponentUpgradeFailReport() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(HDFS_CLIENT); + hdfs.addServiceComponent(HDFS_CLIENT, HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); ServiceComponentHost serviceComponentHost1 = clusters.getCluster(DummyCluster).getService(HDFS). @@ -974,11 +974,11 @@ public void testComponentUpgradeFailReport() throws Exception { public void testComponentUpgradeInProgressReport() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(HDFS_CLIENT); + hdfs.addServiceComponent(HDFS_CLIENT, HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); ServiceComponentHost serviceComponentHost1 = clusters.getCluster(DummyCluster).getService(HDFS). @@ -1230,10 +1230,10 @@ public void testInstallPackagesWithId() throws Exception { public void testComponentInProgressStatusSafeAfterStatusReport() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE). addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE). addServiceComponentHost(DummyHostname1); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java index 3e48ba9823c..afbb3706b21 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java @@ -186,9 +186,9 @@ public void testHeartbeat() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); - hdfs.addServiceComponent(NAMENODE); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(DATANODE, DATANODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); Collection hosts = cluster.getHosts(); assertEquals(hosts.size(), 1); @@ -237,9 +237,9 @@ public void testHeartbeat() throws Exception { public void testStatusHeartbeatWithAnnotation() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); - hdfs.addServiceComponent(NAMENODE); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(DATANODE, DATANODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); ActionQueue aq = new ActionQueue(); @@ -287,10 +287,10 @@ public void testStatusHeartbeatWithAnnotation() throws Exception { public void testLiveStatusUpdateAfterStopFailed() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE). addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, DATANODE); hdfs.getServiceComponent(NAMENODE). addServiceComponentHost(DummyHostname1); @@ -391,15 +391,15 @@ public void testRegistrationRecoveryConfig() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(NAMENODE, NAMENODE).setRecoveryEnabled(true); hdfs.getServiceComponent(NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(HDFS_CLIENT); + hdfs.addServiceComponent(HDFS_CLIENT, HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); // Create helper after creating service to avoid race condition caused by asynchronous recovery configs @@ -467,15 +467,15 @@ public void testRegistrationRecoveryConfigMaintenanceMode() /* * Add three service components enabled for auto start. */ - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(NAMENODE, NAMENODE).setRecoveryEnabled(true); hdfs.getServiceComponent(NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(HDFS_CLIENT).setRecoveryEnabled(true); + hdfs.addServiceComponent(HDFS_CLIENT, HDFS_CLIENT).setRecoveryEnabled(true); hdfs.getServiceComponent(HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); @@ -796,11 +796,11 @@ public void testStateCommandsAtRegistration() throws Exception, InvalidStateTran public void testTaskInProgressHandling() throws Exception, InvalidStateTransitionException { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); hdfs.getServiceComponent(SECONDARY_NAMENODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -852,11 +852,11 @@ public void testTaskInProgressHandling() throws Exception, InvalidStateTransitio public void testOPFailedEventForAbortedTask() throws Exception, InvalidStateTransitionException { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(SECONDARY_NAMENODE); + hdfs.addServiceComponent(SECONDARY_NAMENODE, SECONDARY_NAMENODE); hdfs.getServiceComponent(SECONDARY_NAMENODE).addServiceComponentHost(DummyHostname1); ActionQueue aq = new ActionQueue(); @@ -922,11 +922,11 @@ public void testOPFailedEventForAbortedTask() throws Exception, InvalidStateTran public void testStatusHeartbeat() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(HDFS_CLIENT); + hdfs.addServiceComponent(HDFS_CLIENT, HDFS_CLIENT); hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1); ServiceComponentHost serviceComponentHost1 = clusters.getCluster(DummyCluster).getService(HDFS). @@ -982,9 +982,9 @@ public void testRecoveryStatusReports() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Host hostObject = clusters.getHost(DummyHostname1); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); hdfs.getServiceComponent(NAMENODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); @@ -1062,9 +1062,9 @@ public void testProcessStatusReports() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Host hostObject = clusters.getHost(DummyHostname1); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE); + hdfs.addServiceComponent(NAMENODE, NAMENODE); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); hdfs.getServiceComponent(NAMENODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); @@ -1388,7 +1388,7 @@ private ComponentStatus createComponentStatus(String clusterName, String service public void testCommandStatusProcesses_empty() throws Exception { Cluster cluster = heartbeatTestHelper.getDummyCluster(); Service hdfs = addService(cluster, HDFS); - hdfs.addServiceComponent(DATANODE); + hdfs.addServiceComponent(DATANODE, DATANODE); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java index 5c96ece24ef..e4b8b2d2ea8 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java @@ -176,11 +176,11 @@ public void testStateCommandsGeneration() throws AmbariException, InterruptedExc clusters.mapAndPublishHostsToCluster(hostNames, clusterName); ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name()); + hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name(), Role.SECONDARY_NAMENODE.name()); hdfs.getServiceComponent(Role.SECONDARY_NAMENODE.name()).addServiceComponentHost(hostname1); hdfs.getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(hostname1).setState(State.INSTALLED); @@ -279,16 +279,16 @@ public void testStatusCommandForAnyComponents() throws Exception { clusters.mapAndPublishHostsToCluster(hostNames, clusterName); ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost (hostname1); - hdfs.addServiceComponent(Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost (hostname1); - hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name()); + hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name(), Role.SECONDARY_NAMENODE.name()); hdfs.getServiceComponent(Role.SECONDARY_NAMENODE.name()). addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost (hostname1); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost @@ -387,11 +387,11 @@ public void testHeartbeatStateCommandsEnqueueing() throws AmbariException, Inter ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name()); + hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name(), Role.SECONDARY_NAMENODE.name()); hdfs.getServiceComponent(Role.SECONDARY_NAMENODE.name()).addServiceComponentHost(hostname1); hdfs.getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(hostname1).setState(State.INSTALLED); @@ -469,13 +469,13 @@ public void testHeartbeatLossWithComponent() throws AmbariException, Interrupted ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name()); + hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name(), Role.SECONDARY_NAMENODE.name()); hdfs.getServiceComponent(Role.SECONDARY_NAMENODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(hostname1); ActionQueue aq = new ActionQueue(); @@ -589,11 +589,11 @@ public void testStateCommandsWithAlertsGeneration() throws AmbariException, Inte ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(hostname1); - hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name()); + hdfs.addServiceComponent(Role.SECONDARY_NAMENODE.name(), Role.SECONDARY_NAMENODE.name()); hdfs.getServiceComponent(Role.SECONDARY_NAMENODE.name()).addServiceComponentHost(hostname1); hdfs.getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(hostname1).setState(State.INSTALLED); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/MinimalRendererTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/MinimalRendererTest.java index 580de5003ae..c653f9ad325 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/MinimalRendererTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/api/query/render/MinimalRendererTest.java @@ -382,7 +382,7 @@ public void testFinalizeResult() throws Exception { Map> componentProperties = componentResource.getPropertiesMap(); assertEquals(1, componentProperties.size()); assertEquals(1, componentProperties.get("HostRoles").size()); - assertTrue(componentProperties.get("HostRoles").containsKey("component_name")); + assertTrue(componentProperties.get("HostRoles").containsKey("id")); } } } @@ -450,7 +450,7 @@ public void testFinalizeResult_propsSetOnSubResource() throws Exception { Map> componentProperties = componentResource.getPropertiesMap(); assertEquals(1, componentProperties.size()); assertEquals(1, componentProperties.get("HostRoles").size()); - assertTrue(componentProperties.get("HostRoles").containsKey("component_name")); + assertTrue(componentProperties.get("HostRoles").containsKey("id")); } } } @@ -514,21 +514,25 @@ private void createResultTree(TreeNode resultTree) throws Exception{ // host 1 components Resource nnComponentResource = new ResourceImpl(Resource.Type.HostComponent); + nnComponentResource.setProperty("HostRoles/id", 1L); nnComponentResource.setProperty("HostRoles/component_name", "NAMENODE"); nnComponentResource.setProperty("HostRoles/host_name", "testHost"); nnComponentResource.setProperty("HostRoles/cluster_name", "testCluster"); Resource dnComponentResource = new ResourceImpl(Resource.Type.HostComponent); + dnComponentResource.setProperty("HostRoles/id", 2L); dnComponentResource.setProperty("HostRoles/component_name", "DATANODE"); dnComponentResource.setProperty("HostRoles/host_name", "testHost"); dnComponentResource.setProperty("HostRoles/cluster_name", "testCluster"); Resource jtComponentResource = new ResourceImpl(Resource.Type.HostComponent); + jtComponentResource.setProperty("HostRoles/id", 3L); jtComponentResource.setProperty("HostRoles/component_name", "JOBTRACKER"); jtComponentResource.setProperty("HostRoles/host_name", "testHost"); jtComponentResource.setProperty("HostRoles/cluster_name", "testCluster"); Resource ttComponentResource = new ResourceImpl(Resource.Type.HostComponent); + ttComponentResource.setProperty("HostRoles/id", 4L); ttComponentResource.setProperty("HostRoles/component_name", "TASKTRACKER"); jtComponentResource.setProperty("HostRoles/host_name", "testHost"); jtComponentResource.setProperty("HostRoles/cluster_name", "testCluster"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java index ff3a1090b95..44befba1fc8 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java @@ -151,7 +151,7 @@ public void testServiceComponentInstalled() ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", cluster.getDesiredStackVersion()); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); // Get the recovery configuration @@ -159,7 +159,7 @@ public void testServiceComponentInstalled() assertEquals(recoveryConfig.getEnabledComponents(), "DATANODE"); // Install HDFS::NAMENODE to trigger a component installed event - hdfs.addServiceComponent(NAMENODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(NAMENODE, NAMENODE).setRecoveryEnabled(true); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); // Verify that the config is stale now @@ -186,10 +186,10 @@ public void testServiceComponentUninstalled() ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", cluster.getDesiredStackVersion().getStackId()); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(NAMENODE, NAMENODE).setRecoveryEnabled(true); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); // Get the recovery configuration @@ -223,7 +223,7 @@ public void testClusterEnvConfigChanged() ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", cluster.getDesiredStackVersion().getStackId()); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setDesiredState(State.INSTALLED); @@ -264,10 +264,10 @@ public void testMaintenanceModeChanged() ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", cluster.getDesiredStackVersion().getStackId()); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); - hdfs.addServiceComponent(NAMENODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(NAMENODE, NAMENODE).setRecoveryEnabled(true); hdfs.getServiceComponent(NAMENODE).addServiceComponentHost(DummyHostname1); // Get the recovery configuration @@ -300,7 +300,7 @@ public void testServiceComponentRecoveryChanged() ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", cluster.getDesiredStackVersion().getStackId()); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1); // Get the recovery configuration @@ -344,7 +344,7 @@ public void testMultiNodeCluster() ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", cluster.getDesiredStackVersion().getStackId()); Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion); - hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true); + hdfs.addServiceComponent(DATANODE, DATANODE).setRecoveryEnabled(true); // Add SCH to Host1 and Host2 hdfs.getServiceComponent(DATANODE).addServiceComponentHost("Host1"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java index 7a208edcf3b..0dbfc08fed4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java @@ -580,8 +580,8 @@ public void testServiceCheckRunsOnDependentClientService() throws Exception { OrmTestHelper ormTestHelper = injector.getInstance(OrmTestHelper.class); RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(new StackId("HDP-2.0.6"), "2.0.6-1234"); createService("c1", "CORE", "HADOOP_CLIENTS", repositoryVersion); - createServiceComponent("c1", "CORE", "HADOOP_CLIENTS", "SOME_CLIENT_FOR_SERVICE_CHECK", State.INIT); - createServiceComponentHost("c1", "CORE", "HADOOP_CLIENTS", "SOME_CLIENT_FOR_SERVICE_CHECK", "c1-c6403", State.INIT); + createServiceComponent("c1", "CORE", "HADOOP_CLIENTS", "SOME_CLIENT_FOR_SERVICE_CHECK", "SOME_CLIENT_FOR_SERVICE_CHECK", State.INIT); + createServiceComponentHost("c1", "CORE", "HADOOP_CLIENTS", 1L, "SOME_CLIENT_FOR_SERVICE_CHECK", "SOME_CLIENT_FOR_SERVICE_CHECK", "c1-c6403", State.INIT); //make sure there are no HDFS_CLIENT components from HDFS service Cluster c1 = clusters.getCluster("c1"); @@ -744,7 +744,7 @@ public void testCommandRepository() throws Exception { // add a repo version associated with a component ServiceComponentDesiredStateEntity componentEntity = componentDAO.findByName(cluster.getClusterId(), serviceYARN.getServiceGroupId(), - serviceYARN.getServiceId(), componentRM.getName()); + serviceYARN.getServiceId(), componentRM.getName(), componentRM.getType()); componentEntity.setDesiredRepositoryVersion(repositoryVersion); componentDAO.merge(componentEntity); @@ -788,29 +788,30 @@ private void createClusterFixture(String clusterName, StackId stackId, createService(clusterName, serviceGroupName, "ZOOKEEPER", repositoryVersion); createService(clusterName, serviceGroupName, "FLUME", repositoryVersion); - createServiceComponent(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", State.INIT); - createServiceComponent(clusterName, serviceGroupName, "YARN", "NODEMANAGER", State.INIT); - createServiceComponent(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_SERVER", State.INIT); - createServiceComponent(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_MONITOR", State.INIT); - createServiceComponent(clusterName, serviceGroupName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", State.INIT); + createServiceComponent(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", "RESOURCEMANAGER", State.INIT); + createServiceComponent(clusterName, serviceGroupName, "YARN", "NODEMANAGER", "NODEMANAGER", State.INIT); + createServiceComponent(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_SERVER", "GANGLIA_SERVER", State.INIT); + createServiceComponent(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_MONITOR", "GANGLIA_MONITOR", State.INIT); + createServiceComponent(clusterName, serviceGroupName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT", State.INIT); // this component should be not installed on any host - createServiceComponent(clusterName, serviceGroupName, "FLUME", "FLUME_HANDLER", State.INIT); + createServiceComponent(clusterName, serviceGroupName, "FLUME", "FLUME_HANDLER", "FLUME_HANDLER", State.INIT); } private void createServiceComponentHosts(String clusterName, String serviceGroupName, String hostPrefix) throws AmbariException, AuthorizationException { String hostC6401 = hostPrefix + "-c6401"; String hostC6402 = hostPrefix + "-c6402"; - createServiceComponentHost(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", hostC6401, null); - createServiceComponentHost(clusterName, serviceGroupName, "YARN", "NODEMANAGER", hostC6401, null); - createServiceComponentHost(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_SERVER", hostC6401, State.INIT); - createServiceComponentHost(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_MONITOR", hostC6401, State.INIT); - createServiceComponentHost(clusterName, serviceGroupName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", hostC6401, State.INIT); - - createServiceComponentHost(clusterName, serviceGroupName, "YARN", "NODEMANAGER", hostC6402, null); - createServiceComponentHost(clusterName, serviceGroupName, "GANGLIA", "GANGLIA_MONITOR", hostC6402, State.INIT); - createServiceComponentHost(clusterName, serviceGroupName, "ZOOKEEPER", "ZOOKEEPER_CLIENT", hostC6402, State.INIT); + // TODO : Numbers for component Id may not be correct. + createServiceComponentHost(clusterName, serviceGroupName, "YARN", 1L, "RESOURCEMANAGER", "RESOURCEMANAGER", hostC6401, null); + createServiceComponentHost(clusterName, serviceGroupName, "YARN", 2L, "NODEMANAGER", "NODEMANAGER", hostC6401, null); + createServiceComponentHost(clusterName, serviceGroupName, "GANGLIA", 3L, "GANGLIA_SERVER", "GANGLIA_SERVER", hostC6401, State.INIT); + createServiceComponentHost(clusterName, serviceGroupName, "GANGLIA", 4L, "GANGLIA_MONITOR", "GANGLIA_MONITOR", hostC6401, State.INIT); + createServiceComponentHost(clusterName, serviceGroupName, "ZOOKEEPER", 5L, "ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT", hostC6401, State.INIT); + + createServiceComponentHost(clusterName, serviceGroupName, "YARN", 6L,"NODEMANAGER", "NODEMANAGER", hostC6402, null); + createServiceComponentHost(clusterName, serviceGroupName, "GANGLIA", 7L,"GANGLIA_MONITOR", "GANGLIA_MONITOR", hostC6402, State.INIT); + createServiceComponentHost(clusterName, serviceGroupName, "ZOOKEEPER", 8L, "ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT", hostC6402, State.INIT); } private void addHost(String hostname, String clusterName) throws AmbariException { clusters.addHost(hostname); @@ -843,16 +844,17 @@ private void createService( } private void createServiceComponent( - String clusterName, String serviceGroupName, String serviceName, String componentName, State desiredState + String clusterName, String serviceGroupName, String serviceName, String componentName, String componentType, State desiredState ) throws AmbariException, AuthorizationException { - ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, desiredState != null ? desiredState.name() : null); + ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, componentType, desiredState != null ? desiredState.name() : null); ComponentResourceProviderTest.createComponents(ambariManagementController, Collections.singleton(r)); } private void createServiceComponentHost( - String clusterName, String serviceGroupName, String serviceName, String componentName, String hostname, State desiredState + String clusterName, String serviceGroupName, String serviceName, Long componentId, String componentName, String componentType, String hostname, State desiredState ) throws AmbariException, AuthorizationException { - ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, hostname, desiredState != null ? desiredState.name() : null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentId, componentName, componentType, + hostname, desiredState != null ? desiredState.name() : null); ambariManagementController.createHostComponents(Collections.singleton(r)); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java index 3d33d36352f..893a69f1a02 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java @@ -73,9 +73,13 @@ import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.internal.RequestStageContainer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; +import org.apache.ambari.server.orm.dao.HostComponentStateDAO; import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; +import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO; +import org.apache.ambari.server.orm.entities.HostComponentStateEntity; import org.apache.ambari.server.orm.entities.LdapSyncSpecEntity; import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; +import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity; import org.apache.ambari.server.registry.RegistryManager; import org.apache.ambari.server.security.authorization.Users; import org.apache.ambari.server.security.authorization.internal.InternalAuthenticationToken; @@ -136,6 +140,10 @@ public class AmbariManagementControllerImplTest { private static final Users users = createMock(Users.class); private static final AmbariSessionManager sessionManager = createNiceMock(AmbariSessionManager.class); private static final RegistryManager registryManager = createNiceMock(RegistryManager.class); + private static final HostComponentStateEntity hostComponentStateEntity = createMock(HostComponentStateEntity.class); + private static final HostComponentStateDAO hostComponentStateDAO = createMock(HostComponentStateDAO.class); + private static final ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = createMock(ServiceComponentDesiredStateEntity.class); + private static final ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = createMock(ServiceComponentDesiredStateDAO.class); @BeforeClass public static void setupAuthentication() { @@ -147,7 +155,8 @@ public static void setupAuthentication() { @Before public void before() throws Exception { - reset(ldapDataPopulator, clusters, actionDBAccessor, ambariMetaInfo, users, sessionManager); + reset(ldapDataPopulator, clusters, actionDBAccessor, ambariMetaInfo, users, sessionManager, + hostComponentStateEntity, hostComponentStateDAO, serviceComponentDesiredStateEntity, serviceComponentDesiredStateDAO); } @Test @@ -162,6 +171,9 @@ public void testgetAmbariServerURI() throws Exception { expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + //replay replay(injector); @@ -247,8 +259,11 @@ public void testGetClusters() throws Exception { CredentialStoreService credentialStoreService = createNiceMock(CredentialStoreService.class); expect(credentialStoreService.isInitialized(anyObject(CredentialStoreType.class))).andReturn(true).anyTimes(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(injector, clusters, cluster, response, credentialStoreService); + replay(injector, clusters, cluster, response, credentialStoreService, hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -263,7 +278,7 @@ public void testGetClusters() throws Exception { assertEquals(1, setResponses.size()); assertTrue(setResponses.contains(response)); - verify(injector, clusters, cluster, response, credentialStoreService); + verify(injector, clusters, cluster, response, credentialStoreService, hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -291,8 +306,11 @@ public void testGetClusters___ClusterNotFoundException() throws Exception { // getCluster expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1")); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(injector, clusters); + replay(injector, clusters, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -305,7 +323,7 @@ public void testGetClusters___ClusterNotFoundException() throws Exception { // expected } - verify(injector, clusters); + verify(injector, clusters, hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -354,8 +372,12 @@ public void testGetClusters___OR_Predicate_ClusterNotFoundException() throws Exc CredentialStoreService credentialStoreService = createNiceMock(CredentialStoreService.class); expect(credentialStoreService.isInitialized(anyObject(CredentialStoreType.class))).andReturn(true).anyTimes(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(injector, clusters, cluster, cluster2, response, response2, credentialStoreService); + replay(injector, clusters, cluster, cluster2, response, response2, credentialStoreService, + hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -372,7 +394,8 @@ public void testGetClusters___OR_Predicate_ClusterNotFoundException() throws Exc assertTrue(setResponses.contains(response)); assertTrue(setResponses.contains(response2)); - verify(injector, clusters, cluster, cluster2, response, response2, credentialStoreService); + verify(injector, clusters, cluster, cluster2, response, response2, credentialStoreService, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -409,6 +432,9 @@ public void testUpdateClusters() throws Exception { expect(clusters.getClusterById(1L)).andReturn(cluster).times(1); expect(cluster.getClusterName()).andReturn("clusterOld").times(1); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + cluster.setClusterName("clusterNew"); expectLastCall(); @@ -416,7 +442,8 @@ public void testUpdateClusters() throws Exception { expectLastCall(); // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, configurationRequest); + replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, configurationRequest, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -424,7 +451,8 @@ public void testUpdateClusters() throws Exception { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, configurationRequest); + verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, configurationRequest, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -457,6 +485,9 @@ public void testUpdateClustersWithNullConfigPropertyValues() throws Exception { expect(clusterRequest.getClusterName()).andReturn("clusterNew").anyTimes(); expect(clusterRequest.getClusterId()).andReturn(1L).anyTimes(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + ConfigurationRequest configReq = new ConfigurationRequest(); final Map configReqProps = Maps.newHashMap(); configReqProps.put("p1", null); @@ -479,7 +510,8 @@ public void testUpdateClustersWithNullConfigPropertyValues() throws Exception { expectLastCall(); // replay mocks - replay(actionManager, cluster, clusters, config, injector, clusterRequest, sessionManager); + replay(actionManager, cluster, clusters, config, injector, clusterRequest, sessionManager, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -487,7 +519,8 @@ public void testUpdateClustersWithNullConfigPropertyValues() throws Exception { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, config, injector, clusterRequest, sessionManager); + verify(actionManager, cluster, clusters, config, injector, clusterRequest, sessionManager, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -516,8 +549,12 @@ public void testUpdateClustersToggleKerberosNotInvoked() throws Exception { expect(clusters.getClusterById(1L)).andReturn(cluster).times(1); expect(cluster.getClusterName()).andReturn("cluster").times(1); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -525,7 +562,8 @@ public void testUpdateClustersToggleKerberosNotInvoked() throws Exception { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -557,6 +595,9 @@ public void testUpdateClustersToggleKerberosReenable() throws Exception { expect(cluster.getClusterName()).andReturn("cluster").times(1); expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.KERBEROS, null)) .andReturn(false) .once(); @@ -566,7 +607,8 @@ public void testUpdateClustersToggleKerberosReenable() throws Exception { // Note: kerberosHelper.toggleKerberos is not called // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -574,7 +616,8 @@ public void testUpdateClustersToggleKerberosReenable() throws Exception { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** * Ensure that when the cluster security type updated from NONE to KERBEROS, KerberosHandler.toggleKerberos @@ -604,6 +647,9 @@ public void testUpdateClustersToggleKerberosEnable() throws Exception { expect(cluster.getClusterName()).andReturn("cluster").times(1); expect(cluster.getSecurityType()).andReturn(SecurityType.NONE).anyTimes(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.KERBEROS, null)) .andReturn(false) .once(); @@ -617,8 +663,12 @@ public void testUpdateClustersToggleKerberosEnable() throws Exception { .andReturn(null) .once(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -626,7 +676,8 @@ public void testUpdateClustersToggleKerberosEnable() throws Exception { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -685,6 +736,9 @@ private void testUpdateClustersToggleKerberosDisable(Boolean manageIdentities) t expect(cluster.getClusterName()).andReturn("cluster").times(1); expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.NONE, null)) .andReturn(false) .once(); @@ -761,8 +815,12 @@ public void testUpdateClustersToggleKerberos_Fail() throws Exception { .andThrow(new IllegalArgumentException("bad args!")) .once(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -776,7 +834,8 @@ public void testUpdateClustersToggleKerberos_Fail() throws Exception { // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper); + verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, kerberosHelper, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -804,11 +863,15 @@ public void testUpdateClusters__RollbackException() throws Exception { expect(clusterRequest.getClusterId()).andReturn(1L).times(4); expect(clusters.getClusterById(1L)).andReturn(cluster).times(1); expect(cluster.getClusterName()).andReturn("clusterOld").times(1); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + cluster.setClusterName("clusterNew"); expectLastCall().andThrow(new RollbackException()); // replay mocks - replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager); + replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, + hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector); @@ -820,7 +883,8 @@ public void testUpdateClusters__RollbackException() throws Exception { } // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager); + verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -842,7 +906,7 @@ public void testGetHostComponents() throws Exception { // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", 1L, "component1", "component1", "host1", null); Set setRequests = new HashSet<>(); setRequests.add(request1); @@ -855,6 +919,19 @@ public void testGetHostComponents() throws Exception { expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper).anyTimes(); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(hostComponentStateDAO.findById(1L)).andReturn(hostComponentStateEntity).anyTimes(); + expect(hostComponentStateEntity.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getComponentName()).andReturn("component1").anyTimes(); + expect(hostComponentStateEntity.getComponentType()).andReturn("component1").anyTimes(); + + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component1", "component1")).andReturn(serviceComponentDesiredStateEntity).anyTimes(); + expect(serviceComponentDesiredStateEntity.getId()).andReturn(1L).times(2); + // getHostComponent expect(clusters.getCluster("cluster1")).andReturn(cluster); expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)); @@ -867,7 +944,7 @@ public void testGetHostComponents() throws Exception { expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes(); expect(service.getName()).andReturn("service1").anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component); - expect(component.getName()).andReturn("component1"); + expect(component.getId()).andReturn(1L).times(2); expect(component.getServiceComponentHosts()).andReturn( new HashMap() {{ put("host1", componentHost); @@ -878,7 +955,8 @@ public void testGetHostComponents() throws Exception { // replay mocks replay(maintHelper, injector, clusters, cluster, host, response, stack, - ambariMetaInfo, service, component, componentHost); + ambariMetaInfo, service, component, componentHost, hostComponentStateDAO, hostComponentStateEntity, + serviceComponentDesiredStateDAO, serviceComponentDesiredStateEntity); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -891,7 +969,9 @@ public void testGetHostComponents() throws Exception { assertEquals(1, setResponses.size()); assertTrue(setResponses.contains(response)); - verify(injector, clusters, cluster, host, response, stack, ambariMetaInfo, service, component, componentHost); + verify(injector, clusters, cluster, host, response, stack, ambariMetaInfo, service, component, componentHost, + hostComponentStateDAO, hostComponentStateEntity, serviceComponentDesiredStateDAO, + serviceComponentDesiredStateEntity); } @Test @@ -909,7 +989,7 @@ public void testGetHostComponents___ServiceComponentHostNotFoundException() thro // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", 1L, "component1", "component1", "host1", null); Set setRequests = new HashSet<>(); @@ -934,12 +1014,26 @@ public void testGetHostComponents___ServiceComponentHostNotFoundException() thro expect(cluster.getService("service1")).andReturn(service); expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component); - expect(component.getName()).andReturn("component1").anyTimes(); + expect(component.getId()).andReturn(1L).anyTimes(); expect(component.getServiceComponentHosts()).andReturn(null); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(hostComponentStateDAO.findById(1L)).andReturn(hostComponentStateEntity).anyTimes(); + expect(hostComponentStateEntity.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getComponentName()).andReturn("component1").anyTimes(); + expect(hostComponentStateEntity.getComponentType()).andReturn("component1").anyTimes(); + + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component1", "component1")).andReturn(serviceComponentDesiredStateEntity).anyTimes(); + expect(serviceComponentDesiredStateEntity.getId()).andReturn(1L).anyTimes(); + // replay mocks replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, - service, component); + service, component, hostComponentStateDAO, hostComponentStateEntity, serviceComponentDesiredStateDAO, + serviceComponentDesiredStateEntity); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -954,7 +1048,9 @@ public void testGetHostComponents___ServiceComponentHostNotFoundException() thro // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component); + verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, + hostComponentStateDAO, hostComponentStateEntity, serviceComponentDesiredStateDAO, + serviceComponentDesiredStateEntity); } @Test @@ -974,7 +1070,7 @@ public void testGetHostComponents___ServiceComponentHostFilteredByState() throws // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", "component1", "component1", "host1", null); request1.setState("INSTALLED"); @@ -1018,9 +1114,12 @@ public void testGetHostComponents___ServiceComponentHostFilteredByState() throws expect(componentHost1.convertToResponse(null)).andReturn(response1); expect(componentHost1.getHostName()).andReturn("host1"); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, - service, component, componentHost1, response1); + service, component, componentHost1, response1, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1031,7 +1130,8 @@ public void testGetHostComponents___ServiceComponentHostFilteredByState() throws // assert and verify assertSame(controller, controllerCapture.getValue()); assertTrue(responses.size() == 1); - verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1); + verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -1051,7 +1151,7 @@ public void testGetHostComponents___ServiceComponentHostFilteredByMaintenanceSta // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", "component1", "component1", "host1", null); request1.setMaintenanceState("ON"); @@ -1089,9 +1189,12 @@ public void testGetHostComponents___ServiceComponentHostFilteredByMaintenanceSta expect(componentHost1.convertToResponse(null)).andReturn(response1); expect(componentHost1.getHostName()).andReturn("host1"); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, - service, component, componentHost1, response1); + service, component, componentHost1, response1, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1102,7 +1205,8 @@ public void testGetHostComponents___ServiceComponentHostFilteredByMaintenanceSta // assert and verify assertSame(controller, controllerCapture.getValue()); assertTrue(responses.size() == 1); - verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1); + verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component, componentHost1, response1, + hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -1135,13 +1239,13 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundExc // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", 1L, "component1", "component1", "host1", null); ServiceComponentHostRequest request2 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component2", "host1", null); + "cluster1", "CORE", "service1", 2L, "component2", "component2","host1", null); ServiceComponentHostRequest request3 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component3", "host1", null); + "cluster1", "CORE", "service1", 3L, "component3", "component3", "host1", null); Set setRequests = new HashSet<>(); @@ -1165,7 +1269,6 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundExc expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component1); expect(service.getName()).andReturn("service1").anyTimes(); - expect(component1.getName()).andReturn("component1"); expect(component1.getServiceComponentHosts()).andReturn( new HashMap() {{ put("host1", componentHost1); @@ -1175,23 +1278,60 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundExc expect(cluster.getServiceByComponentName("component2")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component2")).andReturn(component2); - expect(component2.getName()).andReturn("component2"); expect(component2.getServiceComponentHosts()).andReturn(null); expect(componentHost2.getHostName()).andReturn("host1"); expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component3")).andReturn(component3); - expect(component3.getName()).andReturn("component3"); expect(component3.getServiceComponentHosts()).andReturn( new HashMap() {{ put("host1", componentHost2); }}); expect(componentHost2.convertToResponse(null)).andReturn(response2); + HostComponentStateEntity hostComponentStateEntity2 = createNiceMock(HostComponentStateEntity.class); + HostComponentStateEntity hostComponentStateEntity3 = createNiceMock(HostComponentStateEntity.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(hostComponentStateDAO.findById(1L)).andReturn(hostComponentStateEntity).anyTimes(); + expect(hostComponentStateDAO.findById(2L)).andReturn(hostComponentStateEntity2).anyTimes(); + expect(hostComponentStateDAO.findById(3L)).andReturn(hostComponentStateEntity3).anyTimes(); + + expect(hostComponentStateEntity.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getComponentName()).andReturn("component1").anyTimes(); + expect(hostComponentStateEntity.getComponentType()).andReturn("component1").anyTimes(); + + expect(hostComponentStateEntity2.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getComponentName()).andReturn("component2").anyTimes(); + expect(hostComponentStateEntity2.getComponentType()).andReturn("component2").anyTimes(); + + expect(hostComponentStateEntity3.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getComponentName()).andReturn("component3").anyTimes(); + expect(hostComponentStateEntity3.getComponentType()).andReturn("component3").anyTimes(); + + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component1", "component1")).andReturn(serviceComponentDesiredStateEntity).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity2 = createMock(ServiceComponentDesiredStateEntity.class); + + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component2", "component2")).andReturn(serviceComponentDesiredStateEntity2).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity3 = createMock(ServiceComponentDesiredStateEntity.class); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component3", "component3")).andReturn(serviceComponentDesiredStateEntity3).anyTimes(); + expect(serviceComponentDesiredStateEntity.getId()).andReturn(1L).times(2); + // replay mocks replay(stateHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, service, component1, component2, component3, componentHost1, - componentHost2, response1, response2); + componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1206,7 +1346,8 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundExc assertTrue(setResponses.contains(response2)); verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component1, component2, component3, - componentHost1, componentHost2, response1, response2); + componentHost1, componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); } @Test @@ -1234,13 +1375,13 @@ public void testGetHostComponents___OR_Predicate_ServiceNotFoundException() thro // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", 1L, "component1", "component1", "host1", null); ServiceComponentHostRequest request2 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service2", "component2", "host1", null); + "cluster1", "CORE", "service2", 2L, "component2", "component2", "host1", null); ServiceComponentHostRequest request3 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component3", "host1", null); + "cluster1", "CORE", "service1", 3L, "component3", "component3", "host1", null); Set setRequests = new HashSet<>(); @@ -1270,7 +1411,6 @@ public void testGetHostComponents___OR_Predicate_ServiceNotFoundException() thro expect(cluster.getService("service1")).andReturn(service); expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component1); - expect(component1.getName()).andReturn("component1"); expect(component1.getServiceComponentHosts()).andReturn(new HashMap() {{ put("host1", componentHost1); @@ -1284,7 +1424,6 @@ public void testGetHostComponents___OR_Predicate_ServiceNotFoundException() thro expect(service.getName()).andReturn("service1").anyTimes(); expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component3")).andReturn(component3); - expect(component3.getName()).andReturn("component3"); expect(component3.getServiceComponentHosts()).andReturn(new HashMap() {{ put("host1", componentHost2); @@ -1292,10 +1431,49 @@ public void testGetHostComponents___OR_Predicate_ServiceNotFoundException() thro expect(componentHost2.convertToResponse(null)).andReturn(response2); expect(componentHost2.getHostName()).andReturn("host1"); + HostComponentStateEntity hostComponentStateEntity2 = createNiceMock(HostComponentStateEntity.class); + HostComponentStateEntity hostComponentStateEntity3 = createNiceMock(HostComponentStateEntity.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(hostComponentStateDAO.findById(1L)).andReturn(hostComponentStateEntity).anyTimes(); + expect(hostComponentStateDAO.findById(2L)).andReturn(hostComponentStateEntity2).anyTimes(); + expect(hostComponentStateDAO.findById(3L)).andReturn(hostComponentStateEntity3).anyTimes(); + + expect(hostComponentStateEntity.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getComponentName()).andReturn("component1").anyTimes(); + expect(hostComponentStateEntity.getComponentType()).andReturn("component1").anyTimes(); + + expect(hostComponentStateEntity2.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getComponentName()).andReturn("component2").anyTimes(); + expect(hostComponentStateEntity2.getComponentType()).andReturn("component2").anyTimes(); + + expect(hostComponentStateEntity3.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getComponentName()).andReturn("component3").anyTimes(); + expect(hostComponentStateEntity3.getComponentType()).andReturn("component3").anyTimes(); + + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component1", "component1")).andReturn(serviceComponentDesiredStateEntity).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity2 = createMock(ServiceComponentDesiredStateEntity.class); + + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component2", "component2")).andReturn(serviceComponentDesiredStateEntity2).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity3 = createMock(ServiceComponentDesiredStateEntity.class); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component3", "component3")).andReturn(serviceComponentDesiredStateEntity3).anyTimes(); + expect(serviceComponentDesiredStateEntity.getId()).andReturn(1L).times(2); + // replay mocks replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, service, component1, component2, component3, componentHost1, - componentHost2, response1, response2); + componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1310,7 +1488,8 @@ public void testGetHostComponents___OR_Predicate_ServiceNotFoundException() thro assertTrue(setResponses.contains(response2)); verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, component1, component2, component3, - componentHost1, componentHost2, response1, response2); + componentHost1, componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); } @Test @@ -1340,13 +1519,13 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentNotFoundExcepti // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", 1L, "component1", "component1", "host1", null); ServiceComponentHostRequest request2 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service2", "component2", "host1", null); + "cluster1", "CORE", "service2", 2L, "component2", "component2", "host1", null); ServiceComponentHostRequest request3 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component3", "host1", null); + "cluster1", "CORE", "service1", 3L, "component3", "component3", "host1", null); Set setRequests = new HashSet<>(); @@ -1376,7 +1555,6 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentNotFoundExcepti expect(cluster.getService("service1")).andReturn(service); expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component); - expect(component.getName()).andReturn("component1"); expect(component.getServiceComponentHosts()).andReturn(ImmutableMap.builder() .put("host1", componentHost1) .build()); @@ -1394,17 +1572,55 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentNotFoundExcepti expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component3")).andReturn(component3); - expect(component3.getName()).andReturn("component3"); expect(component3.getServiceComponentHosts()).andReturn(ImmutableMap.builder() .put("host1", componentHost2) .build()); expect(componentHost2.convertToResponse(null)).andReturn(response2); expect(componentHost2.getHostName()).andReturn("host1"); + HostComponentStateEntity hostComponentStateEntity2 = createNiceMock(HostComponentStateEntity.class); + HostComponentStateEntity hostComponentStateEntity3 = createNiceMock(HostComponentStateEntity.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(hostComponentStateDAO.findById(1L)).andReturn(hostComponentStateEntity).anyTimes(); + expect(hostComponentStateDAO.findById(2L)).andReturn(hostComponentStateEntity2).anyTimes(); + expect(hostComponentStateDAO.findById(3L)).andReturn(hostComponentStateEntity3).anyTimes(); + + expect(hostComponentStateEntity.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getComponentName()).andReturn("component1").anyTimes(); + expect(hostComponentStateEntity.getComponentType()).andReturn("component1").anyTimes(); + + expect(hostComponentStateEntity2.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getComponentName()).andReturn("component2").anyTimes(); + expect(hostComponentStateEntity2.getComponentType()).andReturn("component2").anyTimes(); + + expect(hostComponentStateEntity3.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getComponentName()).andReturn("component3").anyTimes(); + expect(hostComponentStateEntity3.getComponentType()).andReturn("component3").anyTimes(); + + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component1", "component1")).andReturn(serviceComponentDesiredStateEntity).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity2 = createMock(ServiceComponentDesiredStateEntity.class); + + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component2", "component2")).andReturn(serviceComponentDesiredStateEntity2).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity3 = createMock(ServiceComponentDesiredStateEntity.class); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component3", "component3")).andReturn(serviceComponentDesiredStateEntity3).anyTimes(); + expect(serviceComponentDesiredStateEntity.getId()).andReturn(1L).times(2); + // replay mocks replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, service, service2, component, component2, component3, componentHost1, - componentHost2, response1, response2); + componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1419,7 +1635,8 @@ public void testGetHostComponents___OR_Predicate_ServiceComponentNotFoundExcepti assertTrue(setResponses.contains(response2)); verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, service2, component, component2, component3, - componentHost1, componentHost2, response1, response2); + componentHost1, componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); } @Test @@ -1448,13 +1665,13 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", null, null); + "cluster1", "CORE", "service1", 1L, "component1", "component1", null, null); ServiceComponentHostRequest request2 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component2", "host2", null); + "cluster1", "CORE", "service1", 2L, "component2", "component2", "host2", null); ServiceComponentHostRequest request3 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component3", null, null); + "cluster1", "CORE", "service1", 3L, "component3", "component3", null, null); Set setRequests = new HashSet<>(); @@ -1484,7 +1701,6 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component1")).andReturn(component); expect(service.getName()).andReturn("service1").anyTimes(); - expect(component.getName()).andReturn("component1"); expect(component.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost1)); expect(componentHost1.convertToResponse(null)).andReturn(response1); expect(componentHost1.getHostName()).andReturn("host1"); @@ -1494,15 +1710,53 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi expect(cluster.getService("service1")).andReturn(service); expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes(); expect(service.getServiceComponent("component3")).andReturn(component3); - expect(component3.getName()).andReturn("component3"); expect(component3.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost2)); expect(componentHost2.convertToResponse(null)).andReturn(response2); expect(componentHost2.getHostName()).andReturn("host1"); + HostComponentStateEntity hostComponentStateEntity2 = createNiceMock(HostComponentStateEntity.class); + HostComponentStateEntity hostComponentStateEntity3 = createNiceMock(HostComponentStateEntity.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(hostComponentStateDAO.findById(1L)).andReturn(hostComponentStateEntity).anyTimes(); + expect(hostComponentStateDAO.findById(2L)).andReturn(hostComponentStateEntity2).anyTimes(); + expect(hostComponentStateDAO.findById(3L)).andReturn(hostComponentStateEntity3).anyTimes(); + + expect(hostComponentStateEntity.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity.getComponentName()).andReturn("component1").anyTimes(); + expect(hostComponentStateEntity.getComponentType()).andReturn("component1").anyTimes(); + + expect(hostComponentStateEntity2.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity2.getComponentName()).andReturn("component2").anyTimes(); + expect(hostComponentStateEntity2.getComponentType()).andReturn("component2").anyTimes(); + + expect(hostComponentStateEntity3.getClusterId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceGroupId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getServiceId()).andReturn(1L).anyTimes(); + expect(hostComponentStateEntity3.getComponentName()).andReturn("component3").anyTimes(); + expect(hostComponentStateEntity3.getComponentType()).andReturn("component3").anyTimes(); + + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component1", "component1")).andReturn(serviceComponentDesiredStateEntity).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity2 = createMock(ServiceComponentDesiredStateEntity.class); + + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component2", "component2")).andReturn(serviceComponentDesiredStateEntity2).anyTimes(); + ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity3 = createMock(ServiceComponentDesiredStateEntity.class); + expect(serviceComponentDesiredStateDAO.findByName(1L, 1L, 1L, + "component3", "component3")).andReturn(serviceComponentDesiredStateEntity3).anyTimes(); + expect(serviceComponentDesiredStateEntity.getId()).andReturn(1L).times(2); + // replay mocks replay(maintHelper, injector, clusters, cluster, host, stack, ambariMetaInfo, service, service2, component, component2, component3, componentHost1, - componentHost2, response1, response2); + componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1518,7 +1772,8 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi assertTrue(setResponses.contains(response2)); verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service, service2, component, component2, component3, - componentHost1, componentHost2, response1, response2); + componentHost1, componentHost2, response1, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO, + hostComponentStateEntity, hostComponentStateEntity2, hostComponentStateEntity3); } @Test @@ -1533,13 +1788,13 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", "component1", "component1", "host1", null); ServiceComponentHostRequest request2 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component2", "host1", null); + "cluster1", "CORE", "service1", "component2", "component2", "host1", null); ServiceComponentHostRequest request3 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component3", "host1", null); + "cluster1", "CORE", "service1", "component3", "component3", "host1", null); Set setRequests = new HashSet<>(); @@ -1554,12 +1809,15 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // getHostComponent expect(clusters.getCluster("cluster1")).andReturn(cluster); expect(clusters.getClustersForHost("host1")).andThrow(new HostNotFoundException("host1")); // replay mocks - replay(maintHelper, injector, clusters, cluster, stack, ambariMetaInfo); + replay(maintHelper, injector, clusters, cluster, stack, ambariMetaInfo, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1575,7 +1833,7 @@ public void testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvi // assert and verify assertSame(controller, controllerCapture.getValue()); - verify(injector, clusters, cluster, stack, ambariMetaInfo); + verify(injector, clusters, cluster, stack, ambariMetaInfo, hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -1588,13 +1846,13 @@ public void testGetHostComponents___OR_Predicate_ClusterNotFoundException() thro // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", "host1", null); + "cluster1", "CORE", "service1", "component1", "component1", "host1", null); ServiceComponentHostRequest request2 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component2", "host2", null); + "cluster1", "CORE", "service1", "component2", "component2", "host2", null); ServiceComponentHostRequest request3 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component3", "host1", null); + "cluster1", "CORE", "service1", "component3", "component3", "host1", null); Set setRequests = new HashSet<>(); @@ -1612,6 +1870,9 @@ public void testGetHostComponents___OR_Predicate_ClusterNotFoundException() thro // getHostComponent expect(clusters.getCluster("cluster1")).andThrow(new ClusterNotFoundException("cluster1")); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks replay(maintHelper, injector, clusters, stack, ambariMetaInfo); @@ -1653,7 +1914,7 @@ public void testGetHostComponents___NullHostName() throws Exception { // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", "service1", "component1", null, null); + "cluster1", "CORE", "service1", "component1", "component1", null, null); Set setRequests = new HashSet<>(); @@ -1689,9 +1950,13 @@ public void testGetHostComponents___NullHostName() throws Exception { expect(componentHost1.getHostName()).andReturn("host1"); expect(componentHost2.getHostName()).andReturn("host1"); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks replay(maintHelper, injector, clusters, cluster, response1, response2, - stack, ambariMetaInfo, service, component, componentHost1, componentHost2); + stack, ambariMetaInfo, service, component, componentHost1, componentHost2, + hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1705,7 +1970,8 @@ public void testGetHostComponents___NullHostName() throws Exception { assertTrue(setResponses.contains(response1)); assertTrue(setResponses.contains(response2)); - verify(injector, clusters, cluster, response1, response2, stack, ambariMetaInfo, service, component, componentHost1, componentHost2); + verify(injector, clusters, cluster, response1, response2, stack, ambariMetaInfo, service, component, componentHost1, + componentHost2, hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -1733,7 +1999,7 @@ public void testGetHostComponents___NullHostName_NullComponentName() throws Exce // requests ServiceComponentHostRequest request1 = new ServiceComponentHostRequest( - "cluster1", "CORE", null, null, null, null); + "cluster1", "CORE", null, null, null, null, null); Set setRequests = new HashSet<>(); @@ -1776,13 +2042,16 @@ public void testGetHostComponents___NullHostName_NullComponentName() throws Exce expect(componentHost2.getHostName()).andReturn("host1"); expect(componentHost3.getHostName()).andReturn("host1"); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(component2.getServiceComponentHosts()).andReturn(Collections.singletonMap("foobar", componentHost3)); expect(componentHost3.convertToResponse(null)).andReturn(response3); // replay mocks replay(maintHelper, injector, clusters, cluster, response1, response2, response3, stack, ambariMetaInfo, service1, service2, component1, component2, - componentHost1, componentHost2, componentHost3); + componentHost1, componentHost2, componentHost3, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -1798,7 +2067,7 @@ public void testGetHostComponents___NullHostName_NullComponentName() throws Exce assertTrue(setResponses.contains(response3)); verify(injector, clusters, cluster, response1, response2, response3, stack, ambariMetaInfo, service1, service2, - component1, component2, componentHost1, componentHost2, componentHost3); + component1, component2, componentHost1, componentHost2, componentHost3, hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -1845,15 +2114,19 @@ public void testPopulatePackagesInfo() throws Exception { expect(serviceInfo.getOsSpecifics()).andReturn(osSpecificsService); expect(stackInfo.getOsSpecifics()).andReturn(osSpecificsStack); + injector.injectMembers(capture(controllerCapture)); expect(injector.getInstance(Gson.class)).andReturn(null); expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper).anyTimes(); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + OsFamily osFamilyMock = createNiceMock(OsFamily.class); EasyMock.expect(osFamilyMock.isVersionedOsFamilyExtendedByVersionedFamily("testOSFamily", "testOSFamily")).andReturn(true).times(3); - replay(maintHelper, injector, clusters, stackInfo, serviceInfo, osFamilyMock); + replay(maintHelper, injector, clusters, stackInfo, serviceInfo, osFamilyMock, hostComponentStateDAO, serviceComponentDesiredStateDAO); AmbariManagementControllerImplTest.NestedTestClass nestedTestClass = this.new NestedTestClass(null, clusters, injector, osFamilyMock); @@ -2000,7 +2273,8 @@ public void testSynchronizeLdapUsersAndGroups() throws Exception { expectLastCall().anyTimes(); //replay - replay(ldapDataPopulator, clusters, actionDBAccessor, ambariMetaInfo, users, ldapBatchDto); + replay(ldapDataPopulator, clusters, actionDBAccessor, ambariMetaInfo, users, ldapBatchDto, + hostComponentStateDAO, serviceComponentDesiredStateDAO); AmbariManagementControllerImpl controller = injector.getInstance(AmbariManagementControllerImpl.class); @@ -2019,7 +2293,7 @@ public void testSynchronizeLdapUsersAndGroups() throws Exception { controller.synchronizeLdapUsersAndGroups(userRequest, groupRequest); - verify(ldapDataPopulator, clusters, users, ldapBatchDto); + verify(ldapDataPopulator, clusters, users, ldapBatchDto, hostComponentStateDAO, serviceComponentDesiredStateDAO); } private void setAmbariMetaInfo(AmbariMetaInfo metaInfo, AmbariManagementController controller) throws NoSuchFieldException, IllegalAccessException { @@ -2041,6 +2315,10 @@ public void configure(Binder binder) { binder.bind(Users.class).toInstance(users); binder.bind(AmbariSessionManager.class).toInstance(sessionManager); binder.bind(RegistryManager.class).toInstance(registryManager); + binder.bind(HostComponentStateEntity.class).toInstance(hostComponentStateEntity); + binder.bind(HostComponentStateDAO.class).toInstance(hostComponentStateDAO); + binder.bind(ServiceComponentDesiredStateEntity.class).toInstance(serviceComponentDesiredStateEntity); + binder.bind(ServiceComponentDesiredStateDAO.class).toInstance(serviceComponentDesiredStateDAO); } } @@ -2071,12 +2349,15 @@ public void testVerifyRepositories() throws Exception { expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + Configuration configuration = createNiceMock(Configuration.class); String[] suffices = {"/repodata/repomd.xml"}; expect(configuration.getRepoValidationSuffixes("redhat6")).andReturn(suffices); // replay mocks - replay(injector, clusters, ambariMetaInfo, configuration); + replay(injector, clusters, ambariMetaInfo, configuration, hostComponentStateDAO, serviceComponentDesiredStateDAO); // test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -2101,7 +2382,7 @@ public void testVerifyRepositories() throws Exception { Assert.assertEquals("Could not access base url . file:///some/repo/repodata/repomd.xml . ", e.getMessage()); } - verify(injector, clusters, ambariMetaInfo, configuration); + verify(injector, clusters, ambariMetaInfo, configuration, hostComponentStateDAO, serviceComponentDesiredStateDAO); } @Test @@ -2122,6 +2403,9 @@ public void testRegisterRackChange() throws Exception { expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + RepositoryInfo dummyRepoInfo = new RepositoryInfo(); dummyRepoInfo.setRepoName("repo_name"); @@ -2253,6 +2537,8 @@ public void testGetPacklets() throws Exception { samplePacklet.setDefinition("nifi.tar.gz"); packletArrayList.add(samplePacklet); expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).atLeastOnce(); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); expect(ambariMetaInfo.getModules(mpackId)).andReturn(packletArrayList).atLeastOnce(); replay(ambariMetaInfo,injector); AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index 9c6f495d091..cd3391eb579 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -21,6 +21,7 @@ import static java.util.stream.Collectors.toSet; import static org.easymock.EasyMock.capture; +import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.createStrictMock; import static org.easymock.EasyMock.expect; @@ -102,9 +103,11 @@ import org.apache.ambari.server.orm.OrmTestHelper; import org.apache.ambari.server.orm.dao.ClusterServiceDAO; import org.apache.ambari.server.orm.dao.ExecutionCommandDAO; +import org.apache.ambari.server.orm.dao.HostComponentStateDAO; import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.dao.HostRoleCommandDAO; import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; +import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO; import org.apache.ambari.server.orm.dao.ServiceGroupDAO; import org.apache.ambari.server.orm.dao.StackDAO; import org.apache.ambari.server.orm.dao.TopologyHostInfoDAO; @@ -410,7 +413,7 @@ private void createServiceComponent(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, - serviceName, componentName, dStateStr); + serviceName, componentName, componentName, dStateStr); ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r)); } @@ -423,7 +426,7 @@ private void createServiceComponentHost(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, - serviceName, componentName, hostname, dStateStr); + serviceName, componentName, componentName, hostname, dStateStr); controller.createHostComponents(Collections.singleton(r)); } @@ -436,7 +439,7 @@ private void deleteServiceComponentHost(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, - serviceName, componentName, hostname, dStateStr); + serviceName, componentName, componentName, hostname, dStateStr); controller.deleteHostComponents(Collections.singleton(r)); } @@ -506,7 +509,7 @@ private long stopServiceComponentHosts(String clusterName, String serviceGroupNa for (ServiceComponent sc : s.getServiceComponents().values()) { for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) { ServiceComponentHostRequest schr = new ServiceComponentHostRequest - (clusterName, serviceGroupName, serviceName, sc.getName(), + (clusterName, serviceGroupName, serviceName, sc.getName(), sc.getType(), sch.getHostName(), State.INSTALLED.name()); requests.add(schr); } @@ -952,7 +955,7 @@ public void testCreateServiceComponentSimple() throws Exception { .getService(serviceName).getServiceComponent(componentName)); ServiceComponentRequest r = - new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, null, null); + new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, null, null, null); Set response = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(1, response.size()); @@ -991,7 +994,7 @@ public void testCreateServiceComponentWithInvalidRequest() try { set1.clear(); ServiceComponentRequest rInvalid = - new ServiceComponentRequest(cluster1, null, null, null, null); + new ServiceComponentRequest(cluster1, null, null, null, null, null); set1.add(rInvalid); ComponentResourceProviderTest.createComponents(controller, set1); fail("Expected failure for invalid requests"); @@ -1002,7 +1005,7 @@ public void testCreateServiceComponentWithInvalidRequest() try { set1.clear(); ServiceComponentRequest rInvalid = - new ServiceComponentRequest(cluster1, "s1", null, null, null); + new ServiceComponentRequest(cluster1, "s1", null, null, null, null); set1.add(rInvalid); ComponentResourceProviderTest.createComponents(controller, set1); fail("Expected failure for invalid requests"); @@ -1052,11 +1055,11 @@ public void testCreateServiceComponentWithInvalidRequest() set1.clear(); ServiceComponentRequest valid1 = - new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", null); ServiceComponentRequest valid2 = - new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "JOBTRACKER", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "JOBTRACKER", "JOBTRACKER", null); ServiceComponentRequest valid3 = - new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "TASKTRACKER", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "TASKTRACKER", "TASKTRACKER", null); set1.add(valid1); set1.add(valid2); set1.add(valid3); @@ -1065,9 +1068,9 @@ public void testCreateServiceComponentWithInvalidRequest() try { set1.clear(); ServiceComponentRequest rInvalid1 = - new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "HDFS_CLIENT", State.INSTALLED.name()); + new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", null); ServiceComponentRequest rInvalid2 = - new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "HDFS_CLIENT", State.STARTED.name()); + new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", null); set1.add(rInvalid1); set1.add(rInvalid2); ComponentResourceProviderTest.createComponents(controller, set1); @@ -1079,9 +1082,9 @@ public void testCreateServiceComponentWithInvalidRequest() try { set1.clear(); ServiceComponentRequest rInvalid1 = - new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "HDFS_CLIENT", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", null); ServiceComponentRequest rInvalid2 = - new ServiceComponentRequest(cluster2, serviceGroupName, "HDFS", "HDFS_CLIENT", null); + new ServiceComponentRequest(cluster2, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", null); set1.add(rInvalid1); set1.add(rInvalid2); ComponentResourceProviderTest.createComponents(controller, set1); @@ -1093,7 +1096,7 @@ public void testCreateServiceComponentWithInvalidRequest() try { set1.clear(); ServiceComponentRequest rInvalid = - new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", null); set1.add(rInvalid); ComponentResourceProviderTest.createComponents(controller, set1); fail("Expected failure for already existing component"); @@ -1164,7 +1167,7 @@ public void testGetExecutionCommandWithClusterEnvForRetry() throws Exception { // issue an install command, expect retry is enabled ServiceComponentHostRequest schr = - new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", host2, "INSTALLED"); + new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host2, "INSTALLED"); Map requestProps = new HashMap<>(); requestProps.put("phase", "INITIAL_INSTALL"); RequestStatusResponse rsr = updateHostComponents(Collections.singleton(schr), requestProps, false); @@ -1190,7 +1193,7 @@ public void testGetExecutionCommandWithClusterEnvForRetry() throws Exception { } // issue an start command but no retry as phase is only INITIAL_INSTALL - schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", host2, "STARTED"); + schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host2, "STARTED"); rsr = updateHostComponents(Collections.singleton(schr), requestProps, false); stages = actionDB.getAllStages(rsr.getRequestId()); Assert.assertEquals(1, stages.size()); @@ -1220,7 +1223,7 @@ public void testGetExecutionCommandWithClusterEnvForRetry() throws Exception { // issue an start command and retry is expected requestProps.put("phase", "INITIAL_START"); - schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", host2, "STARTED"); + schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host2, "STARTED"); rsr = updateHostComponents(Collections.singleton(schr), requestProps, false); stages = actionDB.getAllStages(rsr.getRequestId()); Assert.assertEquals(1, stages.size()); @@ -1250,7 +1253,7 @@ public void testGetExecutionCommandWithClusterEnvForRetry() throws Exception { controller.updateClusters(Collections.singleton(crReq), null); requestProps.put("phase", "INITIAL_START"); - schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", host2, "STARTED"); + schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host2, "STARTED"); rsr = updateHostComponents(Collections.singleton(schr), requestProps, false); stages = actionDB.getAllStages(rsr.getRequestId()); Assert.assertEquals(1, stages.size()); @@ -1373,11 +1376,11 @@ public void testCreateServiceComponentMultiple() throws Exception { Set set1 = new HashSet<>(); ServiceComponentRequest valid1 = - new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", null); ServiceComponentRequest valid2 = - new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "JOBTRACKER", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "JOBTRACKER", "JOBTRACKER", null); ServiceComponentRequest valid3 = - new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "TASKTRACKER", null); + new ServiceComponentRequest(cluster1, serviceGroupName, "MAPREDUCE", "TASKTRACKER", "TASKTRACKER", null); set1.add(valid1); set1.add(valid2); set1.add(valid3); @@ -1443,8 +1446,7 @@ private void createServiceComponentHostSimple(String clusterName, String host1, // Expected } - // null service should work - createServiceComponentHost(clusterName, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(clusterName, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(clusterName, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(clusterName, serviceGroupName, serviceName, componentName2, host2, null); createServiceComponentHost(clusterName, serviceGroupName, serviceName, componentName3, host1, null); @@ -1481,7 +1483,7 @@ private void createServiceComponentHostSimple(String clusterName, String host1, ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, - componentName2, null, null); + componentName2, componentName2, null, null); Set response = controller.getHostComponents(Collections.singleton(r)); @@ -1511,16 +1513,16 @@ public void testCreateServiceComponentHostMultiple() new HashSet<>(); ServiceComponentHostRequest r1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, State.INIT.toString()); + componentName1, componentName1, host1, State.INIT.toString()); ServiceComponentHostRequest r2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName2, host1, State.INIT.toString()); + componentName2, componentName2, host1, State.INIT.toString()); ServiceComponentHostRequest r3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host2, State.INIT.toString()); + componentName1, componentName1, host2, State.INIT.toString()); ServiceComponentHostRequest r4 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName2, host2, State.INIT.toString()); + componentName2, componentName2, host2, State.INIT.toString()); set1.add(r1); set1.add(r2); @@ -1550,7 +1552,7 @@ public void testCreateServiceComponentHostMultiple() @Test(expected = IllegalArgumentException.class) public void createHostComponentsRequestRejectedWithoutClusterName() throws Exception { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest(null, "CORE", "HDFS", "NAMENODE", "host1", null) + new ServiceComponentHostRequest(null, "CORE", "HDFS", "NAMENODE", "NAMENODE", "host1", null) ); controller.createHostComponents(requests); } @@ -1558,7 +1560,7 @@ public void createHostComponentsRequestRejectedWithoutClusterName() throws Excep @Test(expected = IllegalArgumentException.class) public void createHostComponentsRequestRejectedWithoutComponentName() throws Exception { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest("foo", "CORE", "HDFS", null, "host1", null) + new ServiceComponentHostRequest("foo", "CORE", "HDFS", null, null, "host1", null) ); controller.createHostComponents(requests); } @@ -1566,7 +1568,7 @@ public void createHostComponentsRequestRejectedWithoutComponentName() throws Exc @Test(expected = IllegalArgumentException.class) public void createHostComponentsRequestRejectedWithoutHostname() throws Exception { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest("foo", "CORE", "HDFS", "NAMENODE", null, null) + new ServiceComponentHostRequest("foo", "CORE", "HDFS", "NAMENODE", "NAMENODE",null, null) ); controller.createHostComponents(requests); } @@ -1574,7 +1576,7 @@ public void createHostComponentsRequestRejectedWithoutHostname() throws Exceptio @Test(expected = ParentObjectNotFoundException.class) public void createHostComponentsRequestRejectedForNonexistentCluster() throws Exception { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest("foo", "CORE", "HDFS", "NAMENODE", "host1", null) + new ServiceComponentHostRequest("foo", "CORE", "HDFS", "NAMENODE", "NAMENODE", "host1", null) ); controller.createHostComponents(requests); } @@ -1619,7 +1621,7 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception try { ServiceComponentHostRequest rInvalid = - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(rInvalid)); fail("Expected failure for invalid service"); } catch (IllegalArgumentException e) { @@ -1636,24 +1638,24 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception try { ServiceComponentHostRequest rInvalid = - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(rInvalid)); fail("Expected failure for invalid service"); } catch (Exception e) { // Expected } - ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "NAMENODE"); + ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "NAMENODE", "NAMENODE"); s1.addServiceComponent(sc1); - ServiceComponent sc2 = serviceComponentFactory.createNew(s2, "NAMENODE"); + ServiceComponent sc2 = serviceComponentFactory.createNew(s2, "NAMENODE", "NAMENODE"); s2.addServiceComponent(sc2); - ServiceComponent sc3 = serviceComponentFactory.createNew(s3, "NAMENODE"); + ServiceComponent sc3 = serviceComponentFactory.createNew(s3, "NAMENODE", "NAMENODE"); s3.addServiceComponent(sc3); try { ServiceComponentHostRequest rInvalid = - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(rInvalid)); fail("Expected failure for invalid host"); } catch (Exception e) { @@ -1678,7 +1680,7 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception try { ServiceComponentHostRequest rInvalid = - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(rInvalid)); fail("Expected failure for invalid host cluster mapping"); } catch (Exception e) { @@ -1691,13 +1693,13 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception clusters.mapAndPublishHostsToCluster(hostnames, cluster2); ServiceComponentHostRequest valid = - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(valid)); try { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest(clusterFoo, "SG1", "HDFS", "NAMENODE", host2, null), - new ServiceComponentHostRequest(clusterFoo, "SG2", "HDFS", "NAMENODE", host2, null) + new ServiceComponentHostRequest(clusterFoo, "SG1", "HDFS", "NAMENODE", "NAMENODE", host2, null), + new ServiceComponentHostRequest(clusterFoo, "SG2", "HDFS", "NAMENODE", "NAMENODE", host2, null) ); controller.createHostComponents(requests); fail("Expected failure for wrong service requests as the SG1 service group doesn't exist on cluster"); @@ -1707,8 +1709,8 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception try { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", host2, null), - new ServiceComponentHostRequest(cluster2, serviceGroupName, "HDFS", "NAMENODE", host3, null) + new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host2, null), + new ServiceComponentHostRequest(cluster2, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host3, null) ); controller.createHostComponents(requests); fail("Expected failure for multiple clusters"); @@ -1718,8 +1720,8 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception try { Set requests = ImmutableSet.of( - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host1, null), - new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", host2, null) + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null), + new ServiceComponentHostRequest(clusterFoo, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host2, null) ); controller.createHostComponents(requests); fail("Expected failure for already existing"); @@ -1732,11 +1734,11 @@ public void testCreateServiceComponentHostWithInvalidRequest() throws Exception Assert.assertEquals(0, foo.getServiceComponentHosts(host3).size()); ServiceComponentHostRequest valid1 = - new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(valid1)); ServiceComponentHostRequest valid2 = - new ServiceComponentHostRequest(cluster2, serviceGroupName, "HDFS", "NAMENODE", host1, null); + new ServiceComponentHostRequest(cluster2, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null); controller.createHostComponents(Collections.singleton(valid2)); Assert.assertEquals(1, foo.getServiceComponentHosts(host1).size()); @@ -2333,12 +2335,12 @@ public void testGetServiceComponents() throws Exception { Service s1 = serviceFactory.createNew(c1, c1.addServiceGroup(serviceGroupName, "HDP-0.2"), new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c1.addService(s1); s1.setDesiredState(State.INSTALLED); - ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE"); + ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE", "DATANODE"); s1.addServiceComponent(sc1); sc1.setDesiredState(State.UNINSTALLED); ServiceComponentRequest r = new ServiceComponentRequest(cluster1, serviceGroupName, - s1.getName(), sc1.getName(), null); + s1.getName(), sc1.getName(), sc1.getType(), null); Set resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(1, resps.size()); @@ -2388,14 +2390,14 @@ public void testGetServiceComponentsWithFilters() throws Exception { s2.setDesiredState(State.INSTALLED); s4.setDesiredState(State.INSTALLED); - ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE"); - ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE"); - ServiceComponent sc3 = serviceComponentFactory.createNew(s3, "HBASE_REGIONSERVER"); - ServiceComponent sc4 = serviceComponentFactory.createNew(s4, "HIVE_SERVER"); - ServiceComponent sc5 = serviceComponentFactory.createNew(s4, "HIVE_CLIENT"); - ServiceComponent sc6 = serviceComponentFactory.createNew(s4, "MYSQL_SERVER"); - ServiceComponent sc7 = serviceComponentFactory.createNew(s5, "ZOOKEEPER_SERVER"); - ServiceComponent sc8 = serviceComponentFactory.createNew(s5, "ZOOKEEPER_CLIENT"); + ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE", "DATANODE"); + ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE", "NAMENODE"); + ServiceComponent sc3 = serviceComponentFactory.createNew(s3, "HBASE_REGIONSERVER", "HBASE_REGIONSERVER"); + ServiceComponent sc4 = serviceComponentFactory.createNew(s4, "HIVE_SERVER", "HIVE_SERVER"); + ServiceComponent sc5 = serviceComponentFactory.createNew(s4, "HIVE_CLIENT", "HIVE_CLIENT"); + ServiceComponent sc6 = serviceComponentFactory.createNew(s4, "MYSQL_SERVER", "MYSQL_SERVER"); + ServiceComponent sc7 = serviceComponentFactory.createNew(s5, "ZOOKEEPER_SERVER", "ZOOKEEPER_SERVER"); + ServiceComponent sc8 = serviceComponentFactory.createNew(s5, "ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT"); s1.addServiceComponent(sc1); s1.addServiceComponent(sc2); @@ -2414,7 +2416,7 @@ public void testGetServiceComponentsWithFilters() throws Exception { sc8.setDesiredState(State.UNINSTALLED); ServiceComponentRequest r = new ServiceComponentRequest(null, null, null, - null, null); + null, null, null); try { ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); @@ -2425,25 +2427,25 @@ public void testGetServiceComponentsWithFilters() throws Exception { // all comps per cluster r = new ServiceComponentRequest(c1.getClusterName(), null, - null, null, null); + null, null, null, null); Set resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(3, resps.size()); // all comps per cluster filter on state r = new ServiceComponentRequest(c2.getClusterName(), null, - null, null, State.UNINSTALLED.toString()); + null, null, null, State.UNINSTALLED.toString()); resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(4, resps.size()); // all comps for given service r = new ServiceComponentRequest(c2.getClusterName(), null, - s5.getName(), null, null); + s5.getName(), null, null, null); resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(2, resps.size()); // all comps for given service filter by state r = new ServiceComponentRequest(c2.getClusterName(), null, - s4.getName(), null, State.INIT.toString()); + s4.getName(), null, null, State.INIT.toString()); resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(1, resps.size()); Assert.assertEquals(sc4.getName(), @@ -2451,7 +2453,7 @@ public void testGetServiceComponentsWithFilters() throws Exception { // get single given comp r = new ServiceComponentRequest(c2.getClusterName(), null, - null, sc5.getName(), State.INIT.toString()); + null, sc5.getName(), sc5.getType(), State.INIT.toString()); resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(1, resps.size()); Assert.assertEquals(sc5.getName(), @@ -2459,7 +2461,7 @@ public void testGetServiceComponentsWithFilters() throws Exception { // get single given comp and given svc r = new ServiceComponentRequest(c2.getClusterName(), null, - s4.getName(), sc5.getName(), State.INIT.toString()); + s4.getName(), sc5.getName(), sc5.getType(), State.INIT.toString()); resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r)); Assert.assertEquals(1, resps.size()); Assert.assertEquals(sc5.getName(), @@ -2469,11 +2471,11 @@ public void testGetServiceComponentsWithFilters() throws Exception { ServiceComponentRequest r1, r2, r3; Set reqs = new HashSet<>(); r1 = new ServiceComponentRequest(c2.getClusterName(), null, - null, null, State.UNINSTALLED.toString()); + null, null, null, State.UNINSTALLED.toString()); r2 = new ServiceComponentRequest(c1.getClusterName(), null, - null, null, null); + null, null, null, null); r3 = new ServiceComponentRequest(c1.getClusterName(), null, - null, null, State.INIT.toString()); + null, null, null, State.INIT.toString()); reqs.addAll(Arrays.asList(r1, r2, r3)); resps = ComponentResourceProviderTest.getComponents(controller, reqs); Assert.assertEquals(7, resps.size()); @@ -2490,7 +2492,7 @@ public void testGetServiceComponentHosts() throws Exception { ServiceGroup serviceGroup = c1.addServiceGroup("CORE", HDP_0_1); Service s1 = serviceFactory.createNew(c1, serviceGroup, new ArrayList<>(), "HDFS", "HDFS", repositoryVersion); c1.addService(s1); - ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE"); + ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE", "DATANODE"); s1.addServiceComponent(sc1); sc1.setDesiredState(State.UNINSTALLED); ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, host1); @@ -2505,7 +2507,7 @@ public void testGetServiceComponentHosts() throws Exception { ServiceComponentHostRequest r = new ServiceComponentHostRequest(c1.getClusterName(), null, - null, null, null, null); + null, null, null, null, null); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); @@ -2591,30 +2593,30 @@ public void testGetServiceComponentHostsWithStaleConfigFilter() throws Exception s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig); ServiceComponentHostRequest r = - new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(5, resps.size()); //Get all host components with stale config = true - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setStaleConfig("true"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); //Get all host components with stale config = false - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setStaleConfig("false"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(3, resps.size()); //Get all host components with stale config = false and hostname filter - r = new ServiceComponentHostRequest(cluster1, null, null, null, host1, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, host1, null); r.setStaleConfig("false"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); //Get all host components with stale config = false and hostname filter - r = new ServiceComponentHostRequest(cluster1, null, null, null, host2, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, host2, null); r.setStaleConfig("true"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); @@ -2659,30 +2661,30 @@ public void testServiceComponentHostsWithDecommissioned() throws Exception { setComponentAdminState(HostComponentAdminState.INSERVICE); ServiceComponentHostRequest r = - new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(5, resps.size()); //Get all host components with decommissiond = true - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setAdminState("DECOMMISSIONED"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); //Get all host components with decommissioned = false - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setAdminState("INSERVICE"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); //Get all host components with decommissioned = some random string - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setAdminState("INSTALLED"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(0, resps.size()); //Update adminState - r = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", host2, null); + r = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host2, null); r.setAdminState("DECOMMISSIONED"); try { updateHostComponents(Collections.singleton(r), new HashMap<>(), false); @@ -2871,9 +2873,9 @@ public void testGetServiceComponentHostsWithFilters() throws Exception { s1.setDesiredState(State.INSTALLED); s2.setDesiredState(State.INSTALLED); - ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE"); - ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE"); - ServiceComponent sc3 = serviceComponentFactory.createNew(s3, "HBASE_REGIONSERVER"); + ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE", "DATANODE"); + ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE", "NAMENODE"); + ServiceComponent sc3 = serviceComponentFactory.createNew(s3, "HBASE_REGIONSERVER", "HBASE_REGIONSERVER"); s1.addServiceComponent(sc1); s1.addServiceComponent(sc2); @@ -2902,7 +2904,7 @@ public void testGetServiceComponentHostsWithFilters() throws Exception { sch5.setDesiredState(State.UNINSTALLED); ServiceComponentHostRequest r = - new ServiceComponentHostRequest(null, null, null, null, null, null); + new ServiceComponentHostRequest(null, null, null, null, null, null, null); try { controller.getHostComponents(Collections.singleton(r)); @@ -2912,14 +2914,14 @@ public void testGetServiceComponentHostsWithFilters() throws Exception { } // all across cluster - r = new ServiceComponentHostRequest(c1.getClusterName(), null, null, + r = new ServiceComponentHostRequest(c1.getClusterName(), null, null, null, null, null, null); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(6, resps.size()); // all for service r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, s1.getName(), - null, null, null); + null, null, null, null); resps = controller.getHostComponents(Collections.singleton(r)); Set actual = resps.stream() .map(AmbariManagementControllerTest::serviceComponentHostToString) @@ -2932,65 +2934,65 @@ public void testGetServiceComponentHostsWithFilters() throws Exception { // all for component r = new ServiceComponentHostRequest(c1.getClusterName(), null, null, - sc3.getName(), null, null); + sc3.getName(), sc3.getType(), null, null); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); // all for host r = new ServiceComponentHostRequest(c1.getClusterName(), null, null, - null, host2, null); + null, null, host2, null); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); // all across cluster with state filter r = new ServiceComponentHostRequest(c1.getClusterName(), null, null, - null, null, State.UNINSTALLED.toString()); + null, null, null, State.UNINSTALLED.toString()); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); // all for service with state filter r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, s1.getName(), - null, null, State.INIT.toString()); + null, null, null, State.INIT.toString()); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); // all for component with state filter r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, null, - sc3.getName(), null, State.INSTALLED.toString()); + sc3.getName(), sc3.getType(), null, State.INSTALLED.toString()); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(0, resps.size()); // all for host with state filter r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, null, - null, host2, State.INIT.toString()); + null, null, host2, State.INIT.toString()); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); // for service and host r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, s3.getName(), - null, host1, null); + null, null, host1, null); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(0, resps.size()); // single sch - given service and host and component r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, s3.getName(), - sc3.getName(), host3, State.INSTALLED.toString()); + sc3.getName(), sc3.getType(), host3, State.INSTALLED.toString()); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(0, resps.size()); // single sch - given service and host and component r = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, s3.getName(), - sc3.getName(), host3, null); + sc3.getName(), sc3.getType(), host3, null); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); ServiceComponentHostRequest r1, r2, r3; r1 = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, null, - null, host3, null); + null, null, host3, null); r2 = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, s3.getName(), - sc3.getName(), host2, null); + sc3.getName(), sc3.getType(), host2, null); r3 = new ServiceComponentHostRequest(c1.getClusterName(), serviceGroupName, null, - null, host2, null); + null, null, host2, null); Set reqs = new HashSet<>(); reqs.addAll(Arrays.asList(r1, r2, r3)); @@ -3237,22 +3239,22 @@ public void testServiceUpdateRecursive() throws Exception { new HashSet<>(); ServiceComponentHostRequest r1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host1, State.INIT.toString()); + componentName1, componentName1, host1, State.INIT.toString()); ServiceComponentHostRequest r2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host1, State.INIT.toString()); + componentName2, componentName2, host1, State.INIT.toString()); ServiceComponentHostRequest r3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host2, State.INIT.toString()); + componentName1, componentName1, host2, State.INIT.toString()); ServiceComponentHostRequest r4 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host2, State.INIT.toString()); + componentName2, componentName2, host2, State.INIT.toString()); ServiceComponentHostRequest r5 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName2, - componentName3, host1, State.INIT.toString()); + componentName3, componentName3, host1, State.INIT.toString()); ServiceComponentHostRequest r6 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName4, host2, State.INIT.toString()); + componentName4, componentName4, host2, State.INIT.toString()); set1.add(r1); set1.add(r2); @@ -3480,19 +3482,19 @@ public void testServiceComponentUpdateRecursive() throws Exception { new HashSet<>(); ServiceComponentHostRequest r1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host1, State.INIT.toString()); + componentName1, componentName1, host1, State.INIT.toString()); ServiceComponentHostRequest r2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host1, State.INIT.toString()); + componentName2, componentName2, host1, State.INIT.toString()); ServiceComponentHostRequest r3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host2, State.INIT.toString()); + componentName1, componentName1, host2, State.INIT.toString()); ServiceComponentHostRequest r4 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host2, State.INIT.toString()); + componentName2, componentName2, host2, State.INIT.toString()); ServiceComponentHostRequest r5 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName3, host1, State.INIT.toString()); + componentName3, componentName3, host1, State.INIT.toString()); set1.add(r1); set1.add(r2); @@ -3533,13 +3535,13 @@ public void testServiceComponentUpdateRecursive() throws Exception { // confirm an UNKOWN doesn't fail req1 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc3.getName(), State.INSTALLED.toString()); + sc3.getName(), sc3.getType(), State.INSTALLED.toString()); reqs.add(req1); ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.emptyMap(), true); try { reqs.clear(); req1 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc1.getName(), State.INIT.toString()); + sc1.getName(), sc1.getType(), State.INIT.toString()); reqs.add(req1); ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.emptyMap(), true); fail("Expected failure for invalid state update"); @@ -3565,7 +3567,7 @@ public void testServiceComponentUpdateRecursive() throws Exception { try { reqs.clear(); req1 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc1.getName(), State.STARTED.toString()); + sc1.getName(), sc1.getType(), State.STARTED.toString()); reqs.add(req1); ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.emptyMap(), true); fail("Expected failure for invalid state update"); @@ -3590,11 +3592,11 @@ public void testServiceComponentUpdateRecursive() throws Exception { reqs.clear(); req1 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc1.getName(), State.INSTALLED.toString()); + sc1.getName(), sc1.getType(), State.INSTALLED.toString()); req2 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc2.getName(), State.INSTALLED.toString()); + sc2.getName(), sc2.getType(), State.INSTALLED.toString()); req3 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc3.getName(), State.INSTALLED.toString()); + sc3.getName(), sc3.getType(), State.INSTALLED.toString()); reqs.add(req1); reqs.add(req2); reqs.add(req3); @@ -3637,9 +3639,9 @@ public void testServiceComponentUpdateRecursive() throws Exception { // test no-op reqs.clear(); req1 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc1.getName(), State.INSTALLED.toString()); + sc1.getName(), sc1.getType(), State.INSTALLED.toString()); req2 = new ServiceComponentRequest(cluster1, serviceGroupName, serviceName1, - sc2.getName(), State.INSTALLED.toString()); + sc2.getName(), sc2.getType(), State.INSTALLED.toString()); reqs.add(req1); reqs.add(req2); trackAction = ComponentResourceProviderTest.updateComponents(controller, reqs, Collections.emptyMap(), true); @@ -3670,19 +3672,19 @@ public void testServiceComponentHostUpdateRecursive() throws Exception { new HashSet<>(); ServiceComponentHostRequest r1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host1, State.INIT.toString()); + componentName1, componentName1, host1, State.INIT.toString()); ServiceComponentHostRequest r2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host1, State.INIT.toString()); + componentName2, componentName2, host1, State.INIT.toString()); ServiceComponentHostRequest r3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host2, State.INIT.toString()); + componentName1, componentName1, host2, State.INIT.toString()); ServiceComponentHostRequest r4 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host2, State.INIT.toString()); + componentName2, componentName2, host2, State.INIT.toString()); ServiceComponentHostRequest r5 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName3, host1, State.INIT.toString()); + componentName3, componentName3, host1, State.INIT.toString()); set1.add(r1); set1.add(r2); @@ -3739,19 +3741,19 @@ public void testServiceComponentHostUpdateRecursive() throws Exception { try { reqs.clear(); req1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host1, + componentName1, componentName1, host1, State.INSTALLED.toString()); req2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host2, + componentName1, componentName2, host2, State.INSTALLED.toString()); req3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host1, + componentName2, componentName2, host1, State.INSTALLED.toString()); req4 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host2, + componentName2, componentName2, host2, State.INSTALLED.toString()); req5 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName3, host1, + componentName3, componentName3, host1, State.STARTED.toString()); reqs.add(req1); reqs.add(req2); @@ -3766,15 +3768,15 @@ public void testServiceComponentHostUpdateRecursive() throws Exception { reqs.clear(); req1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, null, - componentName1, host1, State.INSTALLED.toString()); + componentName1, componentName1, host1, State.INSTALLED.toString()); req2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host2, State.INSTALLED.toString()); + componentName1, componentName1, host2, State.INSTALLED.toString()); req3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, null, - componentName2, host1, State.INSTALLED.toString()); + componentName2, componentName2, host1, State.INSTALLED.toString()); req4 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host2, State.INSTALLED.toString()); + componentName2, componentName2, host2, State.INSTALLED.toString()); req5 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName3, host1, State.INSTALLED.toString()); + componentName3, componentName3, host1, State.INSTALLED.toString()); reqs.add(req1); reqs.add(req2); reqs.add(req3); @@ -3806,10 +3808,10 @@ public void testServiceComponentHostUpdateRecursive() throws Exception { // test no-op reqs.clear(); req1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host1, + componentName1, componentName1, host1, State.INSTALLED.toString()); req2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host2, + componentName1, componentName1, host2, State.INSTALLED.toString()); reqs.add(req1); reqs.add(req2); @@ -3854,11 +3856,11 @@ public void testCreateCustomActions() throws Exception { Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); - hdfs.addServiceComponent(Role.NAMENODE.name()); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); - mapred.addServiceComponent(Role.RESOURCEMANAGER.name()); + mapred.addServiceComponent(Role.RESOURCEMANAGER.name(), Role.RESOURCEMANAGER.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1); @@ -4011,9 +4013,9 @@ public void testComponentCategorySentWithRestart() throws Exception { ServiceGroup serviceGroup = cluster.addServiceGroup(serviceGroupName, "HDP-2.0.7"); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); - hdfs.addServiceComponent(Role.NAMENODE.name()); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1); @@ -4118,11 +4120,11 @@ public void testCreateActionsFailures() throws Exception { Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service hive = cluster.addService(serviceGroup, "HIVE", "HIVE", repositoryVersion); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); - hdfs.addServiceComponent(Role.NAMENODE.name()); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); - hive.addServiceComponent(Role.HIVE_SERVER.name()); + hive.addServiceComponent(Role.HIVE_SERVER.name(), Role.HIVE_SERVER.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1); @@ -4386,8 +4388,8 @@ public void testCreateServiceCheckActions() throws Exception { Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapReduce = cluster.addService(serviceGroup, "MAPREDUCE", "MAPREDUCE", repositoryVersion); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); - mapReduce.addServiceComponent(Role.MAPREDUCE_CLIENT.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); + mapReduce.addServiceComponent(Role.MAPREDUCE_CLIENT.name(), Role.MAPREDUCE_CLIENT.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1); mapReduce.getServiceComponent(Role.MAPREDUCE_CLIENT.name()).addServiceComponentHost(host2); @@ -4490,8 +4492,7 @@ public void testUpdateConfigForRunningService() throws Exception { addHostToCluster(host2, cluster1); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); @@ -4620,14 +4621,14 @@ public void testUpdateConfigForRunningService() throws Exception { configVersions.put("typeC", "v1"); schReqs.clear(); schReqs.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, null)); + componentName1, componentName1, host1, null)); assertNull(updateHostComponents(schReqs, Collections.emptyMap(), true)); configVersions.clear(); configVersions.put("typeC", "v1"); configVersions.put("typeD", "v1"); scReqs.clear(); - scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, componentName2, null)); + scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, componentName2, componentName2, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); // update configs at service level @@ -4647,7 +4648,7 @@ public void testUpdateConfigForRunningService() throws Exception { configVersions.put("typeC", "v1"); schReqs.clear(); schReqs.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, null)); + componentName1, componentName1, host1, null)); assertNull(updateHostComponents(schReqs, Collections.emptyMap(), true)); // update configs at SC level @@ -4656,7 +4657,7 @@ public void testUpdateConfigForRunningService() throws Exception { configVersions.put("typeD", "v1"); scReqs.clear(); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName1, null)); + componentName1, componentName1, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); } @@ -4689,8 +4690,7 @@ public void testConfigUpdates() throws Exception { addHostToCluster(host2, cluster1); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host2, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName3, host1, null); @@ -4762,7 +4762,7 @@ public void testConfigUpdates() throws Exception { configVersions.put("typeC", "v1"); schReqs.clear(); schReqs.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, null)); + componentName1, componentName1, host1, null)); assertNull(updateHostComponents(schReqs, Collections.emptyMap(), true)); configVersions.clear(); @@ -4770,7 +4770,7 @@ public void testConfigUpdates() throws Exception { configVersions.put("typeD", "v1"); scReqs.clear(); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName2, null)); + componentName2, componentName2, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); // update configs at service level @@ -4789,7 +4789,7 @@ public void testConfigUpdates() throws Exception { configVersions.put("typeC", "v1"); schReqs.clear(); schReqs.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, null)); + componentName1, componentName1, host1, null)); assertNull(updateHostComponents(schReqs, Collections.emptyMap(), true)); // update configs at SC level @@ -4798,7 +4798,7 @@ public void testConfigUpdates() throws Exception { configVersions.put("typeD", "v1"); scReqs.clear(); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName1, null)); + componentName1, componentName1, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); } @@ -4831,8 +4831,7 @@ public void testReConfigureService() throws Exception { addHostToCluster(host2, cluster1); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host2, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName3, host1, null); @@ -4892,7 +4891,7 @@ public void testReConfigureService() throws Exception { configVersions.put("hdfs-site", "version1"); schReqs.clear(); schReqs.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, null)); + componentName1, componentName1, host1, null)); assertNull(updateHostComponents(schReqs, Collections.emptyMap(), true)); // Reconfigure SCH level @@ -4900,7 +4899,7 @@ public void testReConfigureService() throws Exception { configVersions.put("core-site", "version122"); schReqs.clear(); schReqs.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, null)); + componentName1, componentName1, host1, null)); assertNull(updateHostComponents(schReqs, Collections.emptyMap(), true)); // Clear Entity Manager @@ -4911,11 +4910,11 @@ public void testReConfigureService() throws Exception { configVersions.put("core-site", "version1"); configVersions.put("hdfs-site", "version1"); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName2, null)); + componentName2, componentName2, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName1, null)); + componentName1, componentName1, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); // Reconfigure SC level @@ -4924,12 +4923,12 @@ public void testReConfigureService() throws Exception { scReqs.clear(); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName2, null)); + componentName2, componentName2, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); scReqs.clear(); scReqs.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, - componentName1, null)); + componentName1, componentName1, null)); assertNull(ComponentResourceProviderTest.updateComponents(controller, scReqs, Collections.emptyMap(), true)); entityManager.clear(); @@ -5239,10 +5238,9 @@ public void testClientServiceSmokeTests() throws Exception { Map mapRequestProps = new HashMap<>(); mapRequestProps.put("context", "Called from a test"); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host2, null); createServiceComponentHost(cluster1, serviceGroupName, null, "SOME_CLIENT_FOR_SERVICE_CHECK", host2, null); @@ -5645,7 +5643,7 @@ public void testReInstallClientComponent() throws Exception { // Reinstall SCH ServiceComponentHostRequest schr = new ServiceComponentHostRequest - (cluster1, serviceGroupName, serviceName, componentName3, host3, State.INSTALLED.name()); + (cluster1, serviceGroupName, serviceName, componentName3, componentName3, host3, State.INSTALLED.name()); Set setReqs = new HashSet<>(); setReqs.add(schr); @@ -5843,13 +5841,13 @@ public void testDecommissonDatanodeAction() throws Exception { createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host2, null); ServiceComponentHostRequest r = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host2, State.INSTALLED.toString()); + componentName1, componentName1, host2, State.INSTALLED.toString()); Set requests = new HashSet<>(); requests.add(r); updateHostComponents(requests, Collections.emptyMap(), true); s.getServiceComponent(componentName1).getServiceComponentHost(host2).setState(State.INSTALLED); r = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host2, State.STARTED.toString()); + componentName1, componentName1, host2, State.STARTED.toString()); requests.clear(); requests.add(r); updateHostComponents(requests, Collections.emptyMap(), true); @@ -5928,11 +5926,11 @@ public void testResourceFiltersWithCustomActions() throws Exception { Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); - hdfs.addServiceComponent(Role.NAMENODE.name()); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); - mapred.addServiceComponent(Role.RESOURCEMANAGER.name()); + mapred.addServiceComponent(Role.RESOURCEMANAGER.name(), Role.RESOURCEMANAGER.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1); @@ -6029,11 +6027,11 @@ public void testResourceFiltersWithCustomCommands() throws Exception { hdfs = cluster.addDependencyToService("CORE", "HDFS", hadoop_clients.getServiceId()); - hdfs.addServiceComponent(Role.HDFS_CLIENT.name()); - hdfs.addServiceComponent(Role.NAMENODE.name()); - hdfs.addServiceComponent(Role.DATANODE.name()); + hdfs.addServiceComponent(Role.HDFS_CLIENT.name(), Role.HDFS_CLIENT.name()); + hdfs.addServiceComponent(Role.NAMENODE.name(), Role.NAMENODE.name()); + hdfs.addServiceComponent(Role.DATANODE.name(), Role.DATANODE.name()); - mapred.addServiceComponent(Role.RESOURCEMANAGER.name()); + mapred.addServiceComponent(Role.RESOURCEMANAGER.name(), Role.RESOURCEMANAGER.name()); hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1); hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1); @@ -6127,7 +6125,7 @@ public void testResourceFiltersWithCustomCommands() throws Exception { // Test service checks - specific host - hadoop_clients.addServiceComponent("SOME_CLIENT_FOR_SERVICE_CHECK"); + hadoop_clients.addServiceComponent("SOME_CLIENT_FOR_SERVICE_CHECK", "SOME_CLIENT_FOR_SERVICE_CHECK"); hadoop_clients.getServiceComponent("SOME_CLIENT_FOR_SERVICE_CHECK").addServiceComponentHost(host1); hadoop_clients.getServiceComponent("SOME_CLIENT_FOR_SERVICE_CHECK").addServiceComponentHost(host2); @@ -6178,8 +6176,7 @@ public void testConfigsAttachedToServiceChecks() throws Exception { addHostToCluster(host2, cluster1); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host2, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName3, host1, null); @@ -6254,8 +6251,7 @@ public void testConfigsAttachedToServiceNotCluster() throws Exception { addHostToCluster(host2, cluster1); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host2, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName3, host1, null); @@ -6323,9 +6319,8 @@ public void testHostLevelParamsSentWithCommands() throws Exception { Map mapRequestProps = new HashMap<>(); mapRequestProps.put("context", "Called from a test"); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host2, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host2, null); @@ -6635,8 +6630,7 @@ public void testConfigGroupOverridesWithServiceCheckActions() throws Exception { addHostToCluster(host1, cluster1); addHostToCluster(host2, cluster1); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host2, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName3, host1, null); @@ -7220,8 +7214,7 @@ public void testServiceStopWhileStopping() throws Exception { Map mapRequestProps = new HashMap<>(); mapRequestProps.put("context", "Called from a test"); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); @@ -7306,7 +7299,7 @@ public void testServiceStopWhileStopping() throws Exception { sch.setState(State.STOPPING); } else if (sch.getServiceComponentName().equals("DATANODE")) { ServiceComponentHostRequest r1 = new ServiceComponentHostRequest - (cluster1, serviceGroupName, serviceName, sch.getServiceComponentName(), + (cluster1, serviceGroupName, serviceName, sch.getServiceComponentName(), sch.getServiceComponentType(), sch.getHostName(), State.INSTALLED.name()); Set reqs1 = new HashSet<>(); @@ -7486,8 +7479,7 @@ public void testUpdateHostComponentsBadState() throws Exception { Map mapRequestProps = new HashMap<>(); mapRequestProps.put("context", "Called from a test"); - // null service should work - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); @@ -7537,7 +7529,7 @@ public void testUpdateHostComponentsBadState() throws Exception { } // issue an installed state request without failure - ServiceComponentHostRequest schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", host2, "INSTALLED"); + ServiceComponentHostRequest schr = new ServiceComponentHostRequest(cluster1, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host2, "INSTALLED"); Map requestProps = new HashMap<>(); requestProps.put("datanode", "dn_value"); requestProps.put("namenode", "nn_value"); @@ -7584,11 +7576,11 @@ public void testServiceUpdateRecursiveBadHostComponent() throws Exception { Set set1 = new HashSet<>(); ServiceComponentHostRequest r1 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName1, host1, State.INIT.toString()); + componentName1, componentName1, host1, State.INIT.toString()); ServiceComponentHostRequest r2 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName2, host1, State.INIT.toString()); + componentName2, componentName2, host1, State.INIT.toString()); ServiceComponentHostRequest r3 = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName1, - componentName3, host1, State.INIT.toString()); + componentName3, componentName3, host1, State.INIT.toString()); set1.add(r1); set1.add(r2); @@ -7693,7 +7685,7 @@ public void testDeleteHostComponentInVariousStates() throws Exception { Set schRequests = new HashSet<>(); // delete HC schRequests.clear(); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName1, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName1, componentName1, host1, null)); try { controller.deleteHostComponents(schRequests); Assert.fail("Expect failure while deleting."); @@ -7717,12 +7709,12 @@ public void testDeleteHostComponentInVariousStates() throws Exception { sc6.getServiceComponentHosts().values().iterator().next().setState(State.INIT); schRequests.clear(); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName1, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName2, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName3, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, mapred, componentName4, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, mapred, componentName5, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, mapred, componentName6, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName1, componentName1, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName2, componentName2, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, hdfs, componentName3, componentName3, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, mapred, componentName4, componentName4, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, mapred, componentName5, componentName5, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, mapred, componentName6, componentName6, host1, null)); DeleteStatusMetaData deleteStatusMetaData = controller.deleteHostComponents(schRequests); Assert.assertEquals(0, deleteStatusMetaData.getExceptionForKeys().size()); } @@ -7880,15 +7872,15 @@ public void testDeleteHost() throws Exception { // Case 1: Delete host that is still part of cluster, but do not specify the cluster_name in the request Set schRequests = new HashSet<>(); // Disable HC for non-clients - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName1, host1, "DISABLED")); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName2, host1, "DISABLED")); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName1, componentName1, host1, "DISABLED")); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName2, componentName2, host1, "DISABLED")); updateHostComponents(schRequests, new HashMap<>(), false); // Delete HC schRequests.clear(); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName1, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName2, host1, null)); - schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName3, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName1, componentName1, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName2, componentName2, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, componentName3, componentName3, host1, null)); controller.deleteHostComponents(schRequests); Assert.assertEquals(0, cluster.getServiceComponentHosts(host1).size()); @@ -8028,7 +8020,7 @@ public void testDeleteComponentsOnHost() throws Exception { addHostToCluster(host1, cluster1); - createServiceComponentHost(cluster1, serviceGroupName, null, componentName1, host1, null); + createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName1, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName2, host1, null); createServiceComponentHost(cluster1, serviceGroupName, serviceName, componentName3, host1, null); @@ -8057,7 +8049,7 @@ public void testDeleteComponentsOnHost() throws Exception { sch.handleEvent(new ServiceComponentHostStartedEvent (sch.getServiceComponentName(), sch.getHostName(), System.currentTimeMillis())); Set schRequests = new HashSet<>(); - schRequests.add(new ServiceComponentHostRequest(cluster1, null, null, null, host1, null)); + schRequests.add(new ServiceComponentHostRequest(cluster1, null, null, null, null, host1, null)); DeleteStatusMetaData deleteStatusMetaData = controller.deleteHostComponents(schRequests); Assert.assertEquals(1, deleteStatusMetaData.getExceptionForKeys().size()); @@ -8209,24 +8201,24 @@ public void testDeleteClusterCreateHost() throws Exception { ServiceResourceProviderTest.createServices(amc, repositoryVersionDAO, serviceRequests); Set serviceComponentRequests = new HashSet<>(); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "DATANODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", null)); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", null)); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "YARN", "NODEMANAGER", null)); - serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "HDFS_CLIENT", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "DATANODE", "DATANODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", "HISTORYSERVER", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", "RESOURCEMANAGER", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "YARN", "NODEMANAGER", "NODEMANAGER", null)); + serviceComponentRequests.add(new ServiceComponentRequest(clusterName, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", null)); ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests); Set componentHostRequests = new HashSet<>(); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "DATANODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "NAMENODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "YARN", "NODEMANAGER", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "HDFS_CLIENT", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "DATANODE", "DATANODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", "HISTORYSERVER", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "YARN", "RESOURCEMANAGER", "RESOURCEMANAGER", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "YARN", "NODEMANAGER", "NODEMANAGER", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(clusterName, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", host1, null)); amc.createHostComponents(componentHostRequests); @@ -8310,10 +8302,10 @@ public void testDisableAndDeleteStates() throws Exception { ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false); Set serviceComponentRequests = new HashSet<>(); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "SECONDARY_NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "DATANODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "HDFS_CLIENT", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "NAMENODE", "NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "DATANODE", "DATANODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "HDFS_CLIENT", "HDFS_CLIENT", null)); ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests); @@ -8325,11 +8317,11 @@ public void testDisableAndDeleteStates() throws Exception { HostResourceProviderTest.createHosts(amc, hostRequests); Set componentHostRequests = new HashSet<>(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "SECONDARY_NAMENODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", host2, null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", host3, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", host2, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", host3, null)); amc.createHostComponents(componentHostRequests); @@ -8364,33 +8356,33 @@ public void testDisableAndDeleteStates() throws Exception { } componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, "DISABLED")); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, "DISABLED")); updateHostComponents(amc, componentHostRequests, mapRequestProps, true); Assert.assertEquals(State.DISABLED, componentHost.getState()); componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, "INSTALLED")); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, "INSTALLED")); updateHostComponents(amc, componentHostRequests, mapRequestProps, true); Assert.assertEquals(State.INSTALLED, componentHost.getState()); componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, "DISABLED")); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, "DISABLED")); updateHostComponents(amc, componentHostRequests, mapRequestProps, true); Assert.assertEquals(State.DISABLED, componentHost.getState()); componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host2, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host2, null)); amc.createHostComponents(componentHostRequests); componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host2, "INSTALLED")); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host2, "INSTALLED")); updateHostComponents(amc, componentHostRequests, mapRequestProps, true); @@ -8411,7 +8403,7 @@ public void testDisableAndDeleteStates() throws Exception { } componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, null)); amc.deleteHostComponents(componentHostRequests); @@ -8424,7 +8416,7 @@ public void testDisableAndDeleteStates() throws Exception { // should be able to add the host component back componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, null)); amc.createHostComponents(componentHostRequests); namenodes = cluster.getService(serviceName).getServiceComponent("NAMENODE").getServiceComponentHosts(); assertEquals(2, namenodes.size()); @@ -8434,7 +8426,7 @@ public void testDisableAndDeleteStates() throws Exception { componentHost.handleEvent(new ServiceComponentHostInstallEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis(), version)); componentHost.handleEvent(new ServiceComponentHostOpSucceededEvent(componentHost.getServiceComponentName(), componentHost.getHostName(), System.currentTimeMillis())); componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", host1, "INSTALLED")); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", host1, "INSTALLED")); updateHostComponents(amc, componentHostRequests, mapRequestProps, true); assertEquals(State.INSTALLED, namenodes.get(host1).getState()); @@ -8450,7 +8442,7 @@ public void testDisableAndDeleteStates() throws Exception { // make disabled componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", host2, "DISABLED")); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", host2, "DISABLED")); updateHostComponents(amc, componentHostRequests, mapRequestProps, false); org.junit.Assert.assertEquals(State.DISABLED, sch.getState()); @@ -8478,7 +8470,7 @@ public void testDisableAndDeleteStates() throws Exception { // confirm delete componentHostRequests.clear(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", host2, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", host2, null)); amc.deleteHostComponents(componentHostRequests); sch = null; @@ -8531,19 +8523,19 @@ public void testDisableAndDeleteStates() throws Exception { ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false); //Crate service components serviceComponentRequests = new HashSet<>(); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "SECONDARY_NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "DATANODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "HDFS_CLIENT", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "NAMENODE", "NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "DATANODE", "DATANODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(cluster1, serviceGroupName, serviceName, "HDFS_CLIENT", "HDFS_CLIENT", null)); ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests); //Create ServiceComponentHosts componentHostRequests = new HashSet<>(); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "host1", null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "host1", null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "SECONDARY_NAMENODE", host1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "host2", null)); - componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "host3", null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", "host1", null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "NAMENODE", "NAMENODE", "host1", null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", host1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", "host2", null)); + componentHostRequests.add(new ServiceComponentHostRequest(cluster1, serviceGroupName, null, "DATANODE", "DATANODE", "host3", null)); amc.createHostComponents(componentHostRequests); @@ -8592,14 +8584,14 @@ public void testScheduleSmokeTest() throws Exception { ServiceResourceProviderTest.createServices(amc, repositoryVersionDAO, serviceRequests); Set serviceComponentRequests = new HashSet<>(); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "DATANODE", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "HDFS_CLIENT", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "YARN", "RESOURCEMANAGER", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "YARN", "NODEMANAGER", null)); - serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "YARN", "YARN_CLIENT", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "DATANODE", "DATANODE", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "HDFS_CLIENT", "HDFS_CLIENT", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", "HISTORYSERVER", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "YARN", "RESOURCEMANAGER", "RESOURCEMANAGER", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "YARN", "NODEMANAGER", "NODEMANAGER", null)); + serviceComponentRequests.add(new ServiceComponentRequest(CLUSTER_NAME, serviceGroupName, "YARN", "YARN_CLIENT", "YARN_CLIENT", null)); ComponentResourceProviderTest.createComponents(amc, serviceComponentRequests); @@ -8609,14 +8601,14 @@ public void testScheduleSmokeTest() throws Exception { HostResourceProviderTest.createHosts(amc, hostRequests); Set componentHostRequests = new HashSet<>(); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "DATANODE", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "NAMENODE", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "HDFS_CLIENT", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "SECONDARY_NAMENODE", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "HISTORYSERVER", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "RESOURCEMANAGER", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "NODEMANAGER", HOST1, null)); - componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "YARN_CLIENT", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "DATANODE", "DATANODE", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "NAMENODE", "NAMENODE", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "HDFS_CLIENT", "HDFS_CLIENT", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, "HDFS", "SECONDARY_NAMENODE", "SECONDARY_NAMENODE", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, "MAPREDUCE2", "HISTORYSERVER", "HISTORYSERVER", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, "YARN", "RESOURCEMANAGER", "RESOURCEMANAGER", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, "YARN", "NODEMANAGER", "NODEMANAGER", HOST1, null)); + componentHostRequests.add(new ServiceComponentHostRequest(CLUSTER_NAME, serviceGroupName, null, "YARN_CLIENT", "YARN_CLIENT", HOST1, null)); amc.createHostComponents(componentHostRequests); @@ -8695,9 +8687,17 @@ public void testGetServices2() throws Exception { expect(clusters.getCluster("cluster1")).andReturn(cluster); expect(cluster.getService("service1")).andReturn(service); + HostComponentStateDAO hostComponentStateDAO = createMock(HostComponentStateDAO.class); + ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = createMock(ServiceComponentDesiredStateDAO.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + expect(service.convertToResponse()).andReturn(response); + + // replay mocks - replay(maintHelper, injector, clusters, cluster, service, response); + replay(maintHelper, injector, clusters, cluster, service, response, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -8708,7 +8708,7 @@ public void testGetServices2() throws Exception { assertEquals(1, setResponses.size()); assertTrue(setResponses.contains(response)); - verify(injector, clusters, cluster, service, response); + verify(injector, clusters, cluster, service, response, hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -8739,8 +8739,14 @@ public void testGetServices___ServiceNotFoundException() throws Exception { expect(clusters.getCluster("cluster1")).andReturn(cluster); expect(cluster.getService("service1")).andThrow(new ServiceNotFoundException("custer1", "service1")); + HostComponentStateDAO hostComponentStateDAO = createMock(HostComponentStateDAO.class); + ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = createMock(ServiceComponentDesiredStateDAO.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // replay mocks - replay(maintHelper, injector, clusters, cluster); + replay(maintHelper, injector, clusters, cluster, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -8754,7 +8760,7 @@ public void testGetServices___ServiceNotFoundException() throws Exception { } assertSame(controller, controllerCapture.getValue()); - verify(injector, clusters, cluster); + verify(injector, clusters, cluster, hostComponentStateDAO, serviceComponentDesiredStateDAO); } /** @@ -8803,9 +8809,17 @@ public void testGetServices___OR_Predicate_ServiceNotFoundException() throws Exc expect(service1.convertToResponse()).andReturn(response); expect(service2.convertToResponse()).andReturn(response2); + + HostComponentStateDAO hostComponentStateDAO = createMock(HostComponentStateDAO.class); + ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = createMock(ServiceComponentDesiredStateDAO.class); + + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + + // replay mocks replay(maintHelper, injector, clusters, cluster, service1, service2, - response, response2); + response, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO); //test AmbariManagementController controller = new AmbariManagementControllerImpl(null, clusters, injector); @@ -8817,7 +8831,7 @@ public void testGetServices___OR_Predicate_ServiceNotFoundException() throws Exc assertTrue(setResponses.contains(response)); assertTrue(setResponses.contains(response2)); - verify(injector, clusters, cluster, service1, service2, response, response2); + verify(injector, clusters, cluster, service1, service2, response, response2, hostComponentStateDAO, serviceComponentDesiredStateDAO); } private void testRunSmokeTestFlag(String serviceGroupName, String serviceName, @@ -9811,30 +9825,30 @@ public void testConfigAttributesStaleConfigFilter() throws Exception { s1.getServiceComponent(componentName2).getServiceComponentHost(host2).updateActualConfigs(actualConfigOld); s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig); - ServiceComponentHostRequest r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(5, resps.size()); // Get all host components with stale config = true - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setStaleConfig("true"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); // Get all host components with stale config = false - r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, null, null); r.setStaleConfig("false"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(3, resps.size()); // Get all host components with stale config = false and hostname filter - r = new ServiceComponentHostRequest(cluster1, null, null, null, host1, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, host1, null); r.setStaleConfig("false"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(2, resps.size()); // Get all host components with stale config = false and hostname filter - r = new ServiceComponentHostRequest(cluster1, null, null, null, host2, null); + r = new ServiceComponentHostRequest(cluster1, null, null, null, null, host2, null); r.setStaleConfig("true"); resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); @@ -10029,7 +10043,7 @@ public void testTargetedProcessCommand() throws Exception { startService(cluster1, serviceGroupName, serviceName, false, false); ServiceComponentHostRequest req = new ServiceComponentHostRequest(cluster1, serviceGroupName, serviceName, - componentName1, host1, "INSTALLED"); + componentName1, componentName1, host1, "INSTALLED"); Map requestProperties = new HashMap<>(); requestProperties.put("namenode", "p1"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java index 4bce571c3e0..d192c43867e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java @@ -224,13 +224,13 @@ private void createService(String clusterName, String serviceGroupName, String s private void createServiceComponent(String clusterName, String serviceGroupName, String serviceName, String componentName, State desiredState) throws AmbariException, AuthorizationException { - ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, desiredState != null ? desiredState.name() : null); + ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, componentName, desiredState != null ? desiredState.name() : null); ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r)); } private void createServiceComponentHost(String clusterName, String serviceGroupName, String serviceName, String componentName, String hostname, State desiredState) throws AmbariException, AuthorizationException { - ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, hostname, desiredState != null ? desiredState.name() : null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, componentName, hostname, desiredState != null ? desiredState.name() : null); controller.createHostComponents(Collections.singleton(r)); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java index 5a2faa07250..d705d6a4b44 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RefreshYarnCapacitySchedulerReleaseConfigTest.java @@ -106,7 +106,7 @@ public void testRMRequiresRestart() throws AmbariException, AuthorizationExcepti controller.updateClusters(Collections.singleton(cr) , null); - ServiceComponentHostRequest r = new ServiceComponentHostRequest("c1", null, null, null, null, null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest("c1", null, null, null, null, null, null); r.setStaleConfig("true"); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(1, resps.size()); @@ -127,7 +127,7 @@ public void testAllRequiresRestart() throws AmbariException, AuthorizationExcept controller.updateClusters(Collections.singleton(cr) , null); - ServiceComponentHostRequest r = new ServiceComponentHostRequest("c1", null, null, null, null, null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest("c1", null, null, null, null, null, null); r.setStaleConfig("true"); Set resps = controller.getHostComponents(Collections.singleton(r)); Assert.assertEquals(4, resps.size()); @@ -215,13 +215,13 @@ private void createService(String clusterName, String serviceGroupName, private void createServiceComponent(String clusterName, String serviceGroupName, String serviceName, String componentName, State desiredState) throws AmbariException, AuthorizationException { - ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, desiredState != null ? desiredState.name() : null); + ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, componentName, desiredState != null ? desiredState.name() : null); ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r)); } private void createServiceComponentHost(String clusterName, String serviceGroupName, String serviceName, String componentName, String hostname, State desiredState) throws AmbariException, AuthorizationException { - ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, hostname, desiredState != null ? desiredState.name() : null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, componentName, hostname, desiredState != null ? desiredState.name() : null); controller.createHostComponents(Collections.singleton(r)); //set actual config diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java index 9f9a101ec92..2630ef746ff 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java @@ -245,7 +245,7 @@ public void testGetResources() throws Exception { serviceOsSpecificHashMap.put("key", osSpecific); ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, clusterName, 1L, "CORE", 1L, serviceName, serviceName, 1L, - componentName, displayName, hostName, publicHostname, desiredState, "", null, null, null, + componentName, componentName, displayName, hostName, publicHostname, desiredState, "", null, null, null, null); Set responses = new LinkedHashSet<>(); @@ -499,7 +499,7 @@ public void testGetResourcesFromCommonServices() throws Exception { serviceOsSpecificHashMap.put("key", osSpecific); ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, clusterName, 1L, "CORE", 1L, serviceName, serviceName, 1L, - componentName, displayName, hostName, publicHostName, desiredState, "", null, null, null, + componentName, componentName, displayName, hostName, publicHostName, desiredState, "", null, null, null, null); Set responses = new LinkedHashSet<>(); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java index 642c97be046..ba641650f98 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java @@ -61,6 +61,8 @@ import org.apache.ambari.server.controller.spi.SystemException; import org.apache.ambari.server.controller.utilities.PredicateBuilder; import org.apache.ambari.server.controller.utilities.PropertyHelper; +import org.apache.ambari.server.orm.dao.HostComponentStateDAO; +import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO; import org.apache.ambari.server.security.TestAuthenticationFactory; import org.apache.ambari.server.security.authorization.AuthorizationException; import org.apache.ambari.server.security.authorization.AuthorizationHelperInitializer; @@ -152,7 +154,7 @@ private void testCreateResources(Authentication authentication) throws Exception expect(componentInfo.isRecoveryEnabled()).andReturn(true).anyTimes(); expect(ambariMetaInfo.getComponent("HDP", "99", "Service100", "Component100")).andReturn(componentInfo).anyTimes(); - expect(serviceComponentFactory.createNew(service, "Component100")).andReturn(serviceComponent); + expect(serviceComponentFactory.createNew(service, "Component100", "Component100")).andReturn(serviceComponent); ServiceComponentResponse componentResponse = createNiceMock(ServiceComponentResponse.class); expect(serviceComponent.convertToResponse()).andReturn(componentResponse); @@ -251,13 +253,13 @@ private void testGetResources(Authentication authentication) throws Exception { expect(service.getServiceComponents()).andReturn(serviceComponentMap).anyTimes(); expect(serviceComponent1.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "CORE", 1L, "Service100", "Service100", "Component100", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "CORE", 1L, "Service100", "Service100", 1L, "Component100", "Component100", stackId, "", serviceComponentStateCountMap, true /* recovery enabled */, "Component100 Client", null, null)); expect(serviceComponent2.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "CORE", 1L, "Service100", "Service100", "Component101", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "CORE", 1L, "Service100", "Service100", 2L, "Component101", "Component101", stackId, "", serviceComponentStateCountMap, false /* recovery not enabled */, "Component101 Client", null, null)); expect(serviceComponent3.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "CORE", 1L, "Service100", "Service100", "Component102", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "CORE", 1L, "Service100", "Service100", 3L, "Component102", "Component102", stackId, "", serviceComponentStateCountMap, true /* recovery enabled */, "Component102 Client", "1.1", RepositoryVersionState.CURRENT)); expect(ambariMetaInfo.getComponent("FOO", "1.0", null, "Component100")).andReturn( @@ -431,13 +433,13 @@ private void testUpdateResources(Authentication authentication) throws Exception expect(component3Info.getCategory()).andReturn(null); expect(serviceComponent1.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", "Component101", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component101", "Component101", stackId, "", serviceComponentStateCountMap, false /* recovery not enabled */, "Component101 Client", null, null)); expect(serviceComponent2.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", "Component102", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", 2L, "Component102", "Component102",stackId, "", serviceComponentStateCountMap, false /* recovery not enabled */, "Component102 Client", null, null)); expect(serviceComponent3.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", "Component103", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", 3L, "Component103", "Component103", stackId, "", serviceComponentStateCountMap, false /* recovery not enabled */, "Component103 Client", null, null)); expect(serviceComponent1.getDesiredState()).andReturn(State.INSTALLED).anyTimes(); expect(serviceComponent2.getDesiredState()).andReturn(State.INSTALLED).anyTimes(); @@ -740,7 +742,7 @@ private void testUpdateAutoStart(Authentication authentication) throws Exception expect(component1Info.getCategory()).andReturn(null); expect(serviceComponent1.convertToResponse()).andReturn( - new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", "Component101", stackId, "", serviceComponentStateCountMap, + new ServiceComponentResponse(100L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component101", "Component101", stackId, "", serviceComponentStateCountMap, false /* recovery not enabled */, "Component101 Client", null, null)); expect(serviceComponent1.getDesiredState()).andReturn(State.INSTALLED).anyTimes(); @@ -948,6 +950,8 @@ public void testGetComponents_ServiceComponentNotFoundException() throws Excepti MaintenanceStateHelper maintHelper = createNiceMock(MaintenanceStateHelper.class); Cluster cluster = createNiceMock(Cluster.class); Service service = createNiceMock(Service.class); + HostComponentStateDAO hostComponentStateDAO = createMock(HostComponentStateDAO.class); + ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = createMock(ServiceComponentDesiredStateDAO.class); // requests ServiceComponentRequest request1 = new ServiceComponentRequest("cluster1", "CORE", "service1", "component1", @@ -963,6 +967,9 @@ public void testGetComponents_ServiceComponentNotFoundException() throws Excepti expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(maintHelper); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); + expect(injector.getInstance(HostComponentStateDAO.class)).andReturn(hostComponentStateDAO).anyTimes(); + expect(injector.getInstance(ServiceComponentDesiredStateDAO.class)).andReturn(serviceComponentDesiredStateDAO).anyTimes(); + // getComponents expect(clusters.getCluster("cluster1")).andReturn(cluster); expect(cluster.getService("service1")).andReturn(service); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java index f0337bb575f..999de001cfd 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java @@ -112,7 +112,7 @@ private void testCreateResources(Authentication authentication) throws Exception AbstractControllerResourceProvider.init(resourceProviderFactory); - ServiceComponentHostRequest request = new ServiceComponentHostRequest("Cluster100", SERVICE_GROUP_NAME, "Service100", "Component100", "Host100", null); + ServiceComponentHostRequest request = new ServiceComponentHostRequest("Cluster100", SERVICE_GROUP_NAME, "Service100", "Component100", "Component100", "Host100", null); Set expectedRequests = Collections.singleton(request); expect(managementController.createHostComponents(eq(expectedRequests))).andReturn(null).once(); @@ -141,6 +141,7 @@ private void testCreateResources(Authentication authentication) throws Exception properties.put(HostComponentResourceProvider.HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID, SERVICE_GROUP_NAME); properties.put(HostComponentResourceProvider.HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID, "Service100"); properties.put(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "Component100"); + properties.put(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID, "Component100"); properties.put(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "Host100"); propertySet.add(properties); @@ -183,17 +184,17 @@ private void testGetResources(Authentication authentication) throws Exception { String repositoryVersion2 = "0.2-1234"; allResponse.add(new ServiceComponentHostResponse( - 1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", "Host100", "Host100", + 1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100", "Component 100", "Host100", "Host100", State.INSTALLED.toString(), stackId.getStackId(), State.STARTED.toString(), stackId2.getStackId(), repositoryVersion2, null)); allResponse.add(new ServiceComponentHostResponse( - 1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component101", "Component 101", "Host100", "Host100", + 1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component101", "Component101", "Component 101", "Host100", "Host100", State.INSTALLED.toString(), stackId.getStackId(), State.STARTED.toString(), stackId2.getStackId(), repositoryVersion2, null)); allResponse.add(new ServiceComponentHostResponse( - 1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component 102", "Host100", "Host100", + 1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component102", "Component 102", "Host100", "Host100", State.INSTALLED.toString(), stackId.getStackId(), State.STARTED.toString(), stackId2.getStackId(), repositoryVersion2, null)); @@ -350,7 +351,7 @@ private void testUpdateResources(Authentication authentication) throws Exception Set nameResponse = new HashSet<>(); nameResponse.add(new ServiceComponentHostResponse( - 1L, "Cluster102", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", "Host100", "Host100", + 1L, "Cluster102", 1L, "ServiceGroup100", 1L, "Service100", "", 1L, "Component100", "Component100","Component 100", "Host100", "Host100", "INSTALLED", "", "", "", "", null)); // set expectations @@ -378,7 +379,7 @@ private void testUpdateResources(Authentication authentication) throws Exception changedHosts.put("Component100", Collections.singletonMap(State.STARTED, changedComponentHosts)); expect(managementController.addStages(null, cluster, mapRequestProps, null, null, null, changedHosts, - Collections.emptyList(), false, false)).andReturn(stageContainer).once(); + Collections.emptyList(), false, false)).andReturn(stageContainer).anyTimes(); stageContainer.persist(); expect(stageContainer.getRequestStatusResponse()).andReturn(response).once(); @@ -411,7 +412,9 @@ private void testUpdateResources(Authentication authentication) throws Exception Predicate predicate = new PredicateBuilder().property( HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").and(). property(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID).equals("INSTALLED").and(). - property(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("Component100").toPredicate(); + property(HostComponentResourceProvider.HOST_COMPONENT_SERVICE_GROUP_NAME_PROPERTY_ID).equals("ServiceGroup100").and(). + property(HostComponentResourceProvider.HOST_COMPONENT_SERVICE_NAME_PROPERTY_ID).equals("Service100").and(). + property(HostComponentResourceProvider.HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID).equals(100L).toPredicate(); RequestStatus requestStatus = provider.updateResources(request, predicate); Resource responseResource = requestStatus.getRequestResource(); assertEquals("response msg", responseResource.getPropertyValue(PropertyHelper.getPropertyId("Requests", "message"))); @@ -450,7 +453,7 @@ private void testDeleteResources(Authentication authentication) throws Exception new HostComponentResourceProvider(managementController, injector); // set expectations - ServiceComponentHostRequest request = new ServiceComponentHostRequest(null, null, null, "Component100", "Host100", null); + ServiceComponentHostRequest request = new ServiceComponentHostRequest(null, null, null, 1L, "Component100", "Component100", "Host100", null); expect(managementController.deleteHostComponents(Collections.singleton(request))).andReturn(deleteStatusMetaData); // replay @@ -463,7 +466,9 @@ private void testDeleteResources(Authentication authentication) throws Exception provider.addObserver(observer); Predicate predicate = new PredicateBuilder(). + property(HostComponentResourceProvider.HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID).equals(1L).and(). property(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("Component100").and(). + property(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_TYPE_PROPERTY_ID).equals("Component100").and(). property(HostComponentResourceProvider.HOST_COMPONENT_HOST_NAME_PROPERTY_ID).equals("Host100").toPredicate(); provider.deleteResources(new RequestImpl(null, null, null, null), predicate); @@ -535,7 +540,7 @@ public void testUpdateResourcesNothingToUpdate() throws Exception { Set nameResponse = new HashSet<>(); nameResponse.add(new ServiceComponentHostResponse( - 1L, "Cluster102", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", "Host100", "Host100", + 1L, "Cluster102", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100", "Component 100", "Host100", "Host100", "INSTALLED", "", "", "", "", null)); // set expectations @@ -588,7 +593,7 @@ public void testUpdateResourcesNothingToUpdate() throws Exception { Predicate predicate = new PredicateBuilder().property( HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").and(). property(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID).equals("INSTALLED").and(). - property(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("Component100").toPredicate(); + property(HostComponentResourceProvider.HOST_COMPONENT_HOST_COMPONENT_ID_PROPERTY_ID).equals(100L).toPredicate(); try { diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java index e68ff2eb03d..1334e260d3c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java @@ -314,11 +314,11 @@ public void testGetResources_Status_NoCluster() throws Exception { Set clusterSet = new HashSet<>(); clusterSet.add(cluster); - ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100","Component 100", "Host100", "Host100", "STARTED", "", null, null, null, null); - ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L,"Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component 102", + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L,"Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component102", "Component 102", "Host100", "Host100", "STARTED", "", null, null, null, null); - ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L,"Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component 103", + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L,"Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component103", "Component 103", "Host100", "Host100", "STARTED", "", null, null, null, null); Set responses = new HashSet<>(); @@ -409,11 +409,11 @@ public void testGetResources_Status_Healthy() throws Exception { Set clusterSet = new HashSet<>(); clusterSet.add(cluster); - ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100", "Component 100", "Host100", "Host100", "STARTED", "", null, null, null, null); - ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component 102", + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component102", "Component 102", "Host100", "Host100", "STARTED", "", null, null, null, null); - ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component 103", + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component103", "Component 103", "Host100", "Host100", "STARTED", "", null, null, null, null); Set responses = new HashSet<>(); @@ -501,11 +501,11 @@ public void testGetResources_Status_Unhealthy() throws Exception { Set clusterSet = new HashSet<>(); clusterSet.add(cluster); - ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100","Component 100", "Host100", "Host100", "STARTED", "", null, null, null, null); - ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component 102", + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component102", "Component 102", "Host100", "Host100", "INSTALLED", "", null, null, null, null); - ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component 103", + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component103", "Component 103", "Host100", "Host100", "STARTED", "", null, null, null, null); Set responses = new HashSet<>(); @@ -688,7 +688,7 @@ private void testGetRecoveryReport(Authentication authentication) throws Excepti Set clusterSet = new HashSet<>(); clusterSet.add(cluster); - ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100", "Component 100", "Host100", "Host100", "STARTED", "", null, null, null, null); Set responses = new HashSet<>(); @@ -772,11 +772,11 @@ public void testGetResources_Status_Alert() throws Exception { Set clusterSet = new HashSet<>(); clusterSet.add(cluster); - ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component 100", + ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component100", "Component100", "Component 100", "Host100", "Host100", "STARTED", "", null, null, null, null); - ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component 102", + ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component102", "Component102", "Component 102", "Host100", "Host100", "INSTALLED", "", null, null, null, null); - ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component 103", + ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse(1L, "Cluster100", 1L, "", 1L, "Service100", "", 1L, "Component103", "Component103", "Component 103", "Host100", "Host100", "STARTED", "", null, null, null, null); Set responses = new HashSet<>(); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java index cee3a521b85..25317ce282e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java @@ -123,14 +123,14 @@ private void createService(String clusterName, String serviceGroupName, String s private void createServiceComponent(String clusterName, String serviceGroupName, String serviceName, String componentName, State desiredState) throws AmbariException, AuthorizationException { - ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, desiredState != null ? desiredState.name() : null); + ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, serviceName, componentName, componentName, desiredState != null ? desiredState.name() : null); ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r)); } private void createServiceComponentHost(String clusterName, String serviceGroupName, String serviceName, String componentName, String hostname, State desiredState) throws AmbariException, AuthorizationException { - ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, hostname, desiredState != null ? desiredState.name() : null); + ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, serviceName, componentName, componentName, hostname, desiredState != null ? desiredState.name() : null); controller.createHostComponents(Collections.singleton(r)); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java index b3099307816..dbf3caeb415 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceDependencyResourceProviderTest.java @@ -256,7 +256,7 @@ private void createServiceComponent(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, - serviceName, componentName, dStateStr); + serviceName, componentName, componentName, dStateStr); ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r)); } @@ -269,7 +269,7 @@ private void createServiceComponentHost(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, - serviceName, componentName, hostname, dStateStr); + serviceName, componentName, componentName, hostname, dStateStr); controller.createHostComponents(Collections.singleton(r)); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java index 9f1910e9f4f..f0e98cafc6e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceGroupDependencyResourceProviderTest.java @@ -251,7 +251,7 @@ private void createServiceComponent(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentRequest r = new ServiceComponentRequest(clusterName, serviceGroupName, - serviceName, componentName, dStateStr); + serviceName, componentName, componentName, dStateStr); ComponentResourceProviderTest.createComponents(controller, Collections.singleton(r)); } @@ -264,7 +264,7 @@ private void createServiceComponentHost(String clusterName, dStateStr = desiredState.toString(); } ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName, serviceGroupName, - serviceName, componentName, hostname, dStateStr); + serviceName, componentName, componentName, hostname, dStateStr); controller.createHostComponents(Collections.singleton(r)); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java index c9464061c9a..fe26a82fd03 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java @@ -142,22 +142,22 @@ public void setup() throws Exception { RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service service = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); - service.addServiceComponent("NAMENODE"); - service.addServiceComponent("DATANODE"); - service.addServiceComponent("JOURNALNODE"); + service.addServiceComponent("NAMENODE", "NAMENODE"); + service.addServiceComponent("DATANODE", "DATANODE"); + service.addServiceComponent("JOURNALNODE", "JOURNALNODE"); service = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion); - service.addServiceComponent("RESOURCEMANAGER"); + service.addServiceComponent("RESOURCEMANAGER", "RESOURCEMANAGER"); service = cluster.addService(serviceGroup, "HBASE", "HBASE", repositoryVersion); - service.addServiceComponent("HBASE_MASTER"); - service.addServiceComponent("HBASE_REGIONSERVER"); + service.addServiceComponent("HBASE_MASTER", "HBASE_MASTER"); + service.addServiceComponent("HBASE_REGIONSERVER", "HBASE_REGIONSERVER"); stackId = new StackId("HDP-2.1.1"); repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); service = cluster.addService(serviceGroup, "STORM", "STORM", repositoryVersion); - service.addServiceComponent("STORM_REST_API"); + service.addServiceComponent("STORM_REST_API", "STORM_REST_API"); clusters.addHost("h1"); Host host = clusters.getHost("h1"); 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 473a7dd1762..549e1c181de 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 @@ -177,11 +177,11 @@ public void createCluster() throws Exception { ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service service = cluster.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repoVersionEntity); - ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER"); + ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER", "ZOOKEEPER_SERVER"); ServiceComponentHost sch = component.addServiceComponentHost("h1"); sch.setVersion("2.2.0.0"); - component = service.addServiceComponent("ZOOKEEPER_CLIENT"); + component = service.addServiceComponent("ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT"); sch = component.addServiceComponentHost("h1"); sch.setVersion("2.2.0.0"); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedStateTest.java index 9b998e506b5..14db57aa1d0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedStateTest.java @@ -43,8 +43,8 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception{ - ServiceComponent masterComponent = service.addServiceComponent("ZOOKEEPER_SERVER"); - ServiceComponent clientComponent = service.addServiceComponent("ZOOKEEPER_CLIENT"); + ServiceComponent masterComponent = service.addServiceComponent("ZOOKEEPER_SERVER", "ZOOKEEPER_SERVER"); + ServiceComponent clientComponent = service.addServiceComponent("ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT"); for (String hostName: hosts){ clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedStateTest.java index f88a4426cc7..35ec2d2fc15 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedStateTest.java @@ -41,7 +41,7 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception { - ServiceComponent masterComponent = service.addServiceComponent("FLUME_HANDLER"); + ServiceComponent masterComponent = service.addServiceComponent("FLUME_HANDLER", "FLUME_HANDLER"); for (String hostName: hosts){ diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedStateTest.java index be814e3c53b..5b972209385 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedStateTest.java @@ -41,9 +41,9 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception { - ServiceComponent masterComponent = service.addServiceComponent("HBASE_MASTER"); - ServiceComponent secondMasterComponent = service.addServiceComponent("HBASE_REGIONSERVER"); - ServiceComponent clientComponent = service.addServiceComponent("HBASE_CLIENT"); + ServiceComponent masterComponent = service.addServiceComponent("HBASE_MASTER", "HBASE_MASTER"); + ServiceComponent secondMasterComponent = service.addServiceComponent("HBASE_REGIONSERVER", "HBASE_REGIONSERVER"); + ServiceComponent clientComponent = service.addServiceComponent("HBASE_CLIENT", "HBASE_CLIENT"); for (String hostName: hosts){ clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedStateTest.java index cfae64fc8e9..6c317cd190d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedStateTest.java @@ -42,9 +42,9 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception { - ServiceComponent masterComponent = service.addServiceComponent("NAMENODE"); - ServiceComponent masterComponent1 = service.addServiceComponent("SECONDARY_NAMENODE"); - ServiceComponent clientComponent = service.addServiceComponent("HDFS_CLIENT"); + ServiceComponent masterComponent = service.addServiceComponent("NAMENODE", "NAMENODE"); + ServiceComponent masterComponent1 = service.addServiceComponent("SECONDARY_NAMENODE", "SECONDARY_NAMENODE"); + ServiceComponent clientComponent = service.addServiceComponent("HDFS_CLIENT", "HDFS_CLIENT"); for (String hostName: hosts){ clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedStateTest.java index 511c165c124..fb598d60816 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedStateTest.java @@ -42,11 +42,11 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception { - ServiceComponent masterComponent = service.addServiceComponent("HIVE_METASTORE"); - ServiceComponent secondMasterComponent = service.addServiceComponent("HIVE_SERVER"); - ServiceComponent thirdMasterComponent = service.addServiceComponent("WEBHCAT_SERVER"); - ServiceComponent fourMasterComponent = service.addServiceComponent("MYSQL_SERVER"); - ServiceComponent clientComponent = service.addServiceComponent("HIVE_CLIENT"); + ServiceComponent masterComponent = service.addServiceComponent("HIVE_METASTORE", "HIVE_METASTORE"); + ServiceComponent secondMasterComponent = service.addServiceComponent("HIVE_SERVER", "HIVE_SERVER"); + ServiceComponent thirdMasterComponent = service.addServiceComponent("WEBHCAT_SERVER", "WEBHCAT_SERVER"); + ServiceComponent fourMasterComponent = service.addServiceComponent("MYSQL_SERVER", "MYSQL_SERVER"); + ServiceComponent clientComponent = service.addServiceComponent("HIVE_CLIENT", "HIVE_CLIENT"); for (String hostName: hosts){ clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedStateTest.java index 3d959ea0c69..6e3a1c8aa32 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedStateTest.java @@ -41,8 +41,8 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception { - ServiceComponent masterComponent = service.addServiceComponent("OOZIE_SERVER"); - ServiceComponent clientComponent = service.addServiceComponent("OOZIE_CLIENT"); + ServiceComponent masterComponent = service.addServiceComponent("OOZIE_SERVER", "OOZIE_SERVER"); + ServiceComponent clientComponent = service.addServiceComponent("OOZIE_CLIENT", "OOZIE_CLIENT"); for (String hostName: hosts){ clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/YarnServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/YarnServiceCalculatedStateTest.java index 2de3ea6b3d6..cf23f319555 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/YarnServiceCalculatedStateTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/YarnServiceCalculatedStateTest.java @@ -42,9 +42,9 @@ protected ServiceCalculatedState getServiceCalculatedStateObject() { @Override protected void createComponentsAndHosts() throws Exception { - ServiceComponent masterComponent = service.addServiceComponent("RESOURCEMANAGER"); - ServiceComponent secondMasterComponent = service.addServiceComponent("NODEMANAGER"); - ServiceComponent clientComponent = service.addServiceComponent("YARN_CLIENT"); + ServiceComponent masterComponent = service.addServiceComponent("RESOURCEMANAGER", "RESOURCEMANAGER"); + ServiceComponent secondMasterComponent = service.addServiceComponent("NODEMANAGER", "NODEMANAGER"); + ServiceComponent clientComponent = service.addServiceComponent("YARN_CLIENT", "YARN_CLIENT"); for (String hostName: hosts){ clusters.addHost(hostName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java index a312f8efbde..f939ce07914 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java @@ -366,7 +366,7 @@ private void installHdfsService() throws Exception { Service service = m_cluster.getService(serviceName); Assert.assertNotNull(service); - ServiceComponent component = m_componentFactory.createNew(service, "DATANODE"); + ServiceComponent component = m_componentFactory.createNew(service, "DATANODE", "DATANODE"); service.addServiceComponent(component); component.setDesiredState(State.INSTALLED); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java index c4bd1de473c..7a180dce9a4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java @@ -558,7 +558,7 @@ private void addService(Cluster cl, ServiceGroup serviceGroup, List host for (Map.Entry> component : topology.entrySet()) { String componentName = component.getKey(); - cl.getService(serviceName).addServiceComponent(componentName); + cl.getService(serviceName).addServiceComponent(componentName, componentName); for (Integer hostIndex : component.getValue()) { cl.getService(serviceName) @@ -580,7 +580,7 @@ private void addServiceComponent(Cluster cl, List hostList, Service service = cl.getService(serviceName); if (!service.getServiceComponents().containsKey(componentName)) { - service.addServiceComponent(componentName); + service.addServiceComponent(componentName, componentName); } ServiceComponent component = service.getServiceComponent(componentName); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java index a1f6a0fb4c9..9756bda6252 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java @@ -468,7 +468,7 @@ public void installHdfsService(Cluster cluster, Service service = cluster.getService(serviceName); assertNotNull(service); - ServiceComponent datanode = componentFactory.createNew(service, "DATANODE"); + ServiceComponent datanode = componentFactory.createNew(service, "DATANODE", "DATANODE"); service.addServiceComponent(datanode); datanode.setDesiredState(State.INSTALLED); @@ -479,7 +479,7 @@ public void installHdfsService(Cluster cluster, sch.setDesiredState(State.INSTALLED); sch.setState(State.INSTALLED); - ServiceComponent namenode = componentFactory.createNew(service, "NAMENODE"); + ServiceComponent namenode = componentFactory.createNew(service, "NAMENODE", "NAMENODE"); service.addServiceComponent(namenode); namenode.setDesiredState(State.INSTALLED); @@ -503,7 +503,7 @@ public void installYarnService(Cluster cluster, assertNotNull(service); ServiceComponent resourceManager = componentFactory.createNew(service, - "RESOURCEMANAGER"); + "RESOURCEMANAGER", "RESOURCEMANAGER"); service.addServiceComponent(resourceManager); resourceManager.setDesiredState(State.INSTALLED); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java index 40ca1190338..f27d9eb3ffd 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java @@ -511,7 +511,7 @@ private ServiceComponent addServiceComponent(Service service, String componentNa try { serviceComponent = service.getServiceComponent(componentName); } catch (ServiceComponentNotFoundException e) { - serviceComponent = serviceComponentFactory.createNew(service, componentName); + serviceComponent = serviceComponentFactory.createNew(service, componentName, componentName); service.addServiceComponent(serviceComponent); serviceComponent.setDesiredState(State.INSTALLED); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java index 21c43b4ac68..f6bc2d21d4f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/CreateAndConfigureActionTest.java @@ -269,7 +269,7 @@ private ServiceComponent addServiceComponent(Service service, try { serviceComponent = service.getServiceComponent(componentName); } catch (ServiceComponentNotFoundException e) { - serviceComponent = serviceComponentFactory.createNew(service, componentName); + serviceComponent = serviceComponentFactory.createNew(service, componentName, componentName); service.addServiceComponent(serviceComponent); serviceComponent.setDesiredState(State.INSTALLED); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java index 90a156e0228..75ac685c6ed 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java @@ -109,7 +109,7 @@ public void teardown() throws AmbariException, SQLException { public void testCreateServiceComponent() throws AmbariException { String componentName = "DATANODE2"; ServiceComponent component = serviceComponentFactory.createNew(service, - componentName); + componentName, componentName); service.addServiceComponent(component); ServiceComponent sc = service.getServiceComponent(componentName); @@ -131,7 +131,7 @@ public void testCreateServiceComponent() throws AmbariException { public void testGetAndSetServiceComponentInfo() throws AmbariException { String componentName = "NAMENODE"; ServiceComponent component = serviceComponentFactory.createNew(service, - componentName); + componentName, componentName); service.addServiceComponent(component); ServiceComponent sc = service.getServiceComponent(componentName); @@ -155,7 +155,7 @@ public void testGetAndSetServiceComponentInfo() throws AmbariException { long serviceId = 1; ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName( - cluster.getClusterId(), serviceGroupId, serviceId, componentName); + cluster.getClusterId(), serviceGroupId, serviceId, componentName, componentName); ServiceComponent sc1 = serviceComponentFactory.createExisting(service, serviceComponentDesiredStateEntity); @@ -193,7 +193,7 @@ private void addHostToCluster(String hostname, @Test public void testAddAndGetServiceComponentHosts() throws AmbariException { String componentName = "NAMENODE"; - ServiceComponent component = serviceComponentFactory.createNew(service, componentName); + ServiceComponent component = serviceComponentFactory.createNew(service, componentName, componentName); service.addServiceComponent(component); ServiceComponent sc = service.getServiceComponent(componentName); @@ -246,18 +246,13 @@ public void testAddAndGetServiceComponentHosts() throws AmbariException { long serviceGroupId = 1; long serviceId = 1; + long componentId = 1; HostComponentDesiredStateEntity desiredStateEntity = - desiredStateDAO.findByIndex( - cluster.getClusterId(), - serviceGroupId, - serviceId, - componentName, - hostEntity1.getHostId() - ); + desiredStateDAO.findByIndex(componentId); HostComponentStateEntity stateEntity = liveStateDAO.findByIndex(cluster.getClusterId(), - serviceGroupId, serviceId, componentName, hostEntity1.getHostId()); + serviceGroupId, serviceId, componentId, hostEntity1.getHostId()); ServiceComponentHost sch = serviceComponentHostFactory.createExisting(sc, stateEntity, desiredStateEntity); @@ -271,7 +266,7 @@ public void testAddAndGetServiceComponentHosts() throws AmbariException { @Test public void testConvertToResponse() throws AmbariException { String componentName = "NAMENODE"; - ServiceComponent component = serviceComponentFactory.createNew(service, componentName); + ServiceComponent component = serviceComponentFactory.createNew(service, componentName, componentName); service.addServiceComponent(component); addHostToCluster("h1", service.getCluster().getClusterName()); @@ -332,7 +327,7 @@ public void testConvertToResponse() throws AmbariException { public void testCanBeRemoved() throws Exception { String componentName = "NAMENODE"; ServiceComponent component = serviceComponentFactory.createNew(service, - componentName); + componentName, componentName); addHostToCluster("h1", service.getCluster().getClusterName()); ServiceComponentHost sch = serviceComponentHostFactory.createNew(component, "h1"); component.addServiceComponentHost(sch); @@ -360,7 +355,7 @@ public void testServiceComponentRemove() throws AmbariException { ServiceComponentDesiredStateDAO.class); String componentName = "NAMENODE"; - ServiceComponent component = serviceComponentFactory.createNew(service, componentName); + ServiceComponent component = serviceComponentFactory.createNew(service, componentName, componentName); service.addServiceComponent(component); ServiceComponent sc = service.getServiceComponent(componentName); @@ -373,7 +368,7 @@ public void testServiceComponentRemove() throws AmbariException { long serviceId = 1; ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName( - cluster.getClusterId(), serviceGroupId, serviceId, componentName); + cluster.getClusterId(), serviceGroupId, serviceId, componentName, componentName); Assert.assertNotNull(serviceComponentDesiredStateEntity); @@ -413,7 +408,7 @@ public void testServiceComponentRemove() throws AmbariException { // verify history is gone, too serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName( - cluster.getClusterId(), serviceGroupId, serviceId, componentName); + cluster.getClusterId(), serviceGroupId, serviceId, componentName, componentName); Assert.assertNull(serviceComponentDesiredStateEntity); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java index 3c38c5bd585..5b8f6fd2cb5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java @@ -100,7 +100,7 @@ public void testCanBeRemoved() throws Exception{ org.junit.Assert.assertTrue(service.canBeRemoved()); } - ServiceComponent component = service.addServiceComponent("NAMENODE"); + ServiceComponent component = service.addServiceComponent("NAMENODE", "NAMENODE"); // component can be removed component.setDesiredState(State.INSTALLED); @@ -179,11 +179,11 @@ public void testAddGetDeleteServiceComponents() throws AmbariException { Assert.assertTrue(s.getServiceComponents().isEmpty()); ServiceComponent sc1 = - serviceComponentFactory.createNew(s, "NAMENODE"); + serviceComponentFactory.createNew(s, "NAMENODE", "NAMENODE"); ServiceComponent sc2 = - serviceComponentFactory.createNew(s, "DATANODE1"); + serviceComponentFactory.createNew(s, "DATANODE1", "DATANODE1"); ServiceComponent sc3 = - serviceComponentFactory.createNew(s, "DATANODE2"); + serviceComponentFactory.createNew(s, "DATANODE2", "DATANODE2"); Map comps = new HashMap<>(); @@ -205,7 +205,7 @@ public void testAddGetDeleteServiceComponents() throws AmbariException { s.addServiceComponent(sc3); - ServiceComponent sc4 = s.addServiceComponent("HDFS_CLIENT"); + ServiceComponent sc4 = s.addServiceComponent("HDFS_CLIENT", "HDFS_CLIENT"); Assert.assertNotNull(s.getServiceComponent(sc4.getName())); Assert.assertEquals(State.INIT, s.getServiceComponent("HDFS_CLIENT").getDesiredState()); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java index 11464ddda54..06ecdc2b6db 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java @@ -595,7 +595,7 @@ private ServiceComponent addServiceComponent(Service service, serviceComponent = service.getServiceComponent(componentName); } catch (ServiceComponentNotFoundException e) { serviceComponent = serviceComponentFactory.createNew(service, - componentName); + componentName, componentName); service.addServiceComponent(serviceComponent); serviceComponent.setDesiredState(State.INSTALLED); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java index 7fbaf6f5404..c4d0a76e96d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java @@ -237,20 +237,20 @@ public void testDeleteService() throws Exception { ServiceGroup serviceGroup = cluster.addServiceGroup("CORE", stackId.getStackId()); Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); - ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE"); + ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE", "NAMENODE"); nameNode.addServiceComponentHost(hostName1); - ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE"); + ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE", "DATANODE"); dataNode.addServiceComponentHost(hostName1); dataNode.addServiceComponentHost(hostName2); - ServiceComponent hdfsClient = hdfs.addServiceComponent("HDFS_CLIENT"); + ServiceComponent hdfsClient = hdfs.addServiceComponent("HDFS_CLIENT", "HDFS_CLIENT"); hdfsClient.addServiceComponentHost(hostName1); hdfsClient.addServiceComponentHost(hostName2); Service tez = cluster.addService(serviceGroup, serviceToDelete, serviceToDelete, repositoryVersion); - ServiceComponent tezClient = tez.addServiceComponent("TEZ_CLIENT"); + ServiceComponent tezClient = tez.addServiceComponent("TEZ_CLIENT", "TEZ_CLIENT"); ServiceComponentHost tezClientHost1 = tezClient.addServiceComponentHost(hostName1); ServiceComponentHost tezClientHost2 = tezClient.addServiceComponentHost(hostName2); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java index 9a7deb6886d..4e85214825d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java @@ -343,22 +343,22 @@ private Cluster createClusterForRU(String clusterName, RepositoryVersionEntity r cluster.addService(s3); // Add HDFS components - ServiceComponent sc1CompA = serviceComponentFactory.createNew(s1, "NAMENODE"); - ServiceComponent sc1CompB = serviceComponentFactory.createNew(s1, "DATANODE"); - ServiceComponent sc1CompC = serviceComponentFactory.createNew(s1, "HDFS_CLIENT"); + ServiceComponent sc1CompA = serviceComponentFactory.createNew(s1, "NAMENODE", "NAMENODE"); + ServiceComponent sc1CompB = serviceComponentFactory.createNew(s1, "DATANODE", "DATANODE"); + ServiceComponent sc1CompC = serviceComponentFactory.createNew(s1, "HDFS_CLIENT", "HDFS_CLIENT"); s1.addServiceComponent(sc1CompA); s1.addServiceComponent(sc1CompB); s1.addServiceComponent(sc1CompC); // Add ZK - ServiceComponent sc2CompA = serviceComponentFactory.createNew(s2, "ZOOKEEPER_SERVER"); - ServiceComponent sc2CompB = serviceComponentFactory.createNew(s2, "ZOOKEEPER_CLIENT"); + ServiceComponent sc2CompA = serviceComponentFactory.createNew(s2, "ZOOKEEPER_SERVER", "ZOOKEEPER_SERVER"); + ServiceComponent sc2CompB = serviceComponentFactory.createNew(s2, "ZOOKEEPER_CLIENT", "ZOOKEEPER_CLIENT"); s2.addServiceComponent(sc2CompA); s2.addServiceComponent(sc2CompB); // Add Ganglia - ServiceComponent sc3CompA = serviceComponentFactory.createNew(s3, "GANGLIA_SERVER"); - ServiceComponent sc3CompB = serviceComponentFactory.createNew(s3, "GANGLIA_MONITOR"); + ServiceComponent sc3CompA = serviceComponentFactory.createNew(s3, "GANGLIA_SERVER", "GANGLIA_SERVER"); + ServiceComponent sc3CompB = serviceComponentFactory.createNew(s3, "GANGLIA_MONITOR", "GANGLIA_MONITOR"); s3.addServiceComponent(sc3CompA); s3.addServiceComponent(sc3CompB); @@ -633,7 +633,7 @@ public void testGetServiceComponentHosts() throws Exception { Service s = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "HDFS", "HDFS", repositoryVersion); c1.addService(s); - ServiceComponent sc = serviceComponentFactory.createNew(s, "NAMENODE"); + ServiceComponent sc = serviceComponentFactory.createNew(s, "NAMENODE", "NAMENODE"); s.addServiceComponent(sc); ServiceComponentHost sch = @@ -651,7 +651,7 @@ public void testGetServiceComponentHosts() throws Exception { iterator.next(); Service s1 = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "PIG", "PIG", repositoryVersion); c1.addService(s1); - ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "PIG"); + ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "PIG", "PIG"); s1.addServiceComponent(sc1); ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, "h1"); sc1.addServiceComponentHost(sch1); @@ -673,12 +673,12 @@ public void testGetServiceComponentHosts_ForService() throws Exception { Service s = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "HDFS", "HDFS", repositoryVersion); c1.addService(s); - ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE"); + ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE", "NAMENODE"); s.addServiceComponent(scNN); ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1"); scNN.addServiceComponentHost(schNNH1); - ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE"); + ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE", "DATANODE"); s.addServiceComponent(scDN); ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1"); scDN.addServiceComponentHost(scDNH1); @@ -703,12 +703,12 @@ public void testGetServiceComponentHosts_ForServiceComponent() throws Exception Service s = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "HDFS", "HDFS", repositoryVersion); c1.addService(s); - ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE"); + ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE", "NAMENODE"); s.addServiceComponent(scNN); ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1"); scNN.addServiceComponentHost(schNNH1); - ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE"); + ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE", "DATANODE"); s.addServiceComponent(scDN); ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1"); scDN.addServiceComponentHost(scDNH1); @@ -739,12 +739,12 @@ public void testGetServiceComponentHostMap() throws Exception { Service s = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "HDFS", "HDFS", repositoryVersion); c1.addService(s); - ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE"); + ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE", "NAMENODE"); s.addServiceComponent(scNN); ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1"); scNN.addServiceComponentHost(schNNH1); - ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE"); + ServiceComponent scDN = serviceComponentFactory.createNew(s, "DATANODE", "DATANODE"); s.addServiceComponent(scDN); ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1"); scDN.addServiceComponentHost(scDNH1); @@ -776,19 +776,19 @@ public void testGetServiceComponentHostMap_ForService() throws Exception { Service sfMR = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); c1.addService(sfMR); - ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE"); + ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE", "NAMENODE"); sfHDFS.addServiceComponent(scNN); ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1"); scNN.addServiceComponentHost(schNNH1); - ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE"); + ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE", "DATANODE"); sfHDFS.addServiceComponent(scDN); ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1"); scDN.addServiceComponentHost(scDNH1); ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2"); scDN.addServiceComponentHost(scDNH2); - ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER"); + ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER", "JOBTRACKER"); sfMR.addServiceComponent(scJT); ServiceComponentHost schJTH1 = serviceComponentHostFactory.createNew(scJT, "h1"); scJT.addServiceComponentHost(schJTH1); @@ -834,19 +834,19 @@ public void testGetServiceComponentHostMap_ForHost() throws Exception { Service sfMR = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); c1.addService(sfMR); - ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE"); + ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE", "NAMENODE"); sfHDFS.addServiceComponent(scNN); ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1"); scNN.addServiceComponentHost(schNNH1); - ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE"); + ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE", "DATANODE"); sfHDFS.addServiceComponent(scDN); ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1"); scDN.addServiceComponentHost(scDNH1); ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2"); scDN.addServiceComponentHost(scDNH2); - ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER"); + ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER", "JOBTRACKER"); sfMR.addServiceComponent(scJT); ServiceComponentHost schJTH1 = serviceComponentHostFactory.createNew(scJT, "h1"); scJT.addServiceComponentHost(schJTH1); @@ -893,19 +893,19 @@ public void testGetServiceComponentHostMap_ForHostAndService() throws Exception Service sfMR = serviceFactory.createNew(c1, serviceGroup, Collections.emptyList(), "MAPREDUCE", "MAPREDUCE", repositoryVersion); c1.addService(sfMR); - ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE"); + ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE", "NAMENODE"); sfHDFS.addServiceComponent(scNN); ServiceComponentHost schNNH1 = serviceComponentHostFactory.createNew(scNN, "h1"); scNN.addServiceComponentHost(schNNH1); - ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE"); + ServiceComponent scDN = serviceComponentFactory.createNew(sfHDFS, "DATANODE", "DATANODE"); sfHDFS.addServiceComponent(scDN); ServiceComponentHost scDNH1 = serviceComponentHostFactory.createNew(scDN, "h1"); scDN.addServiceComponentHost(scDNH1); ServiceComponentHost scDNH2 = serviceComponentHostFactory.createNew(scDN, "h2"); scDN.addServiceComponentHost(scDNH2); - ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER"); + ServiceComponent scJT = serviceComponentFactory.createNew(sfMR, "JOBTRACKER", "JOBTRACKER"); sfMR.addServiceComponent(scJT); ServiceComponentHost schJTH1 = serviceComponentHostFactory.createNew(scJT, "h1"); scJT.addServiceComponentHost(schJTH1); @@ -1076,7 +1076,7 @@ public void testDeleteService() throws Exception { c1.addService(serviceGroup, "MAPREDUCE", "MAPREDUCE", repositoryVersion); Service hdfs = c1.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion); - ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE"); + ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE", "NAMENODE"); assertEquals(2, c1.getServices().size()); assertEquals(2, injector.getProvider(EntityManager.class).get(). @@ -1541,8 +1541,8 @@ public void testTransitionHostsToInstalling() throws Exception { c1.addService(hdfs); // Add HDFS components - ServiceComponent datanode = serviceComponentFactory.createNew(hdfs, "NAMENODE"); - ServiceComponent namenode = serviceComponentFactory.createNew(hdfs, "DATANODE"); + ServiceComponent datanode = serviceComponentFactory.createNew(hdfs, "NAMENODE", "NAMENODE"); + ServiceComponent namenode = serviceComponentFactory.createNew(hdfs, "DATANODE", "DATANODE"); hdfs.addServiceComponent(datanode); hdfs.addServiceComponent(namenode); @@ -1874,12 +1874,12 @@ public void testTransitionNonReportableHost() throws Exception { ServiceGroup serviceGroup = c1.addServiceGroup("CORE", stackId.getStackId()); Service service = c1.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repositoryVersion); - ServiceComponent sc = service.addServiceComponent("ZOOKEEPER_SERVER"); + ServiceComponent sc = service.addServiceComponent("ZOOKEEPER_SERVER", "ZOOKEEPER_SERVER"); sc.addServiceComponentHost("h-1"); sc.addServiceComponentHost("h-2"); service = c1.addService(serviceGroup, "SQOOP", "SQOOP", repositoryVersion); - sc = service.addServiceComponent("SQOOP"); + sc = service.addServiceComponent("SQOOP", "SQOOP"); sc.addServiceComponentHost("h-3"); HostEntity hostEntity = hostDAO.findByName("h-3"); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java index 112166882ab..8988645eaaa 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java @@ -374,7 +374,7 @@ private ServiceComponent addServiceComponent(Service service, serviceComponent = service.getServiceComponent(componentName); } catch (ServiceComponentNotFoundException e) { serviceComponent = serviceComponentFactory.createNew(service, - componentName); + componentName, componentName); service.addServiceComponent(serviceComponent); serviceComponent.setDesiredState(State.INSTALLED); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java index 438079a24f4..dfb7ef16b26 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java @@ -432,10 +432,10 @@ public void testDeleteCluster() throws Exception { //Assert.assertNotNull(injector.getInstance(ClusterServiceDAO.class).findByClusterAndServiceNames(c1, "HDFS")); - ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE"); - ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE"); + ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE", "NAMENODE"); + ServiceComponent dataNode = hdfs.addServiceComponent("DATANODE", "DATANODE"); - ServiceComponent serviceCheckNode = hdfs.addServiceComponent("HDFS_CLIENT"); + ServiceComponent serviceCheckNode = hdfs.addServiceComponent("HDFS_CLIENT", "HDFS_CLIENT"); ServiceComponentHost nameNodeHost = nameNode.addServiceComponentHost(h1); HostEntity nameNodeHostEntity = hostDAO.findByName(nameNodeHost.getHostName()); @@ -448,15 +448,9 @@ public void testDeleteCluster() throws Exception { Assert.assertNotNull(injector.getInstance(HostComponentStateDAO.class).findByIndex( nameNodeHost.getClusterId(), 1L, 1L, - nameNodeHost.getServiceComponentName(), nameNodeHostEntity.getHostId())); - - Assert.assertNotNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByIndex( - nameNodeHost.getClusterId(), - 1L, - 1L, - nameNodeHost.getServiceComponentName(), - nameNodeHostEntity.getHostId() - )); + nameNodeHost.getServiceComponentId(), nameNodeHostEntity.getHostId())); + + Assert.assertNotNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByIndex(nameNodeHost.getServiceComponentId())); Assert.assertEquals(2, injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM ClusterConfigEntity config").getResultList().size()); Assert.assertEquals(1, injector.getProvider(EntityManager.class).get().createQuery("SELECT state FROM ClusterStateEntity state").getResultList().size()); Assert.assertEquals(1, injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM ClusterConfigEntity config WHERE config.selected = 1").getResultList().size()); @@ -492,12 +486,9 @@ public void testDeleteCluster() throws Exception { Assert.assertEquals(2, hostDAO.findAll().size()); Assert.assertNull(injector.getInstance(HostComponentStateDAO.class).findByIndex( nameNodeHost.getClusterId(), 1L, 1L, - nameNodeHost.getServiceComponentName(), nameNodeHostEntity.getHostId())); + nameNodeHost.getServiceComponentId(), nameNodeHostEntity.getHostId())); - Assert.assertNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByIndex( - nameNodeHost.getClusterId(), 1L, 1L, - nameNodeHost.getServiceComponentName(), nameNodeHostEntity.getHostId() - )); + Assert.assertNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByIndex(nameNodeHost.getServiceComponentId())); Assert.assertEquals(0, injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM ClusterConfigEntity config").getResultList().size()); Assert.assertEquals(0, injector.getProvider(EntityManager.class).get().createQuery("SELECT state FROM ClusterStateEntity state").getResultList().size()); Assert.assertEquals(0, topologyRequestDAO.findByClusterId(cluster.getClusterId()).size()); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java index e3d76b323fe..c65b029dcb4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java @@ -243,7 +243,7 @@ private ServiceComponent addServiceComponent(Service service, serviceComponent = service.getServiceComponent(componentName); } catch (ServiceComponentNotFoundException e) { serviceComponent = serviceComponentFactory.createNew(service, - componentName); + componentName, componentName); service.addServiceComponent(serviceComponent); serviceComponent.setDesiredState(State.INSTALLED); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java index 8289a0db5b6..b3afd65cb0d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java @@ -139,7 +139,7 @@ public void setup() throws Exception { clusters.mapHostToCluster(hostName, "c1"); Service service = installService("HDFS"); - addServiceComponent(service, "NAMENODE"); + addServiceComponent(service, "NAMENODE", "NAMENODE"); } @After @@ -151,8 +151,8 @@ public void teardown() throws AmbariException, SQLException { */ @Test() public void testConcurrentWriteDeadlock() throws Exception { - ServiceComponentHost nameNodeSCH = createNewServiceComponentHost("HDFS", "NAMENODE", "c6401"); - ServiceComponentHost dataNodeSCH = createNewServiceComponentHost("HDFS", "DATANODE", "c6401"); + ServiceComponentHost nameNodeSCH = createNewServiceComponentHost("HDFS", "NAMENODE", "NAMENODE", "c6401"); + ServiceComponentHost dataNodeSCH = createNewServiceComponentHost("HDFS", "DATANODE", "DATANODE", "c6401"); List serviceComponentHosts = new ArrayList<>(); serviceComponentHosts.add(nameNodeSCH); @@ -229,10 +229,10 @@ private void setOsFamily(Host host, String osFamily, String osVersion) { } private ServiceComponentHost createNewServiceComponentHost(String svc, - String svcComponent, String hostName) throws AmbariException { + String svcComponentName, String svcComponentType, String hostName) throws AmbariException { Assert.assertNotNull(cluster.getConfigGroups()); Service s = installService(svc); - ServiceComponent sc = addServiceComponent(s, svcComponent); + ServiceComponent sc = addServiceComponent(s, svcComponentName, svcComponentType); ServiceComponentHost sch = serviceComponentHostFactory.createNew(sc, hostName); @@ -258,13 +258,13 @@ private Service installService(String serviceName) throws AmbariException { } private ServiceComponent addServiceComponent(Service service, - String componentName) throws AmbariException { + String componentName, String svcComponentType) throws AmbariException { ServiceComponent serviceComponent = null; try { serviceComponent = service.getServiceComponent(componentName); } catch (ServiceComponentNotFoundException e) { serviceComponent = serviceComponentFactory.createNew(service, - componentName); + componentName, svcComponentType); service.addServiceComponent(serviceComponent); serviceComponent.setDesiredState(State.INSTALLED); } diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java index 7a17ccc5025..3d233ee29b0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java @@ -202,7 +202,7 @@ private ServiceComponentHost createNewServiceComponentHost( try { sc = s.getServiceComponent(svcComponent); } catch (ServiceComponentNotFoundException e) { - sc = serviceComponentFactory.createNew(s, svcComponent); + sc = serviceComponentFactory.createNew(s, svcComponent, svcComponent); s.addServiceComponent(sc); } @@ -1053,26 +1053,14 @@ public void testMaintenance() throws Exception { ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName, customServiceGroup); ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName, customServiceGroup); - HostComponentDesiredStateEntity entity = hostComponentDesiredStateDAO.findByIndex( - cluster.getClusterId(), - customServiceGroup.getServiceGroupId(), - sch1.getServiceId(), - sch1.getServiceComponentName(), - hostEntity.getHostId() - ); + HostComponentDesiredStateEntity entity = hostComponentDesiredStateDAO.findByIndex(sch1.getServiceComponentId()); Assert.assertEquals(MaintenanceState.OFF, entity.getMaintenanceState()); Assert.assertEquals(MaintenanceState.OFF, sch1.getMaintenanceState()); sch1.setMaintenanceState(MaintenanceState.ON); Assert.assertEquals(MaintenanceState.ON, sch1.getMaintenanceState()); - entity = hostComponentDesiredStateDAO.findByIndex( - cluster.getClusterId(), - customServiceGroup.getServiceGroupId(), - sch1.getServiceId(), - sch1.getServiceComponentName(), - hostEntity.getHostId() - ); + entity = hostComponentDesiredStateDAO.findByIndex(sch1.getServiceComponentId()); Assert.assertEquals(MaintenanceState.ON, entity.getMaintenanceState()); } diff --git a/ambari-web/app/controllers/wizard/step8_controller.js b/ambari-web/app/controllers/wizard/step8_controller.js index 444981e86f0..1d90ae649d9 100644 --- a/ambari-web/app/controllers/wizard/step8_controller.js +++ b/ambari-web/app/controllers/wizard/step8_controller.js @@ -1177,6 +1177,7 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz }, this); selectedMasterComponents.mapProperty('component').uniq().forEach(function (component) { var hostNames = []; + let serviceName = App.StackServiceComponent.find().findProperty('componentName', component).get('serviceName'); if (masterOnAllHosts.length > 0) { var compOnAllHosts = false; for (var i=0; i < masterOnAllHosts.length; i++) { @@ -1187,11 +1188,11 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz } if (!compOnAllHosts) { hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName'); - this.registerHostsToComponent(hostNames, component); + this.registerHostsToComponent(hostNames, component, serviceName); } } else { hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName'); - this.registerHostsToComponent(hostNames, component); + this.registerHostsToComponent(hostNames, component, serviceName); } }, this); }, @@ -1253,6 +1254,7 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz var hostNames = []; var compOnAllHosts; if (_slave.componentName !== 'CLIENT') { + let serviceName = App.StackServiceComponent.find().findProperty('componentName', _slave.componentName).get('serviceName'); if (slaveOnAllHosts.length > 0) { compOnAllHosts = false; for (var i=0; i < slaveOnAllHosts.length; i++) { @@ -1265,16 +1267,19 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz } if (!compOnAllHosts) { hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName'); - this.registerHostsToComponent(hostNames, _slave.componentName); + this.registerHostsToComponent(hostNames, _slave.componentName, serviceName); } } else { hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName'); - this.registerHostsToComponent(hostNames, _slave.componentName); + this.registerHostsToComponent(hostNames, _slave.componentName, serviceName); } } else { clients.forEach(function (_client) { hostNames = _slave.hosts.mapProperty('hostName'); + let compName = _client.component_name + let serviceName = App.StackServiceComponent.find().findProperty('componentName', compName).get('serviceName') + // The below logic to install clients to existing/New master hosts should not be applied to Add Host wizard. // This is with the presumption that Add Host controller does not add any new Master component to the cluster if (!this.get('isAddHost')) { @@ -1305,11 +1310,11 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz } if (!compOnAllHosts) { hostNames = hostNames.uniq(); - this.registerHostsToComponent(hostNames, _client.component_name); + this.registerHostsToComponent(hostNames, _client.component_name, serviceName); } } else { hostNames = hostNames.uniq(); - this.registerHostsToComponent(hostNames, _client.component_name); + this.registerHostsToComponent(hostNames, _client.component_name, serviceName); } }, this); } @@ -1366,7 +1371,8 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz // If a dependency for being co-hosted is derived between existing client and selected new master but that // dependency is already satisfied in the cluster then disregard the derived dependency this.removeClientsFromList(_clientName, hostNames); - this.registerHostsToComponent(hostNames, _clientName); + let serviceName = App.StackServiceComponent.find().findProperty('componentName', _clientName).get('serviceName') + this.registerHostsToComponent(hostNames, _clientName, serviceName); if(hostNames.length > 0) { this.get('content.additionalClients').pushObject({hostNames: hostNames, componentName: _clientName}); } @@ -1415,9 +1421,9 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz this.get('content.services').filterProperty('isSelected').forEach(function (service) { service.get('serviceComponents').filterProperty('isRequiredOnAllHosts').forEach(function (component) { if (service.get('isInstalled') && notInstalledHosts.length) { - this.registerHostsToComponent(notInstalledHosts.mapProperty('hostName'), component.get('componentName')); + this.registerHostsToComponent(notInstalledHosts.mapProperty('hostName'), component.get('componentName'), component.get('serviceName')); } else if (!service.get('isInstalled') && registeredHosts.length) { - this.registerHostsToComponent(registeredHosts.mapProperty('hostName'), component.get('componentName')); + this.registerHostsToComponent(registeredHosts.mapProperty('hostName'), component.get('componentName'), component.get('serviceName')); } }, this); }, this); @@ -1427,9 +1433,9 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz if (hiveService) { var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database'); if (hiveDb.value === "New MySQL Database") { - this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER'); + this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER', 'HIVE'); } else if (hiveDb.value === "New PostgreSQL Database") { - this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'POSTGRESQL_SERVER'); + this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'POSTGRESQL_SERVER', 'HIVE'); } } }, @@ -1441,7 +1447,7 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz * @param {String} componentName * @method registerHostsToComponent */ - registerHostsToComponent: function (hostNames, componentName) { + registerHostsToComponent: function (hostNames, componentName, serviceName) { if (!hostNames.length) return; var queryStr = ''; @@ -1459,7 +1465,9 @@ App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wiz "host_components": [ { "HostRoles": { - "component_name": componentName + "component_name": componentName, + "service_group_name": App.get('defaultServiceGroupName'), + "service_name": serviceName } } ]