package jp.ac.nii.prl.mape.autoscaling.analysis.model;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;

@Entity
public class Deployment {
	
	@Id
	@GeneratedValue
	@JsonIgnore
	private Integer id;
	
	@JsonIgnore
	@OneToOne(mappedBy="deployment")
	private Adaptation adaptation;

	@OneToMany(mappedBy="deployment")
	private List<Instance> instances;
	
	@OneToMany(mappedBy="deployment")
	private List<InstanceType> instanceTypes;

	@JsonManagedReference
	public Adaptation getAdaptation() {
		return adaptation;
	}

	public Integer getId() {
		return id;
	}

	@JsonManagedReference
	public List<Instance> getInstances() {
		return instances;
	}

	@JsonManagedReference
	public List<InstanceType> getInstanceTypes() {
		return instanceTypes;
	}

	public void setAdaptation(Adaptation adaptation) {
		this.adaptation = adaptation;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public void setInstances(List<Instance> instances) {
		this.instances = instances;
	}

	public void setInstanceTypes(List<InstanceType> instanceTypes) {
		this.instanceTypes = instanceTypes;
	}

	public int size() {
		return instances.size();
	}
	
	public String toString() {
		return String.format("Deployment %d with %d virtual machines", id, instances.size());
	}

}

@@ -687,16 +687,17 @@
 eTypes;%0A
+%09
 %0A%09@JsonM
@@ -995,32 +995,186 @@
 tanceTypes;%0A%09%7D%0A%0A
+%09public int getNumberCPUs() %7B%0A%09%09int cpus = 0;%0A%09%09for (Instance instance:instances)%0A%09%09%09cpus += instance.getInstanceType().getTypeCPUs();%0A%09%09return cpus;%0A%09%7D%0A%0A
 %09public void set

Add method to determine the number of CPUs active in a deployment