com.huawei.openstack4j.openstack.senlin.domain.SenlinPolicyCreate Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2016 ContainX and OpenStack4j
*
* 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.huawei.openstack4j.openstack.senlin.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.huawei.openstack4j.model.senlin.PolicyCreate;
import com.huawei.openstack4j.model.senlin.builder.PolicyCreateBuilder;
import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.Map;
/**
* This class contains all elements required for the creation of a SenlinPolicy. It
* uses Jackson annotation for (de)serialization into JSON
*
* @author lion
*
*/
public class SenlinPolicyCreate implements PolicyCreate {
private static final long serialVersionUID = 2130740129242729916L;
@JsonProperty("policy")
private Map policy;
/**
* Returnes a {@link SenlinPolicyCreateConcreteBuilder} for configuration and
* creation of a {@link SenlinPolicyCreate} object.
*
* @return a {@link SenlinPolicyCreateConcreteBuilder}
*/
public static SenlinPolicyCreateConcreteBuilder build() {
return new SenlinPolicyCreateConcreteBuilder();
}
@Override
public PolicyCreateBuilder toBuilder() {
return new SenlinPolicyCreateConcreteBuilder(this);
}
/**
* A Builder to create a SenlinPolicy. Use {@link #build()} to receive the
* {@link PolicyCreate} object.
*
* @author lion
*
*/
public static class SenlinPolicyCreateConcreteBuilder implements
PolicyCreateBuilder {
private SenlinPolicyCreate model;
/**
* Constructor to create a {@link SenlinPolicyCreateConcreteBuilder} object
* with a new, empty {@link SenlinPolicyCreate} object.
*/
public SenlinPolicyCreateConcreteBuilder() {
this(new SenlinPolicyCreate());
}
/**
* Constructor for manipulation of an existing {@link SenlinPolicyCreate}
* object.
*
* @param model
* the {@link SenlinPolicyCreate} object which is to be
* modified.
*/
public SenlinPolicyCreateConcreteBuilder(SenlinPolicyCreate model) {
this.model = model;
this.model.policy = Maps.newHashMap();
HashMap spec = Maps.newHashMap();
HashMap properties = Maps.newHashMap();
HashMap adjustment = Maps.newHashMap();
properties.put("adjustment", adjustment);
spec.put("properties", properties);
this.model.policy.put("spec", spec);
}
@Override
public PolicyCreate build() {
return model;
}
@Override
public PolicyCreateBuilder from(PolicyCreate in) {
model = (SenlinPolicyCreate) in;
return this;
}
@Override
public PolicyCreateBuilder name(String name) {
model.policy.put("name", name);
return this;
}
@Override
public PolicyCreateBuilder spec(Map spec) {
model.policy.put("spec", spec);
return this;
}
@Override
public PolicyCreateBuilder properties(Map properties) {
HashMap spec = (HashMap)(model.policy.get("spec"));
spec.put("properties", properties);
return this;
}
@Override
public PolicyCreateBuilder adjustment(Map adjustment) {
HashMap properties = (HashMap)(((HashMap)(model.policy.get("spec"))).get("properties"));
properties.put("adjustment", adjustment);
return this;
}
@Override
public PolicyCreateBuilder minStep(int minStep) {
HashMap adjustment = (HashMap)(((HashMap)((HashMap)model.policy
.get("spec")).get("properties")).get("adjustment"));
adjustment.put("min_step", minStep);
return this;
}
@Override
public PolicyCreateBuilder number(int number) {
HashMap adjustment = (HashMap)(((HashMap)((HashMap)model.policy
.get("spec")).get("properties")).get("adjustment"));
adjustment.put("number", number);
return this;
}
@Override
public PolicyCreateBuilder adjustmentType(String adjustmentType) {
HashMap adjustment = (HashMap)(((HashMap)((HashMap)model.policy
.get("spec")).get("properties")).get("adjustment"));
adjustment.put("type", adjustmentType);
return this;
}
@Override
public PolicyCreateBuilder event(String event) {
HashMap properties = (HashMap)((HashMap)model.policy
.get("spec")).get("properties");
properties.put("event", event);
return this;
}
@Override
public PolicyCreateBuilder specType(String specType) {
HashMap spec = (HashMap)model.policy
.get("spec");
spec.put("type", specType);
return this;
}
@Override
public PolicyCreateBuilder version(String version) {
HashMap spec = (HashMap)model.policy
.get("spec");
spec.put("version", version);
return this;
}
}
}