class TaggingRule extends BaseRule {

	public RuleResult execute(final Map<String, String> ruleParam, Map<String, String> resourceAttributes) {

		logger.debug("========TaggingRule started=========");
		Set<String> missingTags = new HashSet<>();
		String mandatoryTags = ConfigUtils.getPropValue(PacmanSdkConstants.TAGGING_MANDATORY_TAGS);
		String tagsSplitter = ruleParam.get(PacmanSdkConstants.SPLITTER_CHAR);
		String entityId = ruleParam.get(PacmanSdkConstants.RESOURCE_ID);

		String severity = ruleParam.get(PacmanRuleConstants.SEVERITY);
		String category = ruleParam.get(PacmanRuleConstants.CATEGORY);
		String targetType = ruleParam.get(PacmanRuleConstants.TARGET_TYPE);

		MDC.put("executionId", ruleParam.get("executionId")); // this is the logback Mapped Diagnostic Contex
		MDC.put("ruleId", ruleParam.get(PacmanSdkConstants.RULE_ID)); // this is the logback Mapped Diagnostic Contex


		if (!PacmanUtils.doesAllHaveValue(mandatoryTags,tagsSplitter,severity,category,targetType)) {
			logger.info(PacmanRuleConstants.MISSING_CONFIGURATION);
			throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION);
		}

		String missingTagsStr = null;


		List<String> mandatoryTagsList = PacmanUtils.splitStringToAList(mandatoryTags, tagsSplitter);

		if (resourceAttributes!=null) {
			if(targetType.equalsIgnoreCase(PacmanRuleConstants.TARGET_TYPE_EC2)){
				if(resourceAttributes.get(PacmanRuleConstants.STATE_NAME).equalsIgnoreCase(PacmanRuleConstants.RUNNING_STATE)||resourceAttributes.get(PacmanRuleConstants.STATE_NAME).equalsIgnoreCase(PacmanRuleConstants.STOPPED_STATE)){
				missingTags = PacmanUtils.getMissingTagsfromResourceAttribute(mandatoryTagsList,resourceAttributes);
				}
			}else{
				missingTags = PacmanUtils.getMissingTagsfromResourceAttribute(mandatoryTagsList,resourceAttributes);
			}
		}
		missingTagsStr = Joiner.on(", ").join(missingTags);
		if (!missingTags.isEmpty()) {
			String description = "Missed tags for "+targetType+" are "+ missingTagsStr;
			return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createAnnotaion(ruleParam, missingTagsStr, mandatoryTagsList, description,severity,category,targetType));

		} else {
			logger.info(targetType ," ", entityId , " has all manadatory tags");
		}
		logger.debug("========TaggingRule ended=========");
		return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE);
	}

}