/*******************************************************************************
 *
 *   Copyright 2015 Walmart, Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *******************************************************************************/
package com.oneops.cms.util;

import java.util.Map;

import static com.oneops.cms.util.CmsUtil.*;

/**
 * Holds the context used for variable inerpolation
 */
public class VariableContext {
    private final long ciId;
    private final String ciName;
    private final String nsPath;
    private final Map<String, String> cloudVars;
    private final Map<String, String> globalVars;
    private final Map<String, String> localVars;
    private String attrName;
    private String unresolvedAttrValue;


    public VariableContext(long ciId, String ciName, String nsPath, Map<String, String> cloudVars, Map<String, String> globalVars, Map<String, String> localVars) {
        this.ciId = ciId;
        this.ciName = ciName;
        this.nsPath = nsPath;
        this.cloudVars = cloudVars;
        this.globalVars = globalVars;
        this.localVars = localVars;
    }


    public long getCiId() {
        return ciId;
    }

    public String getCiName() {
        return ciName;
    }

    public String getNsPath() {
        return nsPath;
    }

    public String getAttrName() {
        return attrName;
    }

    public void setAttrName(String attrName) {
        this.attrName = attrName;
    }

    public String getUnresolvedAttrValue() {
        return unresolvedAttrValue;
    }

    public void setUnresolvedAttrValue(String unresolvedAttrValue) {
        this.unresolvedAttrValue = unresolvedAttrValue;
    }

    public Map<String, String> getCloudVars() {
        return cloudVars;
    }

    public Map<String, String> getGlobalVars() {
        return globalVars;
    }

    public Map<String, String> getLocalVars() {
        return localVars;
    }

    public String getCloudVar(String variableToResolve) {
        if (getCloudVars() != null)
            return getCloudVars().get(variableToResolve);
        return null;
    }

    public String getGlobalVar(String variableToResolve) {
        if (getGlobalVars() != null)
            return getGlobalVars().get(variableToResolve);
        return null;
    }

    public String getLocalVar(String variableToResolve) {
        if (getLocalVars() != null)
            return getLocalVars().get(variableToResolve);
        return null;
    }

    public String get(String varName, String prefix) {
        String varValue = null;
        if (prefix != null) {
            switch (prefix) {
                case CLOUDVARPFX:
                    varValue = getCloudVar(varName);
                    break;
                case GLOBALVARPFX:
                    varValue = getGlobalVar(varName);
                    break;
                case LOCALVARPFX:
                    varValue = getLocalVar(varName);
                    break;
                default:
                    varValue = null;

            }
        }
        return varValue;
    }


}

@@ -802,16 +802,49 @@
 .util;%0A%0A
+import org.apache.log4j.Logger;%0A%0A
 import j
@@ -1086,24 +1086,95 @@
 ing nsPath;%0A
+    private  String attrName;%0A    private  String unresolvedAttrValue;%0A
     private 
@@ -1301,32 +1301,33 @@
 ing%3E localVars;%0A
+%0A
     private Stri
@@ -1326,65 +1326,77 @@
 ate 
-String attrName;%0A    private String unresolvedAttrValue;%0A
+static final Logger logger = Logger.getLogger(VariableContext.class);
 %0A%0A  
@@ -1460,16 +1460,17 @@
  nsPath,
+ 
  Map%3CStr
@@ -1762,16 +1762,17 @@
     %7D%0A%0A%0A
+%0A
     publ
@@ -2024,276 +2024,56 @@
 lic 
-void setAttrName(String attrName) %7B%0A        this.attrName = attrName;%0A    %7D%0A%0A    public String getUnresolvedAttrValue() %7B%0A        return unresolvedAttrValue;%0A    %7D%0A%0A    public void setUnresolvedAttrValue(String unresolvedAttrValue) %7B%0A        this.unresolvedAttrValue =
+String getUnresolvedAttrValue() %7B%0A        return
  unr
@@ -2334,32 +2334,33 @@
 calVars;%0A    %7D%0A%0A
+%0A
     public Strin
@@ -2427,32 +2427,33 @@
 udVars() != null
+ 
 )%0A            re
@@ -2457,16 +2457,17 @@
  return 
+ 
 getCloud
@@ -2611,32 +2611,33 @@
 alVars() != null
+ 
 )%0A            re
@@ -2641,16 +2641,17 @@
  return 
+ 
 getGloba
@@ -2701,33 +2701,32 @@
 urn null;%0A    %7D%0A
-%0A
     public Strin
@@ -2801,16 +2801,17 @@
  != null
+ 
 )%0A      
@@ -2823,16 +2823,17 @@
  return 
+ 
 getLocal
@@ -2883,32 +2883,256 @@
 rn null;%0A    %7D%0A%0A
+%0A%0A%0A%0A    public void setAttrName(String attrName) %7B%0A        this.attrName = attrName;%0A    %7D%0A%0A    public void setUnresolvedAttrValue(String unresolvedAttrValue) %7B%0A        this.unresolvedAttrValue = unresolvedAttrValue;%0A    %7D%0A%0A
     public Strin
@@ -3224,18 +3224,15 @@
 efix
- 
 !=
- 
 null)
- 
 %7B%0A  
@@ -3317,25 +3317,24 @@
     varValue
- 
 = getCloudVa
@@ -3431,25 +3431,24 @@
     varValue
- 
 = getGlobalV

rollback for upstream changes from another PR