@Test public void testCreateResources_checkRequestId() throws Exception { Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap(); Set<String> propertyIds = Collections.singleton(ValidationResourceProvider.VALIDATION_ID_PROPERTY_ID); AmbariManagementController ambariManagementController = mock(AmbariManagementController.class); ValidationResourceProvider provider = spy(new ValidationResourceProvider(propertyIds, keyPropertyIds, ambariManagementController)); StackAdvisorRequest stackAdvisorRequest = mock(StackAdvisorRequest.class); Request request = mock(Request.class); doReturn(stackAdvisorRequest).when(provider).prepareStackAdvisorRequest(request); StackAdvisorHelper saHelper = mock(StackAdvisorHelper.class); ValidationResponse response = mock(ValidationResponse.class); Version version = mock(Version.class); doReturn(3).when(response).getId(); doReturn(version).when(response).getVersion(); doReturn(response).when(saHelper).validate(any(StackAdvisorRequest.class)); ValidationResourceProvider.init(saHelper); RequestStatus status = provider.createResources(request); Set<Resource> associatedResources = status.getAssociatedResources(); assertNotNull(associatedResources); assertEquals(1, associatedResources.size()); Resource resource = associatedResources.iterator().next(); Object requestId = resource.getPropertyValue(ValidationResourceProvider.VALIDATION_ID_PROPERTY_ID); assertNotNull(requestId); assertEquals(3, requestId); }
@Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest validationRequest = prepareStackAdvisorRequest(request); final ValidationResponse response; try { response = saHelper.validate(validationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occurred during validation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occurred during validation", e); throw new SystemException(e.getMessage(), e); } Resource validation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Validation); setResourceProperty(resource, VALIDATION_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()); List<Map<String, Object>> listItemProps = new ArrayList<Map<String, Object>>(); Set<ValidationItem> items = response.getItems(); for (ValidationItem item : items) { Map<String, Object> mapItemProps = new HashMap<String, Object>(); mapItemProps.put(ITEMS_TYPE_PROPERTY_ID, item.getType()); mapItemProps.put(ITEMS_LEVE_PROPERTY_ID, item.getLevel()); mapItemProps.put(ITEMS_MESSAGE_PROPERTY_ID, item.getMessage()); if (item.getComponentName() != null) { mapItemProps.put(ITEMS_COMPONENT_NAME_PROPERTY_ID, item.getComponentName()); } if (item.getHost() != null) { mapItemProps.put(ITEMS_HOST_PROPERTY_ID, item.getHost()); } if (item.getConfigType() != null) { mapItemProps.put(ITEMS_CONFIG_TYPE_PROPERTY_ID, item.getConfigType()); mapItemProps.put(ITEMS_CONFIG_NAME_PROPERTY_ID, item.getConfigName()); } listItemProps.add(mapItemProps); } setResourceProperty(resource, ITEMS_PROPERTY_ID, listItemProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Validation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(validation)); return new RequestStatusImpl(null, resources); }
ValidationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest validationRequest = prepareStackAdvisorRequest(request); final ValidationResponse response; try { response = saHelper.validate(validationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occurred during validation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occurred during validation", e); throw new SystemException(e.getMessage(), e); } Resource validation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Validation); setResourceProperty(resource, VALIDATION_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()); List<Map<String, Object>> listItemProps = new ArrayList<Map<String, Object>>(); Set<ValidationItem> items = response.getItems(); for (ValidationItem item : items) { Map<String, Object> mapItemProps = new HashMap<String, Object>(); mapItemProps.put(ITEMS_TYPE_PROPERTY_ID, item.getType()); mapItemProps.put(ITEMS_LEVE_PROPERTY_ID, item.getLevel()); mapItemProps.put(ITEMS_MESSAGE_PROPERTY_ID, item.getMessage()); if (item.getComponentName() != null) { mapItemProps.put(ITEMS_COMPONENT_NAME_PROPERTY_ID, item.getComponentName()); } if (item.getHost() != null) { mapItemProps.put(ITEMS_HOST_PROPERTY_ID, item.getHost()); } if (item.getConfigType() != null) { mapItemProps.put(ITEMS_CONFIG_TYPE_PROPERTY_ID, item.getConfigType()); mapItemProps.put(ITEMS_CONFIG_NAME_PROPERTY_ID, item.getConfigName()); } listItemProps.add(mapItemProps); } setResourceProperty(resource, ITEMS_PROPERTY_ID, listItemProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Validation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(validation)); return new RequestStatusImpl(null, resources); } }
ValidationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest validationRequest = prepareStackAdvisorRequest(request); final ValidationResponse response; try { response = saHelper.validate(validationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occurred during validation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occurred during validation", e); throw new SystemException(e.getMessage(), e); } Resource validation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Validation); setResourceProperty(resource, VALIDATION_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()); List<Map<String, Object>> listItemProps = new ArrayList<Map<String, Object>>(); Set<ValidationItem> items = response.getItems(); for (ValidationItem item : items) { Map<String, Object> mapItemProps = new HashMap<String, Object>(); mapItemProps.put(ITEMS_TYPE_PROPERTY_ID, item.getType()); mapItemProps.put(ITEMS_LEVE_PROPERTY_ID, item.getLevel()); mapItemProps.put(ITEMS_MESSAGE_PROPERTY_ID, item.getMessage()); if (item.getComponentName() != null) { mapItemProps.put(ITEMS_COMPONENT_NAME_PROPERTY_ID, item.getComponentName()); } if (item.getHost() != null) { mapItemProps.put(ITEMS_HOST_PROPERTY_ID, item.getHost()); } if (item.getConfigType() != null) { mapItemProps.put(ITEMS_CONFIG_TYPE_PROPERTY_ID, item.getConfigType()); mapItemProps.put(ITEMS_CONFIG_NAME_PROPERTY_ID, item.getConfigName()); } listItemProps.add(mapItemProps); } setResourceProperty(resource, ITEMS_PROPERTY_ID, listItemProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Validation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(validation)); return new RequestStatusImpl(null, resources); } protected  ValidationResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
ValidationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest validationRequest = prepareStackAdvisorRequest(request); final ValidationResponse response; try { response = saHelper.validate(validationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occurred during validation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occurred during validation", e); throw new SystemException(e.getMessage(), e); } Resource validation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Validation); setResourceProperty(resource, VALIDATION_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()); List<Map<String, Object>> listItemProps = new ArrayList<Map<String, Object>>(); Set<ValidationItem> items = response.getItems(); for (ValidationItem item : items) { Map<String, Object> mapItemProps = new HashMap<String, Object>(); mapItemProps.put(ITEMS_TYPE_PROPERTY_ID, item.getType()); mapItemProps.put(ITEMS_LEVE_PROPERTY_ID, item.getLevel()); mapItemProps.put(ITEMS_MESSAGE_PROPERTY_ID, item.getMessage()); if (item.getComponentName() != null) { mapItemProps.put(ITEMS_COMPONENT_NAME_PROPERTY_ID, item.getComponentName()); } if (item.getHost() != null) { mapItemProps.put(ITEMS_HOST_PROPERTY_ID, item.getHost()); } if (item.getConfigType() != null) { mapItemProps.put(ITEMS_CONFIG_TYPE_PROPERTY_ID, item.getConfigType()); mapItemProps.put(ITEMS_CONFIG_NAME_PROPERTY_ID, item.getConfigName()); } listItemProps.add(mapItemProps); } setResourceProperty(resource, ITEMS_PROPERTY_ID, listItemProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Validation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(validation)); return new RequestStatusImpl(null, resources); } protected  ValidationResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override RequestStatus createResources(final Request request); }
ValidationResourceProvider extends StackAdvisorResourceProvider { @Override public RequestStatus createResources(final Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException { StackAdvisorRequest validationRequest = prepareStackAdvisorRequest(request); final ValidationResponse response; try { response = saHelper.validate(validationRequest); } catch (StackAdvisorRequestException e) { LOG.warn("Error occurred during validation", e); throw new IllegalArgumentException(e.getMessage(), e); } catch (StackAdvisorException e) { LOG.warn("Error occurred during validation", e); throw new SystemException(e.getMessage(), e); } Resource validation = createResources(new Command<Resource>() { @Override public Resource invoke() throws AmbariException { Resource resource = new ResourceImpl(Resource.Type.Validation); setResourceProperty(resource, VALIDATION_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()); List<Map<String, Object>> listItemProps = new ArrayList<Map<String, Object>>(); Set<ValidationItem> items = response.getItems(); for (ValidationItem item : items) { Map<String, Object> mapItemProps = new HashMap<String, Object>(); mapItemProps.put(ITEMS_TYPE_PROPERTY_ID, item.getType()); mapItemProps.put(ITEMS_LEVE_PROPERTY_ID, item.getLevel()); mapItemProps.put(ITEMS_MESSAGE_PROPERTY_ID, item.getMessage()); if (item.getComponentName() != null) { mapItemProps.put(ITEMS_COMPONENT_NAME_PROPERTY_ID, item.getComponentName()); } if (item.getHost() != null) { mapItemProps.put(ITEMS_HOST_PROPERTY_ID, item.getHost()); } if (item.getConfigType() != null) { mapItemProps.put(ITEMS_CONFIG_TYPE_PROPERTY_ID, item.getConfigType()); mapItemProps.put(ITEMS_CONFIG_NAME_PROPERTY_ID, item.getConfigName()); } listItemProps.add(mapItemProps); } setResourceProperty(resource, ITEMS_PROPERTY_ID, listItemProps, getPropertyIds()); return resource; } }); notifyCreate(Resource.Type.Validation, request); Set<Resource> resources = new HashSet<Resource>(Arrays.asList(validation)); return new RequestStatusImpl(null, resources); } protected  ValidationResourceProvider(Set<String> propertyIds, Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override RequestStatus createResources(final Request request);  }