class UnusedClassicElbRule extends BaseRule {

	public RuleResult execute(final Map<String, String> ruleParam,Map<String, String> resourceAttributes) {
		logger.debug("========UnusedClassicElbRule started=========");
		String classicLoadBalncerId = null;
		String region = null;
		
		String severity = ruleParam.get(PacmanRuleConstants.SEVERITY);
		String category = ruleParam.get(PacmanRuleConstants.CATEGORY);
		String classicElbUrl = null;
		
		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
		
		String formattedUrl = PacmanUtils.formatUrl(ruleParam,PacmanRuleConstants.ES_CLASSIC_ELB_WITH_INSTANCE_URL);
        
        if(!StringUtils.isNullOrEmpty(formattedUrl)){
            classicElbUrl =  formattedUrl;
        }
		
		if (!PacmanUtils.doesAllHaveValue(severity,category,classicElbUrl)) {
			logger.info(PacmanRuleConstants.MISSING_CONFIGURATION);
			throw new InvalidInputException(PacmanRuleConstants.MISSING_CONFIGURATION);
		}
		
		if (resourceAttributes != null) {
			classicLoadBalncerId = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.LOAD_BALANCER_ID_ATTRIBUTE));
			region = StringUtils.trim(resourceAttributes.get(PacmanRuleConstants.REGION_ATTR));
			boolean isClassicElbWithEc2Exists = false;
			try {
				isClassicElbWithEc2Exists = PacmanUtils.checkResourceIdFromElasticSearch(classicLoadBalncerId,classicElbUrl,PacmanRuleConstants.LOAD_BALANCER_ID_ATTRIBUTE,region);
			} catch (Exception e) {
				logger.error("unable to determine",e);
				throw new RuleExecutionFailedExeption("unable to determine"+e);
			}
			if (!isClassicElbWithEc2Exists) {
				String description = "Unused Classic ELB found!!";
	            return new RuleResult(PacmanSdkConstants.STATUS_FAILURE,PacmanRuleConstants.FAILURE_MESSAGE, PacmanUtils.createELBAnnotation("Classic",ruleParam, description,severity,category));
			}
		}
		logger.debug("========UnusedClassicElbRule ended=========");
		return new RuleResult(PacmanSdkConstants.STATUS_SUCCESS,PacmanRuleConstants.SUCCESS_MESSAGE);
	}

}