@Test public void testValidationIfNifiPresentedAndDownScaleAndEntitledForScalingThenValidationShouldReturnTrue() { Blueprint blueprint = new Blueprint(); blueprint.setBlueprintText(FileReaderUtils.readFileFromClasspathQuietly("input/nifi.bp")); HostGroup hostGroup = new HostGroup(); hostGroup.setName("master"); when(entitlementService.scalingServiceEnabled(anyString(), anyString(), anyString())).thenReturn(true); assertDoesNotThrow(() -> subject.validateHostGroupScalingRequest(userCrn, accountId, blueprint, hostGroup, -2)); }
@Override public void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment) { CmTemplateProcessor templateProcessor = processorFactory.get(blueprint.getBlueprintText()); Set<String> services = templateProcessor.getComponentsByHostGroup().get(hostGroup.getName()); for (BlackListedDownScaleRole role : BlackListedDownScaleRole.values()) { if (services.contains(role.name()) && adjustment < 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } for (BlackListedUpScaleRole role : BlackListedUpScaleRole.values()) { if (services.contains(role.name()) && adjustment > 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } }
CmTemplateValidator implements BlueprintValidator { @Override public void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment) { CmTemplateProcessor templateProcessor = processorFactory.get(blueprint.getBlueprintText()); Set<String> services = templateProcessor.getComponentsByHostGroup().get(hostGroup.getName()); for (BlackListedDownScaleRole role : BlackListedDownScaleRole.values()) { if (services.contains(role.name()) && adjustment < 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } for (BlackListedUpScaleRole role : BlackListedUpScaleRole.values()) { if (services.contains(role.name()) && adjustment > 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } } }
CmTemplateValidator implements BlueprintValidator { @Override public void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment) { CmTemplateProcessor templateProcessor = processorFactory.get(blueprint.getBlueprintText()); Set<String> services = templateProcessor.getComponentsByHostGroup().get(hostGroup.getName()); for (BlackListedDownScaleRole role : BlackListedDownScaleRole.values()) { if (services.contains(role.name()) && adjustment < 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } for (BlackListedUpScaleRole role : BlackListedUpScaleRole.values()) { if (services.contains(role.name()) && adjustment > 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } }  }
CmTemplateValidator implements BlueprintValidator { @Override public void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment) { CmTemplateProcessor templateProcessor = processorFactory.get(blueprint.getBlueprintText()); Set<String> services = templateProcessor.getComponentsByHostGroup().get(hostGroup.getName()); for (BlackListedDownScaleRole role : BlackListedDownScaleRole.values()) { if (services.contains(role.name()) && adjustment < 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } for (BlackListedUpScaleRole role : BlackListedUpScaleRole.values()) { if (services.contains(role.name()) && adjustment > 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } }  @Override void validate(Blueprint blueprint, Set<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups,
        boolean validateServiceCardinality); @Override void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment); }
CmTemplateValidator implements BlueprintValidator { @Override public void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment) { CmTemplateProcessor templateProcessor = processorFactory.get(blueprint.getBlueprintText()); Set<String> services = templateProcessor.getComponentsByHostGroup().get(hostGroup.getName()); for (BlackListedDownScaleRole role : BlackListedDownScaleRole.values()) { if (services.contains(role.name()) && adjustment < 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } for (BlackListedUpScaleRole role : BlackListedUpScaleRole.values()) { if (services.contains(role.name()) && adjustment > 0) { if (!entitlementService.scalingServiceEnabled(userCrn, accountId, role.getEntitledFor())) { throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name())); } else { LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor()); } } } }  @Override void validate(Blueprint blueprint, Set<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups,
        boolean validateServiceCardinality); @Override void validateHostGroupScalingRequest(String userCrn, String accountId, Blueprint blueprint, HostGroup hostGroup, Integer adjustment);  }