AmbariManagementControllerImpl implements AmbariManagementController { @Override public String getAmbariServerURI(String path) { if(masterProtocol==null || masterHostname==null || masterPort==null) { return null; } URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(masterProtocol); uriBuilder.setHost(masterHostname); uriBuilder.setPort(masterPort); String[] parts = path.split("\\?"); if (parts.length > 1) { uriBuilder.setPath(parts[0]); uriBuilder.setQuery(parts[1]); } else { uriBuilder.setPath(path); } return uriBuilder.toString(); } @Inject  AmbariManagementControllerImpl(ActionManager actionManager,
      Clusters clusters, Injector injector); @Override String getAmbariServerURI(String path); @Override RoleCommandOrder getRoleCommandOrder(Cluster cluster); @Override void createCluster(ClusterRequest request); @Override synchronized void createHostComponents(Set<ServiceComponentHostRequest> requests); @Override void registerRackChange(String clusterName); @Override synchronized ConfigurationResponse createConfiguration(
      ConfigurationRequest request); @Override Config createConfig(Cluster cluster, String type, Map<String, String> properties,
                             String versionTag, Map<String, Map<String, String>> propertiesAttributes); @Override void createUsers(Set<UserRequest> requests); @Override void createGroups(Set<GroupRequest> requests); @Override void createMembers(Set<MemberRequest> requests); @Override Set<MemberResponse> getMembers(Set<MemberRequest> requests); @Override @SuppressWarnings("unchecked") synchronized void updateMembers(Set<MemberRequest> requests); @Override MaintenanceState getEffectiveMaintenanceState(ServiceComponentHost sch); @Override @Transactional synchronized RequestStatusResponse updateClusters(Set<ClusterRequest> requests,
                                                           Map<String, String> requestProperties); boolean isAttributeMapsEqual(Map<String, Map<String, String>> requestConfigAttributes,
          Map<String, Map<String, String>> clusterConfigAttributes); void saveClusterUpdate(ClusterRequest clusterRequest, ClusterResponse clusterResponse); @Override ClusterResponse getClusterUpdateResults(ClusterRequest clusterRequest); @Override String getJobTrackerHost(Cluster cluster); @Override Map<String, Map<String,String>> findConfigurationTagsWithOverrides(
          Cluster cluster, String hostName); @Override RequestExecutionFactory getRequestExecutionFactory(); @Override ExecutionScheduleManager getExecutionScheduleManager(); @Override List<ServiceOsSpecific.Package> getPackagesForServiceHost(ServiceInfo serviceInfo, Map<String, String> hostParams, String osFamily); @Override ExecutionCommand getExecutionCommand(Cluster cluster,
                                              ServiceComponentHost scHost,
                                              RoleCommand roleCommand); @Override Set<StackConfigurationDependencyResponse> getStackConfigurationDependencies(
          Set<StackConfigurationDependencyRequest> requests); @Override RequestStatusResponse createAndPersistStages(Cluster cluster, Map<String, String> requestProperties,
                                                      Map<String, String> requestParameters,
                                                      Map<State, List<Service>> changedServices,
                                                      Map<State, List<ServiceComponent>> changedComponents,
                                                      Map<String, Map<State, List<ServiceComponentHost>>> changedHosts,
                                                      Collection<ServiceComponentHost> ignoredHosts,
                                                      boolean runSmokeTest, boolean reconfigureClients); @Override RequestStageContainer addStages(RequestStageContainer requestStages, Cluster cluster, Map<String, String> requestProperties,
                                 Map<String, String> requestParameters, Map<State, List<Service>> changedServices,
                                 Map<State, List<ServiceComponent>> changedComponents,
                                 Map<String, Map<State, List<ServiceComponentHost>>> changedHosts,
                                 Collection<ServiceComponentHost> ignoredHosts, boolean runSmokeTest,
                                 boolean reconfigureClients); void validateServiceComponentHostRequest(ServiceComponentHostRequest request); @Override String findServiceName(Cluster cluster, String componentName); @Override synchronized void updateUsers(Set<UserRequest> requests); @Override synchronized void deleteCluster(ClusterRequest request); @Override DeleteStatusMetaData deleteHostComponents(
      Set<ServiceComponentHostRequest> requests); @Override void deleteUsers(Set<UserRequest> requests); @Override void deleteGroups(Set<GroupRequest> requests); @Override void deleteMembers(java.util.Set<MemberRequest> requests); @Override Set<ClusterResponse> getClusters(Set<ClusterRequest> requests); @Override Set<ServiceComponentHostResponse> getHostComponents(
      Set<ServiceComponentHostRequest> requests); @Override Set<ConfigurationResponse> getConfigurations(
      Set<ConfigurationRequest> requests); @Override Set<ServiceConfigVersionResponse> getServiceConfigVersions(Set<ServiceConfigVersionRequest> requests); @Override Set<UserResponse> getUsers(Set<UserRequest> requests); @Override Set<GroupResponse> getGroups(Set<GroupRequest> requests); @Override void updateGroups(Set<GroupRequest> requests); @Override List<String> selectHealthyHosts(Set<String> hostList); @Override String getHealthyHost(Set<String> hostList); @Override RequestStatusResponse createAction(ExecuteActionRequest actionRequest,
      Map<String, String> requestProperties); @Override Set<StackResponse> getStacks(Set<StackRequest> requests); @Override synchronized RequestStatusResponse updateStacks(); @Override Set<ExtensionResponse> getExtensions(Set<ExtensionRequest> requests); @Override Set<ExtensionVersionResponse> getExtensionVersions(
      Set<ExtensionVersionRequest> requests); @Override Set<RepositoryResponse> getRepositories(Set<RepositoryRequest> requests); @Override void updateRepositories(Set<RepositoryRequest> requests); @Override void verifyRepositories(Set<RepositoryRequest> requests); @Override Set<StackVersionResponse> getStackVersions(
      Set<StackVersionRequest> requests); @Override Set<StackServiceResponse> getStackServices(
      Set<StackServiceRequest> requests); @Override Set<StackConfigurationResponse> getStackLevelConfigurations(
      Set<StackLevelConfigurationRequest> requests); @Override Set<StackConfigurationResponse> getStackConfigurations(
      Set<StackConfigurationRequest> requests); @Override Set<StackServiceComponentResponse> getStackComponents(
      Set<StackServiceComponentRequest> requests); @Override Set<OperatingSystemResponse> getOperatingSystems(
      Set<OperatingSystemRequest> requests); @Override String getAuthName(); @Override int getAuthId(); @Override Set<RootServiceResponse> getRootServices(
      Set<RootServiceRequest> requests); @Override Set<RootServiceComponentResponse> getRootServiceComponents(
      Set<RootServiceComponentRequest> requests); @Override Clusters getClusters(); @Override ConfigHelper getConfigHelper(); @Override AmbariMetaInfo getAmbariMetaInfo(); @Override ServiceComponentFactory getServiceComponentFactory(); @Override ConfigGroupFactory getConfigGroupFactory(); @Override RoleGraphFactory getRoleGraphFactory(); @Override AbstractRootServiceResponseFactory getRootServiceResponseFactory(); @Override ActionManager getActionManager(); @Override String getJdkResourceUrl(); @Override String getJavaHome(); @Override String getJDKName(); @Override String getJCEName(); @Override String getServerDB(); @Override String getOjdbcUrl(); @Override String getMysqljdbcUrl(); @Override Map<String, String> getRcaParameters(); @Override boolean checkLdapConfigured(); @Override LdapSyncDto getLdapSyncInfo(); @Override boolean isLdapSyncInProgress(); @Override synchronized LdapBatchDto synchronizeLdapUsersAndGroups(
      LdapSyncRequest userRequest, LdapSyncRequest groupRequest); @SuppressWarnings("unchecked") @Override void initializeWidgetsAndLayouts(Cluster cluster, Service service); @Override TimelineMetricCacheProvider getTimelineMetricCacheProvider(); @Override MetricPropertyProviderFactory getMetricPropertyProviderFactory(); @Override LoggingSearchPropertyProvider getLoggingSearchPropertyProvider(); @Override LoggingService getLoggingService(String clusterName); @Override AmbariEventPublisher getAmbariEventPublisher(); @Override KerberosHelper getKerberosHelper(); @Override CredentialStoreService getCredentialStoreService(); Map<String,String> getCredentialStoreServiceProperties(); @Override MetricsCollectorHAManager getMetricsCollectorHAManager(); @Override void deleteExtensionLink(ExtensionLinkRequest request); @Override void createExtensionLink(ExtensionLinkRequest request); @Override void updateExtensionLink(ExtensionLinkRequest request); @Override void updateExtensionLink(ExtensionLinkEntity linkEntity); @Override QuickLinkVisibilityController getQuicklinkVisibilityController(); static final String SKIP_INSTALL_FOR_COMPONENTS; static final String DONT_SKIP_INSTALL_FOR_COMPONENTS; }
@Test public void testgetAmbariServerURI() throws Exception { Injector injector = createStrictMock(Injector.class); Capture<AmbariManagementController> controllerCapture = EasyMock.newCapture(); injector.injectMembers(capture(controllerCapture)); expect(injector.getInstance(Gson.class)).andReturn(null); expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null); expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)); replay(injector); AmbariManagementControllerImpl controller = new AmbariManagementControllerImpl(null, null, injector); class AmbariConfigsSetter { public void setConfigs(AmbariManagementController controller, String masterProtocol, String masterHostname, Integer masterPort) throws Exception { Class<?> c = controller.getClass(); Field f = c.getDeclaredField("masterProtocol"); f.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL); f.set(controller, masterProtocol); f = c.getDeclaredField("masterHostname"); f.setAccessible(true); modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL); f.set(controller, masterHostname); f = c.getDeclaredField("masterPort"); f.setAccessible(true); modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL); f.set(controller, masterPort); } } AmbariConfigsSetter ambariConfigsSetter = new AmbariConfigsSetter(); ambariConfigsSetter.setConfigs(controller, "http", "hostname", 8080); assertEquals("http: ambariConfigsSetter.setConfigs(controller, "https", "somesecuredhost", 8443); assertEquals("https: ambariConfigsSetter.setConfigs(controller, "https", "othersecuredhost", 8443); assertEquals("https: ambariConfigsSetter.setConfigs(controller, "http", "hostname", 8080); assertEquals("http: verify(injector); }