You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by wu...@apache.org on 2022/11/24 08:05:39 UTC
[ambari] branch trunk updated: AMBARI-25634: Code cleanup: Remove AgentResource class as it is not needed anymore (#3566)
This is an automated email from the ASF dual-hosted git repository.
wuzhiguo pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 201f5a596c AMBARI-25634: Code cleanup: Remove AgentResource class as it is not needed anymore (#3566)
201f5a596c is described below
commit 201f5a596c7d5f5044c12f1e0e11740bf9400c8e
Author: Yu Hou <52...@qq.com>
AuthorDate: Thu Nov 24 16:05:34 2022 +0800
AMBARI-25634: Code cleanup: Remove AgentResource class as it is not needed anymore (#3566)
---
.../ambari/server/agent/rest/AgentResource.java | 177 ---------
.../ambari/server/controller/AmbariServer.java | 4 +-
.../ambari/server/agent/AgentResourceTest.java | 409 ---------------------
.../ambari/server/topology/AmbariContextTest.java | 17 +-
4 files changed, 15 insertions(+), 592 deletions(-)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
deleted file mode 100644
index cf6d57b04d..0000000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.agent.rest;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.ambari.annotations.ApiIgnore;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.agent.ComponentsResponse;
-import org.apache.ambari.server.agent.HeartBeat;
-import org.apache.ambari.server.agent.HeartBeatHandler;
-import org.apache.ambari.server.agent.HeartBeatResponse;
-import org.apache.ambari.server.agent.Register;
-import org.apache.ambari.server.agent.RegistrationResponse;
-import org.apache.ambari.server.agent.RegistrationStatus;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Inject;
-
-/**
- * Agent Resource represents Ambari agent controller.
- * It provides API for Ambari agents to get the cluster configuration changes
- * as well as report the node attributes and state of services running the on
- * the cluster nodes
- */
-@Path("/")
-public class AgentResource {
- private static HeartBeatHandler hh;
- private static final Logger LOG = LoggerFactory.getLogger(AgentResource.class);
-
- @Inject
- public static void init(HeartBeatHandler instance) {
- hh = instance;
- //hh.start();
- }
-
- /**
- * Explicitly start HH
- */
- public static void startHeartBeatHandler() {
- hh.start();
- }
-
- /**
- * Register information about the host (Internal API to be used for
- * Ambari Agent)
- * @response.representation.200.doc This API is invoked by Ambari agent running
- * on a cluster to register with the server.
- * @response.representation.200.mediaType application/json
- * @response.representation.406.doc Error in register message format
- * @response.representation.408.doc Request Timed out
- * @param message Register message
- * @throws InvalidStateTransitionException
- * @throws AmbariException
- * @throws Exception
- */
- @Path("register/{hostName}")
- @POST @ApiIgnore // until documented
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces({MediaType.APPLICATION_JSON})
- public RegistrationResponse register(Register message,
- @Context HttpServletRequest req)
- throws WebApplicationException, InvalidStateTransitionException {
- /* Call into the heartbeat handler */
-
- RegistrationResponse response = null;
- try {
- response = hh.handleRegistration(message);
- LOG.debug("Sending registration response {}", response);
- } catch (AmbariException ex) {
- response = new RegistrationResponse();
- response.setResponseId(-1);
- response.setResponseStatus(RegistrationStatus.FAILED);
- response.setExitstatus(1);
- response.setLog(ex.getMessage());
- return response;
- }
- return response;
- }
-
- /**
- * Update state of the node (Internal API to be used by Ambari agent).
- *
- * @response.representation.200.doc This API is invoked by Ambari agent running
- * on a cluster to update the state of various services running on the node.
- * @response.representation.200.mediaType application/json
- * @response.representation.406.doc Error in heartbeat message format
- * @response.representation.408.doc Request Timed out
- * @param message Heartbeat message
- * @throws Exception
- */
- @Path("heartbeat/{hostName}")
- @POST @ApiIgnore // until documented
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces({MediaType.APPLICATION_JSON})
- public HeartBeatResponse heartbeat(HeartBeat message)
- throws WebApplicationException {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Received Heartbeat message {}", message);
- }
- HeartBeatResponse heartBeatResponse;
- try {
- heartBeatResponse = hh.handleHeartBeat(message);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Sending heartbeat response with response id {}", heartBeatResponse.getResponseId());
- LOG.debug("Response details {}", heartBeatResponse);
- }
- } catch (Exception e) {
- LOG.warn("Error in HeartBeat", e);
- throw new WebApplicationException(500);
- }
- return heartBeatResponse;
- }
-
- /**
- * Retrieves the components category map for stack used on cluster
- * (Internal API to be used by Ambari agent).
- *
- * @response.representation.200.doc This API is invoked by Ambari agent running
- * on a cluster to update the components category map of stack used by this cluster
- * @response.representation.200.mediaType application/json
- * @response.representation.408.doc Request Timed out
- * @param clusterName of cluster
- * @throws Exception
- */
- @Path("components/{clusterName}")
- @GET @ApiIgnore // until documented
- @Produces({MediaType.APPLICATION_JSON})
- public ComponentsResponse components(
- @PathParam("clusterName") String clusterName) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Received Components request for cluster {}", clusterName);
- }
-
- ComponentsResponse componentsResponse;
-
- try {
- componentsResponse = hh.handleComponents(clusterName);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Sending components response");
- LOG.debug("Response details {}", componentsResponse);
- }
- } catch (Exception e) {
- LOG.warn("Error in Components", e);
- throw new WebApplicationException(500);
- }
-
- return componentsResponse;
- }
-}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index 5dbf372dc9..a2b66e4a34 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -39,7 +39,6 @@ import org.apache.ambari.server.StaticallyInject;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
import org.apache.ambari.server.agent.HeartBeatHandler;
-import org.apache.ambari.server.agent.rest.AgentResource;
import org.apache.ambari.server.api.AmbariErrorHandler;
import org.apache.ambari.server.api.AmbariPersistFilter;
import org.apache.ambari.server.api.ContentTypeOverrideFilter;
@@ -496,7 +495,7 @@ public class AmbariServer {
agentroot.addServlet(agent, "/agent/v1/*");
agent.setInitOrder(3);
- AgentResource.startHeartBeatHandler();
+ injector.getInstance(HeartBeatHandler.class).start();
LOG.info("********** Started Heartbeat handler **********");
ServletHolder cert = new ServletHolder(ServletContainer.class);
@@ -909,7 +908,6 @@ public class AmbariServer {
*/
@Deprecated
public void performStaticInjection() {
- AgentResource.init(injector.getInstance(HeartBeatHandler.class));
CertificateDownload.init(injector.getInstance(CertificateManager.class));
ConnectionInfo.init(injector.getInstance(Configuration.class));
CertificateSign.init(injector.getInstance(CertificateManager.class));
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
deleted file mode 100644
index acc1168070..0000000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.server.agent;
-
-import static org.easymock.EasyMock.createNiceMock;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import javax.persistence.EntityManager;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.ambari.server.RandomPortJerseyTest;
-import org.apache.ambari.server.actionmanager.ActionDBAccessor;
-import org.apache.ambari.server.actionmanager.ActionManager;
-import org.apache.ambari.server.actionmanager.ExecutionCommandWrapperFactory;
-import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
-import org.apache.ambari.server.actionmanager.HostRoleCommandFactoryImpl;
-import org.apache.ambari.server.actionmanager.RequestFactory;
-import org.apache.ambari.server.actionmanager.StageFactory;
-import org.apache.ambari.server.agent.rest.AgentResource;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.configuration.AmbariServerConfiguration;
-import org.apache.ambari.server.controller.AbstractRootServiceResponseFactory;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.KerberosHelper;
-import org.apache.ambari.server.controller.RootServiceResponseFactory;
-import org.apache.ambari.server.events.AgentConfigsUpdateEvent;
-import org.apache.ambari.server.events.AmbariEvent;
-import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
-import org.apache.ambari.server.hooks.AmbariEventFactory;
-import org.apache.ambari.server.hooks.HookContext;
-import org.apache.ambari.server.hooks.HookContextFactory;
-import org.apache.ambari.server.hooks.HookService;
-import org.apache.ambari.server.hooks.users.PostUserCreationHookContext;
-import org.apache.ambari.server.hooks.users.UserCreatedEvent;
-import org.apache.ambari.server.hooks.users.UserHookService;
-import org.apache.ambari.server.ldap.service.AmbariLdapConfigurationProvider;
-import org.apache.ambari.server.ldap.service.LdapFacade;
-import org.apache.ambari.server.metadata.CachedRoleCommandOrderProvider;
-import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
-import org.apache.ambari.server.mpack.MpackManagerFactory;
-import org.apache.ambari.server.orm.DBAccessor;
-import org.apache.ambari.server.orm.dao.HostDAO;
-import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
-import org.apache.ambari.server.scheduler.ExecutionScheduler;
-import org.apache.ambari.server.scheduler.ExecutionSchedulerImpl;
-import org.apache.ambari.server.security.SecurityHelper;
-import org.apache.ambari.server.security.SecurityHelperImpl;
-import org.apache.ambari.server.security.encryption.AESEncryptionService;
-import org.apache.ambari.server.security.encryption.CredentialStoreService;
-import org.apache.ambari.server.security.encryption.CredentialStoreServiceImpl;
-import org.apache.ambari.server.security.encryption.EncryptionService;
-import org.apache.ambari.server.security.encryption.Encryptor;
-import org.apache.ambari.server.stack.StackManagerFactory;
-import org.apache.ambari.server.stack.upgrade.orchestrate.UpgradeContextFactory;
-import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Config;
-import org.apache.ambari.server.state.ConfigFactory;
-import org.apache.ambari.server.state.ConfigImpl;
-import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.Service;
-import org.apache.ambari.server.state.ServiceComponent;
-import org.apache.ambari.server.state.ServiceComponentFactory;
-import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceComponentHostFactory;
-import org.apache.ambari.server.state.ServiceComponentImpl;
-import org.apache.ambari.server.state.ServiceFactory;
-import org.apache.ambari.server.state.ServiceImpl;
-import org.apache.ambari.server.state.cluster.ClusterFactory;
-import org.apache.ambari.server.state.cluster.ClusterImpl;
-import org.apache.ambari.server.state.configgroup.ConfigGroup;
-import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
-import org.apache.ambari.server.state.configgroup.ConfigGroupImpl;
-import org.apache.ambari.server.state.host.HostFactory;
-import org.apache.ambari.server.state.host.HostImpl;
-import org.apache.ambari.server.state.scheduler.RequestExecution;
-import org.apache.ambari.server.state.scheduler.RequestExecutionFactory;
-import org.apache.ambari.server.state.scheduler.RequestExecutionImpl;
-import org.apache.ambari.server.state.stack.OsFamily;
-import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
-import org.apache.ambari.server.topology.PersistedState;
-import org.apache.ambari.server.topology.tasks.ConfigureClusterTaskFactory;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.easymock.EasyMock;
-import org.eclipse.jetty.server.session.SessionHandler;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import org.springframework.security.crypto.password.StandardPasswordEncoder;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.TypeLiteral;
-import com.google.inject.assistedinject.FactoryModuleBuilder;
-import com.google.inject.name.Names;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-import com.sun.jersey.test.framework.WebAppDescriptor;
-
-import junit.framework.Assert;
-
-
-public class AgentResourceTest extends RandomPortJerseyTest {
- static String PACKAGE_NAME = "org.apache.ambari.server.agent.rest";
- private static final Logger LOG = LoggerFactory.getLogger(AgentResourceTest.class);
- protected Client client;
- HeartBeatHandler handler;
- ActionManager actionManager;
- SessionHandler sessionHandler;
- Injector injector;
- AmbariMetaInfo ambariMetaInfo;
- OsFamily os_family;
- ActionDBAccessor actionDBAccessor;
-
- public AgentResourceTest() {
- super(new WebAppDescriptor.Builder(PACKAGE_NAME).servletClass(ServletContainer.class)
- .initParam("com.sun.jersey.api.json.POJOMappingFeature", "true")
- .build());
- }
-
- public static <T> T getJsonFormString(String json, Class<T> type) {
- GsonBuilder gsonBuilder = new GsonBuilder();
- gsonBuilder.serializeNulls();
- Gson gson = gsonBuilder.create();
- return gson.fromJson(json, type);
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- handler = mock(HeartBeatHandler.class);
- injector = Guice.createInjector(new MockModule());
- injector.injectMembers(handler);
- }
-
- private JSONObject createDummyJSONRegister() throws JSONException {
- JSONObject json = new JSONObject();
- json.put("responseId", -1);
- json.put("timestamp", System.currentTimeMillis());
- json.put("hostname", "dummyHost");
- return json;
- }
-
- private JSONObject createDummyHeartBeat() throws JSONException {
- JSONObject json = new JSONObject();
- json.put("responseId", -1);
- json.put("timestamp", System.currentTimeMillis());
- json.put("hostname", "dummyHost");
- return json;
- }
-
- private JSONObject createDummyHeartBeatWithAgentEnv() throws JSONException {
- JSONObject json = new JSONObject();
- json.put("responseId", -1);
- json.put("timestamp", System.currentTimeMillis());
- json.put("hostname", "dummyHost");
-
- JSONObject agentEnv = new JSONObject();
- json.put("agentEnv", agentEnv);
- return json;
- }
-
- @Test
- public void agentRegistration() throws UniformInterfaceException, JSONException {
- RegistrationResponse response;
- ClientConfig clientConfig = new DefaultClientConfig();
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- client = Client.create(clientConfig);
- WebResource webResource = client.resource(String.format("http://localhost:%d/register/dummyhost", getTestPort()));
- response = webResource.type(MediaType.APPLICATION_JSON)
- .post(RegistrationResponse.class, createDummyJSONRegister());
- LOG.info("Returned from Server responce=" + response);
- Assert.assertEquals(response.getResponseStatus(), RegistrationStatus.OK);
- }
-
- @Test
- public void agentHeartBeat() throws UniformInterfaceException, JSONException {
- HeartBeatResponse response;
- ClientConfig clientConfig = new DefaultClientConfig();
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- client = Client.create(clientConfig);
- WebResource webResource = client.resource(String.format("http://localhost:%d/heartbeat/dummyhost", getTestPort()));
- response = webResource.type(MediaType.APPLICATION_JSON)
- .post(HeartBeatResponse.class, createDummyHeartBeat());
- LOG.info("Returned from Server: "
- + " response=" + response);
- Assert.assertEquals(response.getResponseId(), 0L);
- }
-
- @Test
- public void agentHeartBeatWithEnv() throws UniformInterfaceException, JSONException {
- HeartBeatResponse response;
- ClientConfig clientConfig = new DefaultClientConfig();
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- client = Client.create(clientConfig);
- WebResource webResource = client.resource(String.format("http://localhost:%d/heartbeat/dummyhost", getTestPort()));
- response = webResource.type(MediaType.APPLICATION_JSON)
- .post(HeartBeatResponse.class, createDummyHeartBeatWithAgentEnv());
- LOG.info("Returned from Server: "
- + " response=" + response);
- Assert.assertEquals(response.getResponseId(), 0L);
- }
-
- @Test
- public void deserializeClasses() {
- String DirectoryJSON = "[{name:'/var/lib', type:'directory'},{name:'b', type:'directory'}]";
- String PackageDetailJSON = "[{name:'abc', version:'2.3', repoName:'HDP'},{name:'abc', version:'3.3', repoName:'HDP-epel'}]";
- String ExistingUserJSON = "[{name:'hdfs', homeDir:'/var/lib/hadoop', status:''}, " +
- "{name:'ambari_qa', homeDir:'/var/home/ambari_qa',status:'None'}]";
- String JavaProcJSON = "[{user:'root', pid:'355', hadoop:'True'}, " +
- "{user:'hdfs', pid:'325', hadoop:'False'}]";
- String AlternativeJSON = "[{name:'/etc/alternatives/hdfs-conf', target:'/etc/hadoop/conf.dist'}, " +
- "{name:'abc', target:'def'}]";
- String AgentEnvJSON = "{\"alternatives\": " + AlternativeJSON +
- ", \"existingUsers\": "+ ExistingUserJSON +
- ", \"umask\": \"18\", \"installedPackages\": "+
- PackageDetailJSON +", \"stackFoldersAndFiles\": "+ DirectoryJSON +
- ", \"firewallRunning\": \"true\", \"firewallName\": \"iptables\", \"transparentHugePage\": \"never\", \"hasUnlimitedJcePolicy\" : true}";
- AgentEnv.Directory[] dirs = getJsonFormString(
- DirectoryJSON, AgentEnv.Directory[].class);
- Assert.assertEquals("/var/lib", dirs[0].getName());
- Assert.assertEquals("directory", dirs[1].getType());
-
- AgentEnv.PackageDetail[] pkgs = getJsonFormString(
- PackageDetailJSON, AgentEnv.PackageDetail[].class);
- Assert.assertEquals("abc", pkgs[0].getName());
- Assert.assertEquals("HDP", pkgs[0].getRepoName());
- Assert.assertEquals("3.3", pkgs[1].getVersion());
-
- AgentEnv.ExistingUser[] users = getJsonFormString(
- ExistingUserJSON, AgentEnv.ExistingUser[].class);
- Assert.assertEquals("hdfs", users[0].getUserName());
- Assert.assertEquals("/var/lib/hadoop", users[0].getUserHomeDir());
- Assert.assertEquals("None", users[1].getUserStatus());
-
- AgentEnv.JavaProc[] procs = getJsonFormString(
- JavaProcJSON, AgentEnv.JavaProc[].class);
- Assert.assertEquals("root", procs[0].getUser());
- Assert.assertEquals(355, procs[0].getPid());
- Assert.assertEquals(false, procs[1].isHadoop());
-
- AgentEnv.Alternative[] alternatives = getJsonFormString(
- AlternativeJSON, AgentEnv.Alternative[].class);
- Assert.assertEquals("/etc/alternatives/hdfs-conf", alternatives[0].getName());
- Assert.assertEquals("/etc/hadoop/conf.dist", alternatives[0].getTarget());
- Assert.assertEquals("abc", alternatives[1].getName());
- Assert.assertEquals("def", alternatives[1].getTarget());
-
- AgentEnv agentEnv = getJsonFormString(
- AgentEnvJSON, AgentEnv.class);
- Assert.assertTrue(18 == agentEnv.getUmask());
- Assert.assertEquals("never", agentEnv.getTransparentHugePage());
- Assert.assertTrue(agentEnv.getHasUnlimitedJcePolicy());
- Assert.assertTrue(Boolean.TRUE == agentEnv.getFirewallRunning());
- Assert.assertEquals("iptables", agentEnv.getFirewallName());
- Assert.assertEquals("/etc/alternatives/hdfs-conf", agentEnv.getAlternatives()[0].getName());
- Assert.assertEquals("/etc/hadoop/conf.dist", agentEnv.getAlternatives()[0].getTarget());
- Assert.assertEquals("abc", agentEnv.getAlternatives()[1].getName());
- Assert.assertEquals("def", agentEnv.getAlternatives()[1].getTarget());
- Assert.assertEquals("abc", agentEnv.getInstalledPackages()[0].getName());
- Assert.assertEquals("HDP", agentEnv.getInstalledPackages()[0].getRepoName());
- Assert.assertEquals("3.3", agentEnv.getInstalledPackages()[1].getVersion());
- Assert.assertEquals("hdfs", agentEnv.getExistingUsers()[0].getUserName());
- Assert.assertEquals("/var/lib/hadoop", agentEnv.getExistingUsers()[0].getUserHomeDir());
- Assert.assertEquals("None", agentEnv.getExistingUsers()[1].getUserStatus());
- Assert.assertEquals("/var/lib", agentEnv.getStackFoldersAndFiles()[0].getName());
- Assert.assertEquals("directory", agentEnv.getStackFoldersAndFiles()[1].getType());
- }
-
- @Test
- public void agentComponents() {
- ComponentsResponse response;
- ClientConfig clientConfig = new DefaultClientConfig();
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- client = Client.create(clientConfig);
- WebResource webResource = client.resource(String.format("http://localhost:%d/components/dummycluster", getTestPort()));
- response = webResource.get(ComponentsResponse.class);
- Assert.assertEquals(response.getClusterName(), "dummycluster");
- }
-
- public class MockModule extends AbstractModule {
-
- RegistrationResponse response = new RegistrationResponse();
- HeartBeatResponse hresponse = new HeartBeatResponse();
- ComponentsResponse componentsResponse = new ComponentsResponse();
-
- @Override
- protected void configure() {
- installDependencies();
-
- handler = mock(HeartBeatHandler.class);
- response.setResponseStatus(RegistrationStatus.OK);
- hresponse.setResponseId(0L);
- componentsResponse.setClusterName("dummycluster");
- try {
- when(handler.handleRegistration(any(Register.class))).thenReturn(
- response);
- when(handler.handleHeartBeat(any(HeartBeat.class))).thenReturn(
- hresponse);
- when(handler.handleComponents(any(String.class))).thenReturn(
- componentsResponse);
- } catch (Exception ex) {
- // The test will fail anyway
- }
- requestStaticInjection(AgentResource.class);
- os_family = mock(OsFamily.class);
- actionManager = mock(ActionManager.class);
- ambariMetaInfo = mock(AmbariMetaInfo.class);
- actionDBAccessor = mock(ActionDBAccessor.class);
- sessionHandler = mock(SessionHandler.class);
- bind(OsFamily.class).toInstance(os_family);
- bind(ActionDBAccessor.class).toInstance(actionDBAccessor);
- bind(ActionManager.class).toInstance(actionManager);
- bind(SessionHandler.class).toInstance(sessionHandler);
- bind(AgentCommand.class).to(ExecutionCommand.class);
- bind(AbstractRootServiceResponseFactory.class).to(RootServiceResponseFactory.class);
- bind(CredentialStoreService.class).to(CredentialStoreServiceImpl.class);
- bind(PasswordEncoder.class).toInstance(new StandardPasswordEncoder());
- bind(HookService.class).to(UserHookService.class);
- bind(ExecutionScheduler.class).to(ExecutionSchedulerImpl.class);
- bind(HeartBeatHandler.class).toInstance(handler);
- bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
- bind(DBAccessor.class).toInstance(mock(DBAccessor.class));
- bind(HostRoleCommandDAO.class).toInstance(mock(HostRoleCommandDAO.class));
- bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
- bind(HostDAO.class).toInstance(createNiceMock(HostDAO.class));
- bind(Clusters.class).toInstance(createNiceMock(Clusters.class));
- bind(PersistedState.class).toInstance(createNiceMock(PersistedState.class));
- bind(RoleCommandOrderProvider.class).to(CachedRoleCommandOrderProvider.class);
- bind(AmbariManagementController.class).toInstance(createNiceMock(AmbariManagementController.class));
- bind(KerberosHelper.class).toInstance(createNiceMock(KerberosHelper.class));
- bind(MpackManagerFactory.class).toInstance(createNiceMock(MpackManagerFactory.class));
- bind(EncryptionService.class).to(AESEncryptionService.class);
- bind(new TypeLiteral<Encryptor<AgentConfigsUpdateEvent>>() {}).annotatedWith(Names.named("AgentConfigEncryptor")).toInstance(Encryptor.NONE);
- bind(new TypeLiteral<Encryptor<Config>>() {}).annotatedWith(Names.named("ConfigPropertiesEncryptor")).toInstance(Encryptor.NONE);
- bind(new TypeLiteral<Encryptor<AmbariServerConfiguration>>() {}).annotatedWith(Names.named("AmbariServerConfigurationEncryptor")).toInstance(Encryptor.NONE);
- bind(LdapFacade.class).toInstance(createNiceMock(LdapFacade.class));
- bind(AmbariLdapConfigurationProvider.class).toInstance(createNiceMock(AmbariLdapConfigurationProvider.class));
- }
-
- private void installDependencies() {
- install(new FactoryModuleBuilder().build(UpgradeContextFactory.class));
- install(new FactoryModuleBuilder().build(RoleGraphFactory.class));
- install(new FactoryModuleBuilder().implement(
- Cluster.class, ClusterImpl.class).build(ClusterFactory.class));
- install(new FactoryModuleBuilder().implement(
- Host.class, HostImpl.class).build(HostFactory.class));
- install(new FactoryModuleBuilder().implement(
- Service.class, ServiceImpl.class).build(ServiceFactory.class));
- install(new FactoryModuleBuilder().implement(
- ServiceComponent.class, ServiceComponentImpl.class).build(
- ServiceComponentFactory.class));
- install(new FactoryModuleBuilder().implement(
- ServiceComponentHost.class, ServiceComponentHostImpl.class).build(
- ServiceComponentHostFactory.class));
- install(new FactoryModuleBuilder().implement(
- Config.class, ConfigImpl.class).build(ConfigFactory.class));
- install(new FactoryModuleBuilder().implement(
- ConfigGroup.class, ConfigGroupImpl.class).build(ConfigGroupFactory.class));
- install(new FactoryModuleBuilder().implement(RequestExecution.class,
- RequestExecutionImpl.class).build(RequestExecutionFactory.class));
- install(new FactoryModuleBuilder().build(StageFactory.class));
- install(new FactoryModuleBuilder().build(ExecutionCommandWrapperFactory.class));
- install(new FactoryModuleBuilder().build(ConfigureClusterTaskFactory.class));
-
- install(new FactoryModuleBuilder().build(RequestFactory.class));
- install(new FactoryModuleBuilder().implement(AmbariEvent.class, Names.named("userCreated"), UserCreatedEvent.class)
- .build(AmbariEventFactory.class));
- install(new FactoryModuleBuilder().implement(HookContext.class, PostUserCreationHookContext.class)
- .build(HookContextFactory.class));
-
-
- bind(HostRoleCommandFactory.class).to(HostRoleCommandFactoryImpl.class);
- bind(SecurityHelper.class).toInstance(SecurityHelperImpl.getInstance());
- bind(AmbariEventPublisher.class).toInstance(EasyMock.createMock(AmbariEventPublisher.class));
- bind(StackManagerFactory.class).toInstance(
- EasyMock.createMock(StackManagerFactory.class));
- }
- }
-}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
index dbab576620..bebbb25023 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
@@ -88,6 +88,7 @@ import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.inject.Provider;
/**
* AmbariContext unit tests
@@ -127,6 +128,8 @@ public class AmbariContextTest {
private static final Host host2 = createNiceMock(Host.class);
private static final ConfigFactory configFactory = createNiceMock(ConfigFactory.class);
private static final Service mockService1 = createStrictMock(Service.class);
+ private static final Provider<ConfigHelper> mockConfigHelperProvider = createNiceMock(Provider.class);
+ private static final ConfigHelper mockConfigHelper = createNiceMock(ConfigHelper.class);
private static final Collection<String> blueprintServices = new HashSet<>();
private static final Map<String, Service> clusterServices = new HashMap<>();
@@ -165,6 +168,10 @@ public class AmbariContextTest {
f.setAccessible(true);
f.set(null, hostComponentResourceProvider);
+ f = clazz.getDeclaredField("configHelper");
+ f.setAccessible(true);
+ f.set(context, mockConfigHelperProvider);
+
// bp configuration
Map<String, Map<String, String>> bpProperties = new HashMap<>();
Map<String, String> bpType1Props = new HashMap<>();
@@ -273,23 +280,27 @@ public class AmbariContextTest {
expect(configGroup1.getName()).andReturn(String.format("%s:%s", BP_NAME, HOST_GROUP_1)).anyTimes();
expect(configGroup2.getName()).andReturn(String.format("%s:%s", BP_NAME, HOST_GROUP_2)).anyTimes();
+ expect(mockConfigHelperProvider.get()).andReturn(mockConfigHelper).anyTimes();
}
@After
public void tearDown() throws Exception {
verify(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider,
hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters,
- cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory);
+ cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory,
+ mockConfigHelperProvider, mockConfigHelper);
reset(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider,
hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters,
- cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory);
+ cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory,
+ mockConfigHelperProvider, mockConfigHelper);
}
private void replayAll() {
replay(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider,
hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters,
- cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory);
+ cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory,
+ mockConfigHelperProvider, mockConfigHelper);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org