com.arkea.jenkins.openstack.heat.orchestration.template.Bundle.java Source code

Java tutorial

Introduction

Here is the source code for com.arkea.jenkins.openstack.heat.orchestration.template.Bundle.java

Source

package com.arkea.jenkins.openstack.heat.orchestration.template;

import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;

/**
 * @author Credit Mutuel Arkea
 * 
 *         Copyright 2015 Credit Mutuel Arkea
 *
 *         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.
 * 
 *         This class is a bean describing a stack
 * 
 */
public class Bundle {

    /**
     * Properties
     */
    private String hotName;
    private String name;
    private boolean exist;
    private boolean debug;
    private Map<String, Parameter> parameters = new TreeMap<String, Parameter>();
    private Map<String, Output> outputs = new TreeMap<String, Output>();
    private String envName;

    public Bundle(String hotName, String name, boolean exist, boolean debug) {
        this.hotName = hotName;
        this.name = name;
        this.exist = exist;
        this.debug = debug;
    }

    public String getHotName() {
        return hotName;
    }

    public String getName() {
        return name;
    }

    public boolean isExist() {
        return exist;
    }

    public boolean isDebug() {
        return debug;
    }

    public Map<String, Parameter> getParameters() {
        return parameters;
    }

    public Map<String, Output> getOutputs() {
        return outputs;
    }

    public void setParameters(Map<String, Parameter> parameters) {
        this.parameters = parameters;
    }

    public void setOutputs(Map<String, Output> outputs) {
        this.outputs = outputs;
    }

    public String getEnvName() {
        return envName;
    }

    public void setEnvName(String envName) {
        this.envName = envName;
    }

    /**
     * @return the parameters to create a stack via OpenStack4jClient.
     */
    public Map<String, String> getParamsOS() {
        Map<String, String> paramsOS = new TreeMap<String, String>();
        for (String key : this.parameters.keySet()) {
            if (parameters.get(key).getValue() != null && !StringUtils.isEmpty(parameters.get(key).getValue())) {
                paramsOS.put(key, convertValue(parameters.get(key).getValue()));
            } else if (parameters.get(key).getDefaultValue() != null
                    && !StringUtils.isEmpty(convertValue(parameters.get(key).getDefaultValue()))) {
                paramsOS.put(key, convertValue(parameters.get(key).getDefaultValue()));
            } else {
                paramsOS.put(key, "");
            }
        }
        return paramsOS;
    }

    /**
     * Convert an object value from the yaml to string
     * 
     * @param value
     *            the object value from the yaml
     * @return the object in string format
     */
    @SuppressWarnings("unchecked")
    private String convertValue(Object value) {
        if (value instanceof java.util.LinkedHashMap) {
            StringBuilder rtn = new StringBuilder("{");
            java.util.LinkedHashMap<String, String> data = (java.util.LinkedHashMap<String, String>) value;
            for (String key : data.keySet()) {
                rtn.append(key).append(":").append(data.get(key)).append(",");
            }
            rtn.deleteCharAt(rtn.length() - 1);
            rtn.append("}");
            return rtn.toString();
        }
        return String.valueOf(value);
    }
}