@Test public void testCreateResources() throws Exception { }
@Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest recommendationRequest = prepareStackAdvisorRequest(request); final RecommendationResponse response; try { response = saHelper.recommend(recommendationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occured during recommendation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occured during recommendation", e); throw new SystemException(e.getMessage(), e); } Resource recommendation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Recommendation); setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds()); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(), getPropertyIds()); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion() .getStackVersion(), getPropertyIds()); setResourceProperty(resource, HOSTS_PROPERTY_ID, response.getHosts(), getPropertyIds()); setResourceProperty(resource, SERVICES_PROPERTY_ID, response.getServices(), getPropertyIds()); setResourceProperty(resource, CONFIG_GROUPS_PROPERTY_ID, response.getRecommendations().getConfigGroups(), getPropertyIds()); setResourceProperty(resource, BLUEPRINT_CONFIGURATIONS_PROPERTY_ID, response .getRecommendations().getBlueprint().getConfigurations(), getPropertyIds()); Set<HostGroup> hostGroups = response.getRecommendations().getBlueprint().getHostGroups(); List<Map<String, Object>> listGroupProps = new ArrayList<Map<String, Object>>(); for (HostGroup hostGroup : hostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BLUEPRINT_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps .put(BLUEPRINT_HOST_GROUPS_COMPONENTS_PROPERTY_ID, hostGroup.getComponents()); listGroupProps.add(mapGroupProps); } setResourceProperty(resource, BLUEPRINT_HOST_GROUPS_PROPERTY_ID, listGroupProps, getPropertyIds()); Set<BindingHostGroup> bindingHostGroups = response.getRecommendations() .getBlueprintClusterBinding().getHostGroups(); List<Map<String, Object>> listBindingGroupProps = new ArrayList<Map<String, Object>>(); for (BindingHostGroup hostGroup : bindingHostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BINDING_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps.put(BINDING_HOST_GROUPS_HOSTS_PROPERTY_ID, hostGroup.getHosts()); listBindingGroupProps.add(mapGroupProps); } setResourceProperty(resource, BINDING_HOST_GROUPS_PROPERTY_ID, listBindingGroupProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Recommendation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(recommendation)); return new RequestStatusImpl(null, resources); }
RecommendationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest recommendationRequest = prepareStackAdvisorRequest(request); final RecommendationResponse response; try { response = saHelper.recommend(recommendationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occured during recommendation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occured during recommendation", e); throw new SystemException(e.getMessage(), e); } Resource recommendation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Recommendation); setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds()); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(), getPropertyIds()); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion() .getStackVersion(), getPropertyIds()); setResourceProperty(resource, HOSTS_PROPERTY_ID, response.getHosts(), getPropertyIds()); setResourceProperty(resource, SERVICES_PROPERTY_ID, response.getServices(), getPropertyIds()); setResourceProperty(resource, CONFIG_GROUPS_PROPERTY_ID, response.getRecommendations().getConfigGroups(), getPropertyIds()); setResourceProperty(resource, BLUEPRINT_CONFIGURATIONS_PROPERTY_ID, response .getRecommendations().getBlueprint().getConfigurations(), getPropertyIds()); Set<HostGroup> hostGroups = response.getRecommendations().getBlueprint().getHostGroups(); List<Map<String, Object>> listGroupProps = new ArrayList<Map<String, Object>>(); for (HostGroup hostGroup : hostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BLUEPRINT_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps .put(BLUEPRINT_HOST_GROUPS_COMPONENTS_PROPERTY_ID, hostGroup.getComponents()); listGroupProps.add(mapGroupProps); } setResourceProperty(resource, BLUEPRINT_HOST_GROUPS_PROPERTY_ID, listGroupProps, getPropertyIds()); Set<BindingHostGroup> bindingHostGroups = response.getRecommendations() .getBlueprintClusterBinding().getHostGroups(); List<Map<String, Object>> listBindingGroupProps = new ArrayList<Map<String, Object>>(); for (BindingHostGroup hostGroup : bindingHostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BINDING_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps.put(BINDING_HOST_GROUPS_HOSTS_PROPERTY_ID, hostGroup.getHosts()); listBindingGroupProps.add(mapGroupProps); } setResourceProperty(resource, BINDING_HOST_GROUPS_PROPERTY_ID, listBindingGroupProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Recommendation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(recommendation)); return new RequestStatusImpl(null, resources); } }
RecommendationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest recommendationRequest = prepareStackAdvisorRequest(request); final RecommendationResponse response; try { response = saHelper.recommend(recommendationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occured during recommendation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occured during recommendation", e); throw new SystemException(e.getMessage(), e); } Resource recommendation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Recommendation); setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds()); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(), getPropertyIds()); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion() .getStackVersion(), getPropertyIds()); setResourceProperty(resource, HOSTS_PROPERTY_ID, response.getHosts(), getPropertyIds()); setResourceProperty(resource, SERVICES_PROPERTY_ID, response.getServices(), getPropertyIds()); setResourceProperty(resource, CONFIG_GROUPS_PROPERTY_ID, response.getRecommendations().getConfigGroups(), getPropertyIds()); setResourceProperty(resource, BLUEPRINT_CONFIGURATIONS_PROPERTY_ID, response .getRecommendations().getBlueprint().getConfigurations(), getPropertyIds()); Set<HostGroup> hostGroups = response.getRecommendations().getBlueprint().getHostGroups(); List<Map<String, Object>> listGroupProps = new ArrayList<Map<String, Object>>(); for (HostGroup hostGroup : hostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BLUEPRINT_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps .put(BLUEPRINT_HOST_GROUPS_COMPONENTS_PROPERTY_ID, hostGroup.getComponents()); listGroupProps.add(mapGroupProps); } setResourceProperty(resource, BLUEPRINT_HOST_GROUPS_PROPERTY_ID, listGroupProps, getPropertyIds()); Set<BindingHostGroup> bindingHostGroups = response.getRecommendations() .getBlueprintClusterBinding().getHostGroups(); List<Map<String, Object>> listBindingGroupProps = new ArrayList<Map<String, Object>>(); for (BindingHostGroup hostGroup : bindingHostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BINDING_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps.put(BINDING_HOST_GROUPS_HOSTS_PROPERTY_ID, hostGroup.getHosts()); listBindingGroupProps.add(mapGroupProps); } setResourceProperty(resource, BINDING_HOST_GROUPS_PROPERTY_ID, listBindingGroupProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Recommendation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(recommendation)); return new RequestStatusImpl(null, resources); } protected  RecommendationResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds, AmbariManagementController managementController); }
RecommendationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest recommendationRequest = prepareStackAdvisorRequest(request); final RecommendationResponse response; try { response = saHelper.recommend(recommendationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occured during recommendation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occured during recommendation", e); throw new SystemException(e.getMessage(), e); } Resource recommendation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Recommendation); setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds()); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(), getPropertyIds()); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion() .getStackVersion(), getPropertyIds()); setResourceProperty(resource, HOSTS_PROPERTY_ID, response.getHosts(), getPropertyIds()); setResourceProperty(resource, SERVICES_PROPERTY_ID, response.getServices(), getPropertyIds()); setResourceProperty(resource, CONFIG_GROUPS_PROPERTY_ID, response.getRecommendations().getConfigGroups(), getPropertyIds()); setResourceProperty(resource, BLUEPRINT_CONFIGURATIONS_PROPERTY_ID, response .getRecommendations().getBlueprint().getConfigurations(), getPropertyIds()); Set<HostGroup> hostGroups = response.getRecommendations().getBlueprint().getHostGroups(); List<Map<String, Object>> listGroupProps = new ArrayList<Map<String, Object>>(); for (HostGroup hostGroup : hostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BLUEPRINT_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps .put(BLUEPRINT_HOST_GROUPS_COMPONENTS_PROPERTY_ID, hostGroup.getComponents()); listGroupProps.add(mapGroupProps); } setResourceProperty(resource, BLUEPRINT_HOST_GROUPS_PROPERTY_ID, listGroupProps, getPropertyIds()); Set<BindingHostGroup> bindingHostGroups = response.getRecommendations() .getBlueprintClusterBinding().getHostGroups(); List<Map<String, Object>> listBindingGroupProps = new ArrayList<Map<String, Object>>(); for (BindingHostGroup hostGroup : bindingHostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BINDING_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps.put(BINDING_HOST_GROUPS_HOSTS_PROPERTY_ID, hostGroup.getHosts()); listBindingGroupProps.add(mapGroupProps); } setResourceProperty(resource, BINDING_HOST_GROUPS_PROPERTY_ID, listBindingGroupProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Recommendation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(recommendation)); return new RequestStatusImpl(null, resources); } protected  RecommendationResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds, AmbariManagementController managementController); @Override RequestStatus createResources(final Request request); }
RecommendationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest recommendationRequest = prepareStackAdvisorRequest(request); final RecommendationResponse response; try { response = saHelper.recommend(recommendationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occured during recommendation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occured during recommendation", e); throw new SystemException(e.getMessage(), e); } Resource recommendation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Recommendation); setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds()); setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(), getPropertyIds()); setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion() .getStackVersion(), getPropertyIds()); setResourceProperty(resource, HOSTS_PROPERTY_ID, response.getHosts(), getPropertyIds()); setResourceProperty(resource, SERVICES_PROPERTY_ID, response.getServices(), getPropertyIds()); setResourceProperty(resource, CONFIG_GROUPS_PROPERTY_ID, response.getRecommendations().getConfigGroups(), getPropertyIds()); setResourceProperty(resource, BLUEPRINT_CONFIGURATIONS_PROPERTY_ID, response .getRecommendations().getBlueprint().getConfigurations(), getPropertyIds()); Set<HostGroup> hostGroups = response.getRecommendations().getBlueprint().getHostGroups(); List<Map<String, Object>> listGroupProps = new ArrayList<Map<String, Object>>(); for (HostGroup hostGroup : hostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BLUEPRINT_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps .put(BLUEPRINT_HOST_GROUPS_COMPONENTS_PROPERTY_ID, hostGroup.getComponents()); listGroupProps.add(mapGroupProps); } setResourceProperty(resource, BLUEPRINT_HOST_GROUPS_PROPERTY_ID, listGroupProps, getPropertyIds()); Set<BindingHostGroup> bindingHostGroups = response.getRecommendations() .getBlueprintClusterBinding().getHostGroups(); List<Map<String, Object>> listBindingGroupProps = new ArrayList<Map<String, Object>>(); for (BindingHostGroup hostGroup : bindingHostGroups) { Map<String, Object> mapGroupProps = new HashMap<String, Object>(); mapGroupProps.put(BINDING_HOST_GROUPS_NAME_PROPERTY_ID, hostGroup.getName()); mapGroupProps.put(BINDING_HOST_GROUPS_HOSTS_PROPERTY_ID, hostGroup.getHosts()); listBindingGroupProps.add(mapGroupProps); } setResourceProperty(resource, BINDING_HOST_GROUPS_PROPERTY_ID, listBindingGroupProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Recommendation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(recommendation)); return new RequestStatusImpl(null, resources); } protected  RecommendationResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds, AmbariManagementController managementController); @Override RequestStatus createResources(final Request request);  }