@Test public void executeTest() throws Exception { mockStatic(PacmanUtils.class); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString(),anyString())).thenReturn( true); when(PacmanUtils.splitStringToAList(anyString(),anyString())).thenReturn(CommonTestUtils.getListString()); assertThat(deprecatedInstanceTypeRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); when(PacmanUtils.splitStringToAList(anyString(),anyString())).thenReturn(CommonTestUtils.getOneMoreListString()); assertThat(deprecatedInstanceTypeRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 ")), is(notNullValue())); when(PacmanUtils.doesAllHaveValue(anyString(),anyString(),anyString(),anyString())).thenReturn( false); assertThatThrownBy( () -> deprecatedInstanceTypeRule.execute(CommonTestUtils.getMapString("r_123 "),CommonTestUtils.getMapString("r_123 "))).isInstanceOf(InvalidInputException.class); }
public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========EC2DeprecatedInstanceTypeRule started========="); if (resourceAttributes.get("statename") != null && "running".equals(resourceAttributes.get("statename"))) { Annotation annotation = null; String entityId = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); String deprecatedInstanceType = ruleParam .get(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPE); String tagsSplitter = ruleParam .get(PacmanSdkConstants.SPLITTER_CHAR); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(deprecatedInstanceType, tagsSplitter, severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } String instanceType = resourceAttributes .get(PacmanRuleConstants.INSTANCE_TYPE); List<String> deprecatedInstanceTypeList = PacmanUtils .splitStringToAList(deprecatedInstanceType, tagsSplitter); if (isInstanceDepricated(instanceType, deprecatedInstanceTypeList)) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Deprecated instance type " + instanceType + " found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Deprecated instance type " + instanceType + " found !!"); issue.put(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPES, String.join(",", deprecatedInstanceTypeList)); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========EC2DeprecatedInstanceTypeRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } else { logger.debug(entityId ,":not a deprecated instance"); } } logger.debug("========EC2DeprecatedInstanceTypeRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }
EC2DeprecatedInstanceTypeRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========EC2DeprecatedInstanceTypeRule started========="); if (resourceAttributes.get("statename") != null && "running".equals(resourceAttributes.get("statename"))) { Annotation annotation = null; String entityId = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); String deprecatedInstanceType = ruleParam .get(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPE); String tagsSplitter = ruleParam .get(PacmanSdkConstants.SPLITTER_CHAR); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(deprecatedInstanceType, tagsSplitter, severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } String instanceType = resourceAttributes .get(PacmanRuleConstants.INSTANCE_TYPE); List<String> deprecatedInstanceTypeList = PacmanUtils .splitStringToAList(deprecatedInstanceType, tagsSplitter); if (isInstanceDepricated(instanceType, deprecatedInstanceTypeList)) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Deprecated instance type " + instanceType + " found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Deprecated instance type " + instanceType + " found !!"); issue.put(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPES, String.join(",", deprecatedInstanceTypeList)); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========EC2DeprecatedInstanceTypeRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } else { logger.debug(entityId ,":not a deprecated instance"); } } logger.debug("========EC2DeprecatedInstanceTypeRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); } }
EC2DeprecatedInstanceTypeRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========EC2DeprecatedInstanceTypeRule started========="); if (resourceAttributes.get("statename") != null && "running".equals(resourceAttributes.get("statename"))) { Annotation annotation = null; String entityId = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); String deprecatedInstanceType = ruleParam .get(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPE); String tagsSplitter = ruleParam .get(PacmanSdkConstants.SPLITTER_CHAR); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(deprecatedInstanceType, tagsSplitter, severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } String instanceType = resourceAttributes .get(PacmanRuleConstants.INSTANCE_TYPE); List<String> deprecatedInstanceTypeList = PacmanUtils .splitStringToAList(deprecatedInstanceType, tagsSplitter); if (isInstanceDepricated(instanceType, deprecatedInstanceTypeList)) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Deprecated instance type " + instanceType + " found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Deprecated instance type " + instanceType + " found !!"); issue.put(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPES, String.join(",", deprecatedInstanceTypeList)); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========EC2DeprecatedInstanceTypeRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } else { logger.debug(entityId ,":not a deprecated instance"); } } logger.debug("========EC2DeprecatedInstanceTypeRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  }
EC2DeprecatedInstanceTypeRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========EC2DeprecatedInstanceTypeRule started========="); if (resourceAttributes.get("statename") != null && "running".equals(resourceAttributes.get("statename"))) { Annotation annotation = null; String entityId = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); String deprecatedInstanceType = ruleParam .get(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPE); String tagsSplitter = ruleParam .get(PacmanSdkConstants.SPLITTER_CHAR); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(deprecatedInstanceType, tagsSplitter, severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } String instanceType = resourceAttributes .get(PacmanRuleConstants.INSTANCE_TYPE); List<String> deprecatedInstanceTypeList = PacmanUtils .splitStringToAList(deprecatedInstanceType, tagsSplitter); if (isInstanceDepricated(instanceType, deprecatedInstanceTypeList)) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Deprecated instance type " + instanceType + " found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Deprecated instance type " + instanceType + " found !!"); issue.put(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPES, String.join(",", deprecatedInstanceTypeList)); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========EC2DeprecatedInstanceTypeRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } else { logger.debug(entityId ,":not a deprecated instance"); } } logger.debug("========EC2DeprecatedInstanceTypeRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); String getHelpText(); }
EC2DeprecatedInstanceTypeRule extends BaseRule { public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) { logger.debug("========EC2DeprecatedInstanceTypeRule started========="); if (resourceAttributes.get("statename") != null && "running".equals(resourceAttributes.get("statename"))) { Annotation annotation = null; String entityId = ruleParam.get(PacmanSdkConstants.RESOURCE_ID); String deprecatedInstanceType = ruleParam .get(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPE); String tagsSplitter = ruleParam .get(PacmanSdkConstants.SPLITTER_CHAR); String severity = ruleParam.get(PacmanRuleConstants.SEVERITY); String category = ruleParam.get(PacmanRuleConstants.CATEGORY); MDC.put("executionId", ruleParam.get("executionId")); MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); List<LinkedHashMap<String, Object>> issueList = new ArrayList<>(); LinkedHashMap<String, Object> issue = new LinkedHashMap<>(); if (!PacmanUtils.doesAllHaveValue(deprecatedInstanceType, tagsSplitter, severity, category)) { logger.info(PacmanRuleConstants.MISSING_CONFIGURATION); throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION); } String instanceType = resourceAttributes .get(PacmanRuleConstants.INSTANCE_TYPE); List<String> deprecatedInstanceTypeList = PacmanUtils .splitStringToAList(deprecatedInstanceType, tagsSplitter); if (isInstanceDepricated(instanceType, deprecatedInstanceTypeList)) { annotation = Annotation.buildAnnotation(ruleParam, Annotation.Type.ISSUE); annotation.put(PacmanSdkConstants.DESCRIPTION, "Deprecated instance type " + instanceType + " found !!"); annotation.put(PacmanRuleConstants.SEVERITY, severity); annotation.put(PacmanRuleConstants.CATEGORY, category); issue.put(PacmanRuleConstants.VIOLATION_REASON, "Deprecated instance type " + instanceType + " found !!"); issue.put(PacmanRuleConstants.DEPRECATED_INSTANCE_TYPES, String.join(",", deprecatedInstanceTypeList)); issueList.add(issue); annotation.put("issueDetails", issueList.toString()); logger.debug("========EC2DeprecatedInstanceTypeRule ended with annotation {} :=========",annotation); return new RuleResult(PacmanSdkConstants.STATUS_FAILURE, PacmanRuleConstants.FAILURE_MESSAGE, annotation); } else { logger.debug(entityId ,":not a deprecated instance"); } } logger.debug("========EC2DeprecatedInstanceTypeRule ended========="); return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS, PacmanRuleConstants.SUCCESS_MESSAGE); }  RuleResult execute(final Map<String, String> ruleParam,
            Map<String, String> resourceAttributes); String getHelpText();  }