TopologyManager { public RequestStatusResponse provisionCluster(final ProvisionClusterRequest request) throws InvalidTopologyException, AmbariException { ensureInitialized(); final ClusterTopology topology = new ClusterTopologyImpl(ambariContext, request); final String clusterName = request.getClusterName(); final Stack stack = topology.getBlueprint().getStack(); final String repoVersion = request.getRepositoryVersion(); final Long provisionId = ambariContext.getNextRequestId(); boolean configureSecurity = false; SecurityConfiguration securityConfiguration = processSecurityConfiguration(request); if (securityConfiguration != null && securityConfiguration.getType() == SecurityType.KERBEROS) { configureSecurity = true; addKerberosClient(topology); topology.getBlueprint().getConfiguration().setParentConfiguration(stack.getConfiguration(topology.getBlueprint ().getServices())); ambariContext.createAmbariResources(topology, clusterName, SecurityType.KERBEROS, repoVersion); if (securityConfiguration.getDescriptor() != null) { submitKerberosDescriptorAsArtifact(clusterName, securityConfiguration.getDescriptor()); } Credential credential = request.getCredentialsMap().get(KDC_ADMIN_CREDENTIAL); if (credential == null) { throw new InvalidTopologyException(KDC_ADMIN_CREDENTIAL + " is missing from request."); } submitCredential(clusterName, credential); } else { ambariContext.createAmbariResources(topology, clusterName, null, repoVersion); } long clusterId = ambariContext.getClusterId(clusterName); topology.setClusterId(clusterId); request.setClusterId(clusterId); topology.setConfigRecommendationStrategy(request.getConfigRecommendationStrategy()); topology.setProvisionAction(request.getProvisionAction()); LogicalRequest logicalRequest = RetryHelper.executeWithRetry(new Callable<LogicalRequest>() { @Override public LogicalRequest call() throws Exception { LogicalRequest logicalRequest = processAndPersistProvisionClusterTopologyRequest(request, topology, provisionId); return logicalRequest; } } ); clusterTopologyMap.put(clusterId, topology); addClusterConfigRequest(topology, new ClusterConfigurationRequest( ambariContext, topology, true, stackAdvisorBlueprintProcessor, configureSecurity)); executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { ambariEventPublisher.publish(new ClusterConfigFinishedEvent(clusterName)); return Boolean.TRUE; } }); processRequest(request, topology, logicalRequest); ambariContext.persistInstallStateForUI(clusterName, stack.getName(), stack.getVersion()); clusterProvisionWithBlueprintCreateRequests.put(clusterId, logicalRequest); return getRequestStatus(logicalRequest.getRequestId()); } TopologyManager(); @Inject  TopologyManager(Configuration configuration); @Subscribe void onRequestFinished(RequestFinishedEvent event); boolean isClusterProvisionWithBlueprintTracked(long clusterId); boolean isClusterProvisionWithBlueprintFinished(long clusterId); RequestStatusResponse provisionCluster(final ProvisionClusterRequest request); RequestStatusResponse scaleHosts(final ScaleClusterRequest request); void onHostRegistered(HostImpl host, boolean associatedWithCluster); void onHostHeartBeatLost(Host host); LogicalRequest getRequest(long requestId); Collection<LogicalRequest> getRequests(Collection<Long> requestIds); Collection<StageEntity> getStages(); Collection<HostRoleCommand> getTasks(long requestId); Collection<HostRoleCommand> getTasks(Collection<Long> requestIds); Map<Long, HostRoleCommandStatusSummaryDTO> getStageSummaries(Long requestId); RequestStatusResponse getRequestStatus(long requestId); Collection<RequestStatusResponse> getRequestStatus(Collection<Long> ids); ClusterTopology getClusterTopology(Long clusterId); Map<String, Collection<String>> getPendingHostComponents(); @Subscribe void processHostRemovedEvent(HostsRemovedEvent hostsRemovedEvent); static final String INTERNAL_AUTH_TOKEN; static final String INITIAL_CONFIG_TAG; static final String TOPOLOGY_RESOLVED_TAG; static final String KDC_ADMIN_CREDENTIAL; }
@Test public void testProvisionCluster() throws Exception { expect(persistedState.getAllRequests()).andReturn(Collections.<ClusterTopology, List<LogicalRequest>>emptyMap()).anyTimes(); replayAll(); topologyManager.provisionCluster(request); }
@Test public void testProvisionCluster_QuickLinkProfileIsSavedTheFirstTime() throws Exception { expect(persistedState.getAllRequests()).andReturn(Collections.<ClusterTopology, List<LogicalRequest>>emptyMap()).anyTimes(); expect(request.getQuickLinksProfileJson()).andReturn(SAMPLE_QUICKLINKS_PROFILE_1).anyTimes(); expect(settingDAO.findByName(QuickLinksProfile.SETTING_NAME_QUICKLINKS_PROFILE)).andReturn(null); final long timeStamp = System.currentTimeMillis(); mockStatic(System.class); expect(System.currentTimeMillis()).andReturn(timeStamp); PowerMock.replay(System.class); final SettingEntity quickLinksProfile = createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_1, timeStamp); settingDAO.create(eq(quickLinksProfile)); replayAll(); topologyManager.provisionCluster(request); }
@Test public void testProvisionCluster_ExistingQuickLinkProfileIsOverwritten() throws Exception { expect(persistedState.getAllRequests()).andReturn(Collections.<ClusterTopology, List<LogicalRequest>>emptyMap()).anyTimes(); expect(request.getQuickLinksProfileJson()).andReturn(SAMPLE_QUICKLINKS_PROFILE_2).anyTimes(); final long timeStamp1 = System.currentTimeMillis(); SettingEntity originalProfile = createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_1, timeStamp1); expect(settingDAO.findByName(QuickLinksProfile.SETTING_NAME_QUICKLINKS_PROFILE)).andReturn(originalProfile); mockStatic(System.class); final long timeStamp2 = timeStamp1 + 100; expect(System.currentTimeMillis()).andReturn(timeStamp2); PowerMock.replay(System.class); final SettingEntity newProfile = createQuickLinksSettingEntity(SAMPLE_QUICKLINKS_PROFILE_2, timeStamp2); expect(settingDAO.merge(newProfile)).andReturn(newProfile); replayAll(); topologyManager.provisionCluster(request); }