You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mu...@apache.org on 2013/05/13 17:53:37 UTC
[17/93] [abbrv] [partial] merge master
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/DcDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/DcDetailVO.java b/engine/schema/src/com/cloud/dc/DcDetailVO.java
new file mode 100644
index 0000000..15bfacb
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/DcDetailVO.java
@@ -0,0 +1,73 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="data_center_details")
+public class DcDetailVO implements InternalIdentity {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="dc_id")
+ private long dcId;
+
+ @Column(name="name")
+ private String name;
+
+ @Column(name="value")
+ private String value;
+
+ protected DcDetailVO() {
+ }
+
+ public DcDetailVO(long dcId, String name, String value) {
+ this.dcId = dcId;
+ this.name = name;
+ this.value = value;
+ }
+
+ public long getDcId() {
+ return dcId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public long getId() {
+ return id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/HostPodVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/HostPodVO.java b/engine/schema/src/com/cloud/dc/HostPodVO.java
new file mode 100644
index 0000000..e4ba9d0
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/HostPodVO.java
@@ -0,0 +1,197 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.Identity;
+import com.cloud.org.Grouping;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.db.GenericDao;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = "host_pod_ref")
+public class HostPodVO implements Pod {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ long id;
+
+ @Column(name = "name")
+ private String name = null;
+
+ @Column(name = "data_center_id")
+ private long dataCenterId;
+
+ @Column(name = "gateway")
+ private String gateway;
+
+ @Column(name = "cidr_address")
+ private String cidrAddress;
+
+ @Column(name = "cidr_size")
+ private int cidrSize;
+
+ @Column(name = "description")
+ private String description;
+
+ @Column(name="allocation_state")
+ @Enumerated(value=EnumType.STRING)
+ AllocationState allocationState;
+
+ @Column(name = "external_dhcp")
+ private Boolean externalDhcp;
+
+ @Column(name=GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = "uuid")
+ private String uuid;
+
+ public HostPodVO(String name, long dcId, String gateway, String cidrAddress, int cidrSize, String description) {
+ this.name = name;
+ this.dataCenterId = dcId;
+ this.gateway = gateway;
+ this.cidrAddress = cidrAddress;
+ this.cidrSize = cidrSize;
+ this.description = description;
+ this.allocationState = Grouping.AllocationState.Enabled;
+ this.externalDhcp = false;
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ /*
+ * public HostPodVO(String name, long dcId) { this(null, name, dcId); }
+ */
+ protected HostPodVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ public long getDataCenterId() {
+ return dataCenterId;
+ }
+
+ public void setDataCenterId(long dataCenterId) {
+ this.dataCenterId = dataCenterId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getCidrAddress() {
+ return cidrAddress;
+ }
+
+ public void setCidrAddress(String cidrAddress) {
+ this.cidrAddress = cidrAddress;
+ }
+
+ @Override
+ public int getCidrSize() {
+ return cidrSize;
+ }
+
+ public void setCidrSize(int cidrSize) {
+ this.cidrSize = cidrSize;
+ }
+
+ @Override
+ public String getGateway() {
+ return gateway;
+ }
+
+ public void setGateway(String gateway) {
+ this.gateway = gateway;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public AllocationState getAllocationState() {
+ return allocationState;
+ }
+
+ public void setAllocationState(AllocationState allocationState) {
+ this.allocationState = allocationState;
+ }
+
+ // Use for comparisons only.
+ public HostPodVO(Long id) {
+ this.id = id;
+ }
+
+ @Override
+ public int hashCode() {
+ return NumbersUtil.hash(id);
+ }
+
+ public boolean getExternalDhcp() {
+ return externalDhcp;
+ }
+
+ public void setExternalDhcp(boolean use) {
+ externalDhcp = use;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof HostPodVO) {
+ return id == ((HostPodVO)obj).id;
+ } else {
+ return false;
+ }
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/PodCluster.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/PodCluster.java b/engine/schema/src/com/cloud/dc/PodCluster.java
new file mode 100644
index 0000000..acffe4d
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/PodCluster.java
@@ -0,0 +1,67 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+public class PodCluster {
+ HostPodVO _pod;
+ ClusterVO _cluster;
+
+ protected PodCluster() {
+ super();
+ }
+
+ public PodCluster(HostPodVO pod, ClusterVO cluster) {
+ _pod = pod;
+ _cluster = cluster;
+ }
+
+ public HostPodVO getPod() {
+ return _pod;
+ }
+
+ public ClusterVO getCluster() {
+ return _cluster;
+ }
+
+
+ @Override
+ public int hashCode() {
+ return _pod.hashCode() ^ (_cluster != null ? _cluster.hashCode() : 0);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof PodCluster)) {
+ return false;
+ }
+
+ PodCluster that = (PodCluster)obj;
+ if (!this._pod.equals(that._pod)) {
+ return false;
+ }
+
+ if (this._cluster == null && that._cluster == null) {
+ return true;
+ }
+
+ if (this._cluster == null || that._cluster == null) {
+ return false;
+ }
+
+ return this._cluster.equals(that._cluster);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/PodVlanMapVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/PodVlanMapVO.java b/engine/schema/src/com/cloud/dc/PodVlanMapVO.java
new file mode 100644
index 0000000..8853fac
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/PodVlanMapVO.java
@@ -0,0 +1,62 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="pod_vlan_map")
+public class PodVlanMapVO implements InternalIdentity {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="pod_id")
+ private long podId;
+
+ @Column(name="vlan_db_id")
+ private long vlanDbId;
+
+ public PodVlanMapVO(long podId, long vlanDbId) {
+ this.podId = podId;
+ this.vlanDbId = vlanDbId;
+ }
+
+ public PodVlanMapVO() {
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getPodId() {
+ return podId;
+ }
+
+ public long getVlanDbId() {
+ return vlanDbId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/PodVlanVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/PodVlanVO.java b/engine/schema/src/com/cloud/dc/PodVlanVO.java
new file mode 100755
index 0000000..5324c84
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/PodVlanVO.java
@@ -0,0 +1,98 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="op_pod_vlan_alloc")
+public class PodVlanVO implements InternalIdentity {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ Long id;
+
+ @Column(name="taken", nullable=true)
+ @Temporal(value=TemporalType.TIMESTAMP)
+ Date takenAt;
+
+ @Column(name="vlan", updatable=false, nullable=false)
+ protected String vlan;
+
+ @Column(name="data_center_id")
+ long dataCenterId;
+
+ @Column(name="pod_id", updatable=false, nullable=false)
+ protected long podId;
+
+ @Column(name="account_id")
+ protected Long accountId;
+
+ public Date getTakenAt() {
+ return takenAt;
+ }
+
+ public void setTakenAt(Date taken) {
+ this.takenAt = taken;
+ }
+
+ public PodVlanVO(String vlan, long dataCenterId, long podId) {
+ this.vlan = vlan;
+ this.dataCenterId = dataCenterId;
+ this.podId = podId;
+ this.takenAt = null;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public Long getAccountId() {
+ return accountId;
+ }
+
+ public String getVlan() {
+ return vlan;
+ }
+
+ public long getDataCenterId() {
+ return dataCenterId;
+ }
+
+ public long getPodId() {
+ return podId;
+ }
+
+ public void setAccountId(Long accountId) {
+ this.accountId = accountId;
+ }
+
+ protected PodVlanVO() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/StorageNetworkIpAddressVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/StorageNetworkIpAddressVO.java b/engine/schema/src/com/cloud/dc/StorageNetworkIpAddressVO.java
new file mode 100755
index 0000000..6ad1ecd
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/StorageNetworkIpAddressVO.java
@@ -0,0 +1,120 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.SecondaryTable;
+import javax.persistence.SecondaryTables;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name="op_dc_storage_network_ip_address")
+@SecondaryTables({@SecondaryTable(name = "dc_storage_network_ip_range", pkJoinColumns = { @PrimaryKeyJoinColumn(name = "range_id", referencedColumnName = "id")})})
+public class StorageNetworkIpAddressVO implements InternalIdentity {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ long id;
+
+ @Column(name = "range_id")
+ long rangeId;
+
+ @Column(name = "ip_address", updatable = false, nullable = false)
+ String ipAddress;
+
+ @Column(name = "taken")
+ @Temporal(value = TemporalType.TIMESTAMP)
+ private Date takenAt;
+
+ @Column(name = "netmask", table = "dc_storage_network_ip_range", insertable = false, updatable = false)
+ private String netmask;
+
+ @Column(name = "mac_address")
+ long mac;
+
+ @Column(name = "vlan", table = "dc_storage_network_ip_range", insertable = false, updatable = false)
+ Integer vlan;
+
+ @Column(name = "gateway", table = "dc_storage_network_ip_range", insertable = false, updatable = false)
+ String gateway;
+
+ protected StorageNetworkIpAddressVO() {
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setTakenAt(Date takenDate) {
+ this.takenAt = takenDate;
+ }
+
+ public String getIpAddress() {
+ return ipAddress;
+ }
+
+ public void setIpAddress(String ip) {
+ this.ipAddress = ip;
+ }
+
+ public Date getTakenAt() {
+ return takenAt;
+ }
+
+ public long getRangeId() {
+ return rangeId;
+ }
+
+ public void setRangeId(long id) {
+ this.rangeId = id;
+ }
+
+ public long getMac() {
+ return mac;
+ }
+
+ public void setMac(long mac) {
+ this.mac = mac;
+ }
+
+ public String getNetmask() {
+ return netmask;
+ }
+
+ public void setNetmask(String netmask) {
+ this.netmask = netmask;
+ }
+
+ public Integer getVlan() {
+ return vlan;
+ }
+
+ public String getGateway() {
+ return gateway;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/StorageNetworkIpRangeVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/StorageNetworkIpRangeVO.java b/engine/schema/src/com/cloud/dc/StorageNetworkIpRangeVO.java
new file mode 100755
index 0000000..e410d22
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/StorageNetworkIpRangeVO.java
@@ -0,0 +1,184 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.SecondaryTable;
+import javax.persistence.SecondaryTables;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="dc_storage_network_ip_range")
+@SecondaryTables({@SecondaryTable(name="networks", pkJoinColumns={@PrimaryKeyJoinColumn(name="network_id", referencedColumnName="id")}),
+ @SecondaryTable(name="host_pod_ref", pkJoinColumns={@PrimaryKeyJoinColumn(name="pod_id", referencedColumnName="id")}),
+ @SecondaryTable(name="data_center", pkJoinColumns={@PrimaryKeyJoinColumn(name="data_center_id", referencedColumnName="id")})
+})
+public class StorageNetworkIpRangeVO implements StorageNetworkIpRange {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name = "id")
+ private long id;
+
+ @Column(name = "uuid")
+ String uuid;
+
+ @Column(name = "vlan")
+ private Integer vlan;
+
+ @Column(name = "data_center_id")
+ private long dataCenterId;
+
+ @Column(name = "pod_id")
+ private long podId;
+
+ @Column(name = "start_ip")
+ private String startIp;
+
+ @Column(name = "end_ip")
+ private String endIp;
+
+ @Column(name = "gateway")
+ private String gateway;
+
+ @Column(name = "network_id")
+ private long networkId;
+
+ @Column(name="netmask")
+ private String netmask;
+
+ @Column(name = "uuid", table = "networks", insertable = false, updatable = false)
+ String networkUuid;
+
+ @Column(name = "uuid", table = "host_pod_ref", insertable = false, updatable = false)
+ String podUuid;
+
+ @Column(name = "uuid", table = "data_center", insertable = false, updatable = false)
+ String zoneUuid;
+
+ public StorageNetworkIpRangeVO(long dcId, long podId, long networkId, String startIp, String endIp, Integer vlan, String netmask, String gateway) {
+ this();
+ this.dataCenterId = dcId;
+ this.podId = podId;
+ this.networkId = networkId;
+ this.startIp = startIp;
+ this.endIp = endIp;
+ this.vlan = vlan;
+ this.netmask = netmask;
+ this.gateway = gateway;
+ }
+
+ protected StorageNetworkIpRangeVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getDataCenterId() {
+ return dataCenterId;
+ }
+
+ public void setDataCenterId(long dcId) {
+ this.dataCenterId = dcId;
+ }
+
+ public long getPodId() {
+ return podId;
+ }
+
+ public void setPodId(long podId) {
+ this.podId = podId;
+ }
+
+ public long getNetworkId() {
+ return networkId;
+ }
+
+ public void setNetworkId(long nwId) {
+ this.networkId = nwId;
+ }
+
+ public Integer getVlan() {
+ return vlan;
+ }
+
+ public void setVlan(int vlan) {
+ this.vlan = vlan;
+ }
+
+ public void setStartIp(String start) {
+ this.startIp = start;
+ }
+
+ public String getStartIp() {
+ return startIp;
+ }
+
+ public void setEndIp(String end) {
+ this.endIp = end;
+ }
+
+ public String getEndIp() {
+ return endIp;
+ }
+
+ public String getNetmask() {
+ return netmask;
+ }
+
+ public String getGateway() {
+ return this.gateway;
+ }
+
+ public void setGateway(String gateway) {
+ this.gateway = gateway;
+ }
+
+ public void setNetmask(String netmask) {
+ this.netmask = netmask;
+ }
+
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+
+ @Override
+ public String getPodUuid() {
+ return podUuid;
+ }
+
+ @Override
+ public String getNetworkUuid() {
+ return networkUuid;
+ }
+
+ @Override
+ public String getZoneUuid() {
+ return zoneUuid;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/VlanVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/VlanVO.java b/engine/schema/src/com/cloud/dc/VlanVO.java
new file mode 100644
index 0000000..af6b5fc
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/VlanVO.java
@@ -0,0 +1,196 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name="vlan")
+public class VlanVO implements Vlan {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ Long id;
+
+ @Column(name="vlan_id")
+ String vlanTag;
+
+ @Column(name="vlan_gateway")
+ String vlanGateway;
+
+ @Column(name="vlan_netmask")
+ String vlanNetmask;
+
+ @Column(name="ip6_gateway")
+ String ip6Gateway;
+
+ @Column(name="ip6_cidr")
+ String ip6Cidr;
+
+ @Column(name="data_center_id")
+ long dataCenterId;
+
+ @Column(name="description")
+ String ipRange;
+
+ @Column(name="ip6_range")
+ String ip6Range;
+
+ @Column(name="network_id")
+ Long networkId;
+
+ @Column(name="physical_network_id")
+ Long physicalNetworkId;
+
+ @Column(name="vlan_type")
+ @Enumerated(EnumType.STRING)
+ VlanType vlanType;
+
+ @Column(name="uuid")
+ String uuid;
+
+ public VlanVO(VlanType vlanType, String vlanTag, String vlanGateway, String vlanNetmask, long dataCenterId, String ipRange, Long networkId, Long physicalNetworkId, String ip6Gateway, String ip6Cidr, String ip6Range) {
+ this.vlanType = vlanType;
+ this.vlanTag = vlanTag;
+ this.vlanGateway = vlanGateway;
+ this.vlanNetmask = vlanNetmask;
+ this.ip6Gateway = ip6Gateway;
+ this.ip6Cidr = ip6Cidr;
+ this.dataCenterId = dataCenterId;
+ this.ipRange = ipRange;
+ this.ip6Range = ip6Range;
+ this.networkId = networkId;
+ this.uuid = UUID.randomUUID().toString();
+ this.physicalNetworkId = physicalNetworkId;
+ }
+
+ public VlanVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ @Override
+ public long getId() {
+ return id;
+ }
+
+ @Override
+ public String getVlanTag() {
+ return vlanTag;
+ }
+
+ @Override
+ public String getVlanGateway() {
+ return vlanGateway;
+ }
+
+ @Override
+ public String getVlanNetmask() {
+ return vlanNetmask;
+ }
+
+ @Override
+ public long getDataCenterId() {
+ return dataCenterId;
+ }
+
+ @Override
+ public String getIpRange() {
+ return ipRange;
+ }
+
+ @Override
+ public VlanType getVlanType() {
+ return vlanType;
+ }
+
+ @Override
+ public Long getNetworkId() {
+ return networkId;
+ }
+
+ public void setNetworkId(Long networkId) {
+ this.networkId = networkId;
+ }
+
+ @Override
+ public String getUuid() {
+ return this.uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+ @Override
+ public Long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public void setPhysicalNetworkId(Long physicalNetworkId) {
+ this.physicalNetworkId = physicalNetworkId;
+ }
+
+ transient String toString;
+ @Override
+ public String toString() {
+ if (toString == null) {
+ toString = new StringBuilder("Vlan[").append(vlanTag).append("|").append(vlanGateway).append("|").append(vlanNetmask).
+ append("|").append(ip6Gateway).append("|").append(ip6Cidr).append("|").append(ipRange).append("|").
+ append("|").append(ip6Range).append(networkId).append("]").toString();
+ }
+ return toString;
+ }
+
+ @Override
+ public String getIp6Gateway() {
+ return ip6Gateway;
+ }
+
+ public void setIp6Gateway(String ip6Gateway) {
+ this.ip6Gateway = ip6Gateway;
+ }
+
+ @Override
+ public String getIp6Cidr() {
+ return ip6Cidr;
+ }
+
+ public void setIp6Cidr(String ip6Cidr) {
+ this.ip6Cidr = ip6Cidr;
+ }
+
+ @Override
+ public String getIp6Range() {
+ return ip6Range;
+ }
+
+ public void setIp6Range(String ip6Range) {
+ this.ip6Range = ip6Range;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDao.java b/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDao.java
new file mode 100644
index 0000000..c90557b
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDao.java
@@ -0,0 +1,30 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+
+import com.cloud.dc.AccountVlanMapVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface AccountVlanMapDao extends GenericDao<AccountVlanMapVO, Long> {
+
+ public List<AccountVlanMapVO> listAccountVlanMapsByAccount(long accountId);
+ public List<AccountVlanMapVO> listAccountVlanMapsByVlan(long vlanDbId);
+ public AccountVlanMapVO findAccountVlanMap(long accountId, long vlanDbId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDaoImpl.java
new file mode 100644
index 0000000..e4c0652
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/AccountVlanMapDaoImpl.java
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.AccountVlanMapVO;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+
+@Component
+@Local(value={AccountVlanMapDao.class})
+public class AccountVlanMapDaoImpl extends GenericDaoBase<AccountVlanMapVO, Long> implements AccountVlanMapDao {
+
+ protected SearchBuilder<AccountVlanMapVO> AccountSearch;
+ protected SearchBuilder<AccountVlanMapVO> VlanSearch;
+ protected SearchBuilder<AccountVlanMapVO> AccountVlanSearch;
+
+ @Override
+ public List<AccountVlanMapVO> listAccountVlanMapsByAccount(long accountId) {
+ SearchCriteria<AccountVlanMapVO> sc = AccountSearch.create();
+ sc.setParameters("accountId", accountId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<AccountVlanMapVO> listAccountVlanMapsByVlan(long vlanDbId) {
+ SearchCriteria<AccountVlanMapVO> sc = VlanSearch.create();
+ sc.setParameters("vlanDbId", vlanDbId);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public AccountVlanMapVO findAccountVlanMap(long accountId, long vlanDbId) {
+ SearchCriteria<AccountVlanMapVO> sc = AccountVlanSearch.create();
+ sc.setParameters("accountId", accountId);
+ sc.setParameters("vlanDbId", vlanDbId);
+ return findOneIncludingRemovedBy(sc);
+ }
+
+ public AccountVlanMapDaoImpl() {
+ AccountSearch = createSearchBuilder();
+ AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+ AccountSearch.done();
+
+ VlanSearch = createSearchBuilder();
+ VlanSearch.and("vlanDbId", VlanSearch.entity().getVlanDbId(), SearchCriteria.Op.EQ);
+ VlanSearch.done();
+
+ AccountVlanSearch = createSearchBuilder();
+ AccountVlanSearch.and("accountId", AccountVlanSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+ AccountVlanSearch.and("vlanDbId", AccountVlanSearch.entity().getVlanDbId(), SearchCriteria.Op.EQ);
+ AccountVlanSearch.done();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/ClusterDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/ClusterDao.java b/engine/schema/src/com/cloud/dc/dao/ClusterDao.java
new file mode 100644
index 0000000..3ce0798
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/ClusterDao.java
@@ -0,0 +1,37 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+import java.util.Map;
+
+import com.cloud.dc.ClusterVO;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.utils.db.GenericDao;
+
+public interface ClusterDao extends GenericDao<ClusterVO, Long> {
+ List<ClusterVO> listByPodId(long podId);
+ ClusterVO findBy(String name, long podId);
+ List<ClusterVO> listByHyTypeWithoutGuid(String hyType);
+ List<ClusterVO> listByZoneId(long zoneId);
+
+ List<HypervisorType> getAvailableHypervisorInZone(Long zoneId);
+ List<ClusterVO> listByDcHyType(long dcId, String hyType);
+ Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds);
+ List<Long> listDisabledClusters(long zoneId, Long podId);
+ List<Long> listClustersWithDisabledPods(long zoneId);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/ClusterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/ClusterDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/ClusterDaoImpl.java
new file mode 100644
index 0000000..86dc65e
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/ClusterDaoImpl.java
@@ -0,0 +1,241 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.HostPodVO;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.org.Grouping;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+@Local(value=ClusterDao.class)
+public class ClusterDaoImpl extends GenericDaoBase<ClusterVO, Long> implements ClusterDao {
+
+ protected final SearchBuilder<ClusterVO> PodSearch;
+ protected final SearchBuilder<ClusterVO> HyTypeWithoutGuidSearch;
+ protected final SearchBuilder<ClusterVO> AvailHyperSearch;
+ protected final SearchBuilder<ClusterVO> ZoneSearch;
+ protected final SearchBuilder<ClusterVO> ZoneHyTypeSearch;
+
+ private static final String GET_POD_CLUSTER_MAP_PREFIX = "SELECT pod_id, id FROM cloud.cluster WHERE cluster.id IN( ";
+ private static final String GET_POD_CLUSTER_MAP_SUFFIX = " )";
+ @Inject
+ protected HostPodDao _hostPodDao;
+
+ public ClusterDaoImpl() {
+ super();
+
+ HyTypeWithoutGuidSearch = createSearchBuilder();
+ HyTypeWithoutGuidSearch.and("hypervisorType", HyTypeWithoutGuidSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+ HyTypeWithoutGuidSearch.and("guid", HyTypeWithoutGuidSearch.entity().getGuid(), SearchCriteria.Op.NULL);
+ HyTypeWithoutGuidSearch.done();
+
+ ZoneHyTypeSearch = createSearchBuilder();
+ ZoneHyTypeSearch.and("hypervisorType", ZoneHyTypeSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
+ ZoneHyTypeSearch.and("dataCenterId", ZoneHyTypeSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ ZoneHyTypeSearch.done();
+
+ PodSearch = createSearchBuilder();
+ PodSearch.and("pod", PodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+ PodSearch.and("name", PodSearch.entity().getName(), SearchCriteria.Op.EQ);
+ PodSearch.done();
+
+ ZoneSearch = createSearchBuilder();
+ ZoneSearch.and("dataCenterId", ZoneSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ ZoneSearch.groupBy(ZoneSearch.entity().getHypervisorType());
+ ZoneSearch.done();
+
+ AvailHyperSearch = createSearchBuilder();
+ AvailHyperSearch.and("zoneId", AvailHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ AvailHyperSearch.select(null, Func.DISTINCT, AvailHyperSearch.entity().getHypervisorType());
+ AvailHyperSearch.done();
+ }
+
+ @Override
+ public List<ClusterVO> listByZoneId(long zoneId) {
+ SearchCriteria<ClusterVO> sc = ZoneSearch.create();
+ sc.setParameters("dataCenterId", zoneId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<ClusterVO> listByPodId(long podId) {
+ SearchCriteria<ClusterVO> sc = PodSearch.create();
+ sc.setParameters("pod", podId);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public ClusterVO findBy(String name, long podId) {
+ SearchCriteria<ClusterVO> sc = PodSearch.create();
+ sc.setParameters("pod", podId);
+ sc.setParameters("name", name);
+
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<ClusterVO> listByHyTypeWithoutGuid(String hyType) {
+ SearchCriteria<ClusterVO> sc = HyTypeWithoutGuidSearch.create();
+ sc.setParameters("hypervisorType", hyType);
+
+ return listBy(sc);
+ }
+
+ @Override
+ public List<ClusterVO> listByDcHyType(long dcId, String hyType) {
+ SearchCriteria<ClusterVO> sc = ZoneHyTypeSearch.create();
+ sc.setParameters("dataCenterId", dcId);
+ sc.setParameters("hypervisorType", hyType);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<HypervisorType> getAvailableHypervisorInZone(Long zoneId) {
+ SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
+ if (zoneId != null) {
+ sc.setParameters("zoneId", zoneId);
+ }
+ List<ClusterVO> clusters = listBy(sc);
+ List<HypervisorType> hypers = new ArrayList<HypervisorType>(4);
+ for (ClusterVO cluster : clusters) {
+ hypers.add(cluster.getHypervisorType());
+ }
+
+ return hypers;
+ }
+
+ @Override
+ public Map<Long, List<Long>> getPodClusterIdMap(List<Long> clusterIds){
+ Transaction txn = Transaction.currentTxn();
+ PreparedStatement pstmt = null;
+ Map<Long, List<Long>> result = new HashMap<Long, List<Long>>();
+
+ try {
+ StringBuilder sql = new StringBuilder(GET_POD_CLUSTER_MAP_PREFIX);
+ if (clusterIds.size() > 0) {
+ for (Long clusterId : clusterIds) {
+ sql.append(clusterId).append(",");
+ }
+ sql.delete(sql.length()-1, sql.length());
+ sql.append(GET_POD_CLUSTER_MAP_SUFFIX);
+ }
+
+ pstmt = txn.prepareAutoCloseStatement(sql.toString());
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ Long podId = rs.getLong(1);
+ Long clusterIdInPod = rs.getLong(2);
+ if(result.containsKey(podId)){
+ List<Long> clusterList = result.get(podId);
+ clusterList.add(clusterIdInPod);
+ result.put(podId, clusterList);
+ }else{
+ List<Long> clusterList = new ArrayList<Long>();
+ clusterList.add(clusterIdInPod);
+ result.put(podId, clusterList);
+ }
+ }
+ return result;
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("DB Exception on: " + GET_POD_CLUSTER_MAP_PREFIX, e);
+ } catch (Throwable e) {
+ throw new CloudRuntimeException("Caught: " + GET_POD_CLUSTER_MAP_PREFIX, e);
+ }
+ }
+
+ @Override
+ public List<Long> listDisabledClusters(long zoneId, Long podId) {
+ GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
+ clusterIdSearch.selectField(clusterIdSearch.entity().getId());
+ clusterIdSearch.and("dataCenterId", clusterIdSearch.entity().getDataCenterId(), Op.EQ);
+ if(podId != null){
+ clusterIdSearch.and("podId", clusterIdSearch.entity().getPodId(), Op.EQ);
+ }
+ clusterIdSearch.and("allocationState", clusterIdSearch.entity().getAllocationState(), Op.EQ);
+ clusterIdSearch.done();
+
+
+ SearchCriteria<Long> sc = clusterIdSearch.create();
+ sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
+ if (podId != null) {
+ sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
+ }
+ sc.addAnd("allocationState", SearchCriteria.Op.EQ, Grouping.AllocationState.Disabled);
+ return customSearch(sc, null);
+ }
+
+ @Override
+ public List<Long> listClustersWithDisabledPods(long zoneId) {
+
+ GenericSearchBuilder<HostPodVO, Long> disabledPodIdSearch = _hostPodDao.createSearchBuilder(Long.class);
+ disabledPodIdSearch.selectField(disabledPodIdSearch.entity().getId());
+ disabledPodIdSearch.and("dataCenterId", disabledPodIdSearch.entity().getDataCenterId(), Op.EQ);
+ disabledPodIdSearch.and("allocationState", disabledPodIdSearch.entity().getAllocationState(), Op.EQ);
+
+ GenericSearchBuilder<ClusterVO, Long> clusterIdSearch = createSearchBuilder(Long.class);
+ clusterIdSearch.selectField(clusterIdSearch.entity().getId());
+ clusterIdSearch.join("disabledPodIdSearch", disabledPodIdSearch, clusterIdSearch.entity().getPodId(), disabledPodIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+ clusterIdSearch.done();
+
+
+ SearchCriteria<Long> sc = clusterIdSearch.create();
+ sc.setJoinParameters("disabledPodIdSearch", "dataCenterId", zoneId);
+ sc.setJoinParameters("disabledPodIdSearch", "allocationState", Grouping.AllocationState.Disabled);
+
+ return customSearch(sc, null);
+ }
+
+ @Override
+ public boolean remove(Long id) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ ClusterVO cluster = createForUpdate();
+ cluster.setName(null);
+ cluster.setGuid(null);
+
+ update(id, cluster);
+
+ boolean result = super.remove(id);
+ txn.commit();
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDao.java b/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDao.java
new file mode 100644
index 0000000..ae08e59
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDao.java
@@ -0,0 +1,29 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+
+import com.cloud.dc.ClusterVSMMapVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface ClusterVSMMapDao extends GenericDao<ClusterVSMMapVO, Long> {
+ ClusterVSMMapVO findByClusterId(long clusterId);
+ List<ClusterVSMMapVO> listByVSMId(long vsmId);
+ boolean removeByVsmId(long vsmId);
+ boolean removeByClusterId(long clusterId);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDaoImpl.java
new file mode 100644
index 0000000..b12fa9d
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/ClusterVSMMapDaoImpl.java
@@ -0,0 +1,95 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+import javax.ejb.Local;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.ClusterVSMMapVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+@Local(value=ClusterVSMMapDao.class)
+@DB(txn = false)
+public class ClusterVSMMapDaoImpl extends GenericDaoBase<ClusterVSMMapVO, Long> implements ClusterVSMMapDao {
+
+ final SearchBuilder<ClusterVSMMapVO> ClusterSearch;
+ final SearchBuilder<ClusterVSMMapVO> VsmSearch;
+
+ public ClusterVSMMapDaoImpl() {
+ //super();
+
+ ClusterSearch = createSearchBuilder();
+ ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+ ClusterSearch.done();
+
+ VsmSearch = createSearchBuilder();
+ VsmSearch.and("vsmId", VsmSearch.entity().getVsmId(), SearchCriteria.Op.EQ);
+ VsmSearch.done();
+ }
+
+ @Override
+ public boolean removeByVsmId(long vsmId) {
+ SearchCriteria<ClusterVSMMapVO> sc = VsmSearch.create();
+ sc.setParameters("vsmId", vsmId);
+ this.remove(sc);
+ return true;
+ }
+
+ @Override
+ public boolean removeByClusterId(long clusterId) {
+ SearchCriteria<ClusterVSMMapVO> sc = ClusterSearch.create();
+ sc.setParameters("clusterId", clusterId);
+ this.remove(sc);
+ return true;
+ }
+
+ @Override
+ public ClusterVSMMapVO findByClusterId(long clusterId) {
+ SearchCriteria<ClusterVSMMapVO> sc = ClusterSearch.create();
+ sc.setParameters("clusterId", clusterId);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<ClusterVSMMapVO> listByVSMId(long vsmId) {
+ SearchCriteria<ClusterVSMMapVO> sc = VsmSearch.create();
+ sc.setParameters("vsmId", vsmId);
+ return listBy(sc);
+ }
+
+ public boolean remove(Long id) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ ClusterVSMMapVO cluster = createForUpdate();
+ //cluster.setClusterId(null);
+ //cluster.setVsmId(null);
+
+ update(id, cluster);
+
+ boolean result = super.remove(id);
+ txn.commit();
+ return result;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java b/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java
new file mode 100755
index 0000000..e54b9bb
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterDao.java
@@ -0,0 +1,82 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+
+import com.cloud.dc.DataCenterIpAddressVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.DataCenterVnetVO;
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.GenericDao;
+
+public interface DataCenterDao extends GenericDao<DataCenterVO, Long> {
+ DataCenterVO findByName(String name);
+
+ /**
+ * @param id data center id
+ * @return a pair of mac address strings. The first one is private and second is public.
+ */
+ String[] getNextAvailableMacAddressPair(long id);
+ String[] getNextAvailableMacAddressPair(long id, long mask);
+ Pair<String, Long> allocatePrivateIpAddress(long id, long podId, long instanceId, String reservationId);
+ DataCenterIpAddressVO allocatePrivateIpAddress(long id, String reservationId);
+ String allocateLinkLocalIpAddress(long id, long podId, long instanceId, String reservationId);
+ String allocateVnet(long dcId, long physicalNetworkId, long accountId, String reservationId);
+
+ void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId);
+ void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId);
+ void releasePrivateIpAddress(long nicId, String reservationId);
+ void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId);
+ void releaseLinkLocalIpAddress(long nicId, String reservationId);
+
+ boolean deletePrivateIpAddressByPod(long podId);
+ boolean deleteLinkLocalIpAddressByPod(long podId);
+
+ void addPrivateIpAddress(long dcId,long podId, String start, String end);
+ void addLinkLocalIpAddress(long dcId,long podId, String start, String end);
+
+ List<DataCenterVnetVO> findVnet(long dcId, long physicalNetworkId, String vnet);
+
+ String allocatePodVlan(long podId, long accountId);
+
+ List<DataCenterVO> findZonesByDomainId(Long domainId);
+
+ List<DataCenterVO> listPublicZones(String keyword);
+
+ List<DataCenterVO> findChildZones(Object[] ids, String keyword);
+
+ void loadDetails(DataCenterVO zone);
+ void saveDetails(DataCenterVO zone);
+
+ List<DataCenterVO> listDisabledZones();
+ List<DataCenterVO> listEnabledZones();
+ DataCenterVO findByToken(String zoneToken);
+ DataCenterVO findByTokenOrIdOrName(String tokenIdOrName);
+
+ int countZoneVlans(long dcId, boolean onlyCountAllocated);
+
+ void addVnet(long dcId, long physicalNetworkId, int start, int end);
+ void deleteVnet(long physicalNetworkId);
+ List<DataCenterVnetVO> listAllocatedVnets(long physicalNetworkId);
+
+ List<DataCenterVO> findZonesByDomainId(Long domainId, String keyword);
+
+ List<DataCenterVO> findByKeyword(String keyword);
+
+ List<DataCenterVO> listAllZones();
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
new file mode 100755
index 0000000..4d9d010
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterDaoImpl.java
@@ -0,0 +1,425 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import javax.persistence.TableGenerator;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.DataCenterIpAddressVO;
+import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.DataCenterVnetVO;
+import com.cloud.dc.PodVlanVO;
+import com.cloud.network.dao.AccountGuestVlanMapDao;
+import com.cloud.network.dao.AccountGuestVlanMapVO;
+import com.cloud.org.Grouping;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.Pair;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SequenceFetcher;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.net.NetUtils;
+
+/**
+ * @config
+ * {@table
+ * || Param Name | Description | Values | Default ||
+ * || mac.address.prefix | prefix to attach to all public and private mac addresses | number | 06 ||
+ * }
+ **/
+@Component
+@Local(value={DataCenterDao.class})
+public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implements DataCenterDao {
+ private static final Logger s_logger = Logger.getLogger(DataCenterDaoImpl.class);
+
+ protected SearchBuilder<DataCenterVO> NameSearch;
+ protected SearchBuilder<DataCenterVO> ListZonesByDomainIdSearch;
+ protected SearchBuilder<DataCenterVO> PublicZonesSearch;
+ protected SearchBuilder<DataCenterVO> ChildZonesSearch;
+ protected SearchBuilder<DataCenterVO> DisabledZonesSearch;
+ protected SearchBuilder<DataCenterVO> TokenSearch;
+
+ @Inject protected DataCenterIpAddressDao _ipAllocDao = null;
+ @Inject protected DataCenterLinkLocalIpAddressDao _LinkLocalIpAllocDao = null;
+ @Inject protected DataCenterVnetDao _vnetAllocDao = null;
+ @Inject protected PodVlanDao _podVlanAllocDao = null;
+ @Inject protected DcDetailsDao _detailsDao = null;
+ @Inject protected AccountGuestVlanMapDao _accountGuestVlanMapDao = null;
+
+ protected long _prefix;
+ protected Random _rand = new Random(System.currentTimeMillis());
+ protected TableGenerator _tgMacAddress;
+
+
+ @Override
+ public DataCenterVO findByName(String name) {
+ SearchCriteria<DataCenterVO> sc = NameSearch.create();
+ sc.setParameters("name", name);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public DataCenterVO findByToken(String zoneToken){
+ SearchCriteria<DataCenterVO> sc = TokenSearch.create();
+ sc.setParameters("zoneToken", zoneToken);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<DataCenterVO> findZonesByDomainId(Long domainId){
+ SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create();
+ sc.setParameters("domainId", domainId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<DataCenterVO> findZonesByDomainId(Long domainId, String keyword){
+ SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create();
+ sc.setParameters("domainId", domainId);
+ if (keyword != null) {
+ SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ sc.addAnd("name", SearchCriteria.Op.SC, ssc);
+ }
+ return listBy(sc);
+ }
+
+ @Override
+ public List<DataCenterVO> findChildZones(Object[] ids, String keyword){
+ SearchCriteria<DataCenterVO> sc = ChildZonesSearch.create();
+ sc.setParameters("domainid", ids);
+ if (keyword != null) {
+ SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ sc.addAnd("name", SearchCriteria.Op.SC, ssc);
+ }
+ return listBy(sc);
+ }
+
+ @Override
+ public List<DataCenterVO> listPublicZones(String keyword){
+ SearchCriteria<DataCenterVO> sc = PublicZonesSearch.create();
+ if (keyword != null) {
+ SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ sc.addAnd("name", SearchCriteria.Op.SC, ssc);
+ }
+ //sc.setParameters("domainId", domainId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<DataCenterVO> findByKeyword(String keyword){
+ SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
+ ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
+ return listBy(ssc);
+ }
+
+ @Override
+ public void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId) {
+ _vnetAllocDao.release(vnet, physicalNetworkId, accountId, reservationId);
+ }
+
+ @Override
+ public List<DataCenterVnetVO> findVnet(long dcId, long physicalNetworkId, String vnet) {
+ return _vnetAllocDao.findVnet(dcId, physicalNetworkId, vnet);
+ }
+
+ @Override
+ public int countZoneVlans(long dcId, boolean onlyCountAllocated){
+ return _vnetAllocDao.countZoneVlans(dcId, onlyCountAllocated);
+ }
+
+ @Override
+ public void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId) {
+ _ipAllocDao.releaseIpAddress(ipAddress, dcId, instanceId);
+ }
+
+ @Override
+ public void releasePrivateIpAddress(long nicId, String reservationId) {
+ _ipAllocDao.releaseIpAddress(nicId, reservationId);
+ }
+
+ @Override
+ public void releaseLinkLocalIpAddress(long nicId, String reservationId) {
+ _LinkLocalIpAllocDao.releaseIpAddress(nicId, reservationId);
+ }
+
+ @Override
+ public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) {
+ _LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId);
+ }
+
+ @Override
+ public boolean deletePrivateIpAddressByPod(long podId) {
+ return _ipAllocDao.deleteIpAddressByPod(podId);
+ }
+
+ @Override
+ public boolean deleteLinkLocalIpAddressByPod(long podId) {
+ return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId);
+ }
+
+ @Override
+ public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId) {
+ ArrayList<Long> dedicatedVlanDbIds = new ArrayList<Long>();
+ List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId);
+ for (AccountGuestVlanMapVO map : maps) {
+ dedicatedVlanDbIds.add(map.getId());
+ }
+ if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
+ DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, dedicatedVlanDbIds);
+ if (vo != null)
+ return vo.getVnet();
+ }
+ DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null);
+ if (vo == null) {
+ return null;
+ }
+ return vo.getVnet();
+ }
+
+ @Override
+ public String allocatePodVlan(long podId, long accountId) {
+ PodVlanVO vo = _podVlanAllocDao.take(podId, accountId);
+ if (vo == null) {
+ return null;
+ }
+ return vo.getVlan();
+ }
+
+ @Override
+ public String[] getNextAvailableMacAddressPair(long id) {
+ return getNextAvailableMacAddressPair(id, 0);
+ }
+
+ @Override
+ public String[] getNextAvailableMacAddressPair(long id, long mask) {
+ SequenceFetcher fetch = SequenceFetcher.getInstance();
+
+ long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id);
+ seq = seq | _prefix | ((id & 0x7f) << 32);
+ seq |= mask;
+ seq |= ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
+ String[] pair = new String[2];
+ pair[0] = NetUtils.long2Mac(seq);
+ pair[1] = NetUtils.long2Mac(seq | 0x1l << 39);
+ return pair;
+ }
+
+ @Override
+ public Pair<String, Long> allocatePrivateIpAddress(long dcId, long podId, long instanceId, String reservationId) {
+ DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId);
+ if (vo == null) {
+ return null;
+ }
+ return new Pair<String, Long>(vo.getIpAddress(), vo.getMacAddress());
+ }
+
+ @Override
+ public DataCenterIpAddressVO allocatePrivateIpAddress(long dcId, String reservationId) {
+ DataCenterIpAddressVO vo = _ipAllocDao.takeDataCenterIpAddress(dcId, reservationId);
+ return vo;
+ }
+
+ @Override
+ public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) {
+ DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId);
+ if (vo == null) {
+ return null;
+ }
+ return vo.getIpAddress();
+ }
+
+ @Override
+ public void addVnet(long dcId, long physicalNetworkId, int start, int end) {
+ _vnetAllocDao.add(dcId, physicalNetworkId, start, end);
+ }
+
+ @Override
+ public void deleteVnet(long physicalNetworkId) {
+ _vnetAllocDao.delete(physicalNetworkId);
+ }
+
+ @Override
+ public List<DataCenterVnetVO> listAllocatedVnets(long physicalNetworkId) {
+ return _vnetAllocDao.listAllocatedVnets(physicalNetworkId);
+ }
+
+ @Override
+ public void addPrivateIpAddress(long dcId,long podId, String start, String end) {
+ _ipAllocDao.addIpRange(dcId, podId, start, end);
+ }
+
+ @Override
+ public void addLinkLocalIpAddress(long dcId,long podId, String start, String end) {
+ _LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end);
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ if (!super.configure(name, params)) {
+ return false;
+ }
+
+ String value = (String)params.get("mac.address.prefix");
+ _prefix = (long)NumbersUtil.parseInt(value, 06) << 40;
+
+ if (!_ipAllocDao.configure("Ip Alloc", params)) {
+ return false;
+ }
+
+ if (!_vnetAllocDao.configure("vnet Alloc", params)) {
+ return false;
+ }
+ return true;
+ }
+
+ public DataCenterDaoImpl() {
+ super();
+ NameSearch = createSearchBuilder();
+ NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+ NameSearch.done();
+
+ ListZonesByDomainIdSearch = createSearchBuilder();
+ ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
+ ListZonesByDomainIdSearch.done();
+
+ PublicZonesSearch = createSearchBuilder();
+ PublicZonesSearch.and("domainId", PublicZonesSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
+ PublicZonesSearch.done();
+
+ ChildZonesSearch = createSearchBuilder();
+ ChildZonesSearch.and("domainid", ChildZonesSearch.entity().getDomainId(), SearchCriteria.Op.IN);
+ ChildZonesSearch.done();
+
+ DisabledZonesSearch = createSearchBuilder();
+ DisabledZonesSearch.and("allocationState", DisabledZonesSearch.entity().getAllocationState(), SearchCriteria.Op.EQ);
+ DisabledZonesSearch.done();
+
+ TokenSearch = createSearchBuilder();
+ TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ);
+ TokenSearch.done();
+
+ _tgMacAddress = _tgs.get("macAddress");
+ assert _tgMacAddress != null : "Couldn't get mac address table generator";
+ }
+
+ @Override @DB
+ public boolean update(Long zoneId, DataCenterVO zone) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ boolean persisted = super.update(zoneId, zone);
+ if (!persisted) {
+ return persisted;
+ }
+ saveDetails(zone);
+ txn.commit();
+ return persisted;
+ }
+
+ @Override
+ public void loadDetails(DataCenterVO zone) {
+ Map<String, String> details =_detailsDao.findDetails(zone.getId());
+ zone.setDetails(details);
+ }
+
+ @Override
+ public void saveDetails(DataCenterVO zone) {
+ Map<String, String> details = zone.getDetails();
+ if (details == null) {
+ return;
+ }
+ _detailsDao.persist(zone.getId(), details);
+ }
+
+ @Override
+ public List<DataCenterVO> listDisabledZones(){
+ SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create();
+ sc.setParameters("allocationState", Grouping.AllocationState.Disabled);
+
+ List<DataCenterVO> dcs = listBy(sc);
+
+ return dcs;
+ }
+
+ @Override
+ public List<DataCenterVO> listEnabledZones(){
+ SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create();
+ sc.setParameters("allocationState", Grouping.AllocationState.Enabled);
+
+ List<DataCenterVO> dcs = listBy(sc);
+
+ return dcs;
+ }
+
+ @Override
+ public DataCenterVO findByTokenOrIdOrName(String tokenOrIdOrName) {
+ DataCenterVO result = findByToken(tokenOrIdOrName);
+ if (result == null) {
+ result = findByName(tokenOrIdOrName);
+ if (result == null) {
+ try {
+ Long dcId = Long.parseLong(tokenOrIdOrName);
+ return findById(dcId);
+ } catch (NumberFormatException nfe) {
+
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean remove(Long id) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ DataCenterVO zone = createForUpdate();
+ zone.setName(null);
+
+ update(id, zone);
+
+ boolean result = super.remove(id);
+ txn.commit();
+ return result;
+ }
+
+ @Override
+ public List<DataCenterVO> listAllZones(){
+ SearchCriteria<DataCenterVO> sc = NameSearch.create();
+ List<DataCenterVO> dcs = listBy(sc);
+
+ return dcs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
new file mode 100644
index 0000000..7a19b24
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDao.java
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+
+import com.cloud.dc.DataCenterIpAddressVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface DataCenterIpAddressDao extends GenericDao<DataCenterIpAddressVO, Long> {
+
+ public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId);
+ public DataCenterIpAddressVO takeDataCenterIpAddress(long dcId, String reservationId);
+ public void addIpRange(long dcId, long podId, String start, String end);
+ public void releaseIpAddress(String ipAddress, long dcId, Long instanceId);
+ public void releaseIpAddress(long nicId, String reservationId);
+
+ boolean mark(long dcId, long podId, String ip);
+ List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress);
+ List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId);
+ int countIPs(long podId, long dcId, boolean onlyCountAllocated);
+ boolean deleteIpAddressByPod(long podId);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
new file mode 100755
index 0000000..353402d
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
@@ -0,0 +1,225 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.List;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import com.cloud.dc.DataCenterIpAddressVO;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+
+@Component
+@Local(value={DataCenterIpAddressDao.class}) @DB(txn=false)
+public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddressVO, Long> implements DataCenterIpAddressDao {
+ private static final Logger s_logger = Logger.getLogger(DataCenterIpAddressDaoImpl.class);
+
+ private final SearchBuilder<DataCenterIpAddressVO> AllFieldsSearch;
+ private final GenericSearchBuilder<DataCenterIpAddressVO, Integer> AllIpCount;
+ private final GenericSearchBuilder<DataCenterIpAddressVO, Integer> AllAllocatedIpCount;
+
+ @DB
+ public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId) {
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("pod", podId);
+ sc.setParameters("taken", (Date)null);
+
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ DataCenterIpAddressVO vo = lockOneRandomRow(sc, true);
+ if (vo == null) {
+ txn.rollback();
+ return null;
+ }
+ vo.setTakenAt(new Date());
+ vo.setInstanceId(instanceId);
+ vo.setReservationId(reservationId);
+ update(vo.getId(), vo);
+ txn.commit();
+ return vo;
+ }
+
+ @DB
+ public DataCenterIpAddressVO takeDataCenterIpAddress(long dcId, String reservationId) {
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("dc", dcId);
+ sc.setParameters("taken", (Date)null);
+
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ DataCenterIpAddressVO vo = lockOneRandomRow(sc, true);
+ if (vo == null) {
+ txn.rollback();
+ return null;
+ }
+ vo.setTakenAt(new Date());
+ vo.setReservationId(reservationId);
+ update(vo.getId(), vo);
+ txn.commit();
+ return vo;
+ }
+
+ @Override
+ public boolean deleteIpAddressByPod(long podId) {
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("pod", podId);
+ return remove(sc) > 0;
+ }
+
+ @Override
+ public boolean mark(long dcId, long podId, String ip) {
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("pod", podId);
+ sc.setParameters("ipAddress", ip);
+
+ DataCenterIpAddressVO vo = createForUpdate();
+ vo.setTakenAt(new Date());
+
+ return update(vo, sc) >= 1;
+ }
+
+ @DB
+ public void addIpRange(long dcId, long podId, String start, String end) {
+ Transaction txn = Transaction.currentTxn();
+ String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))";
+ String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
+ PreparedStatement stmt = null;
+
+ long startIP = NetUtils.ip2Long(start);
+ long endIP = NetUtils.ip2Long(end);
+
+ try {
+ txn.start();
+
+ while (startIP <= endIP) {
+ stmt = txn.prepareStatement(insertSql);
+ stmt.setString(1, NetUtils.long2Ip(startIP++));
+ stmt.setLong(2, dcId);
+ stmt.setLong(3, podId);
+ stmt.setLong(4, dcId);
+ stmt.executeUpdate();
+ stmt.close();
+ stmt = txn.prepareStatement(updateSql);
+ stmt.setLong(1, dcId);
+ stmt.executeUpdate();
+ stmt.close();
+ }
+ txn.commit();
+ } catch (SQLException ex) {
+ throw new CloudRuntimeException("Unable to persist ip address range ", ex);
+ }
+ }
+
+ public void releaseIpAddress(String ipAddress, long dcId, Long instanceId) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId);
+ }
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("ip", ipAddress);
+ sc.setParameters("dc", dcId);
+ sc.setParameters("instance", instanceId);
+
+ DataCenterIpAddressVO vo = createForUpdate();
+
+ vo.setTakenAt(null);
+ vo.setInstanceId(null);
+ vo.setReservationId(null);
+ update(vo, sc);
+ }
+
+ public void releaseIpAddress(long nicId, String reservationId) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Releasing ip address for reservationId=" + reservationId + ", instance=" + nicId);
+ }
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("instance", nicId);
+ sc.setParameters("reservation", reservationId);
+
+ DataCenterIpAddressVO vo = createForUpdate();
+ vo.setTakenAt(null);
+ vo.setInstanceId(null);
+ vo.setReservationId(null);
+ update(vo, sc);
+ }
+
+ public List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId) {
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("pod", podId);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) {
+ SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
+ sc.setParameters("pod", podId);
+ sc.setParameters("ipAddress", ipAddress);
+ return listBy(sc);
+ }
+
+ @Override
+ public int countIPs(long podId, long dcId, boolean onlyCountAllocated) {
+ SearchCriteria<Integer> sc;
+ if (onlyCountAllocated) {
+ sc = AllAllocatedIpCount.create();
+ } else {
+ sc = AllIpCount.create();
+ }
+
+ sc.setParameters("pod", podId);
+ List<Integer> count = customSearch(sc, null);
+ return count.get(0);
+ }
+
+ public DataCenterIpAddressDaoImpl() {
+ super();
+
+ AllFieldsSearch = createSearchBuilder();
+ AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
+ AllFieldsSearch.done();
+
+ AllIpCount = createSearchBuilder(Integer.class);
+ AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId());
+ AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ);
+ AllIpCount.done();
+
+ AllAllocatedIpCount = createSearchBuilder(Integer.class);
+ AllAllocatedIpCount.select(null, Func.COUNT, AllAllocatedIpCount.entity().getId());
+ AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ);
+ AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL);
+ AllAllocatedIpCount.done();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c11dbad9/engine/schema/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java b/engine/schema/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java
new file mode 100644
index 0000000..7fe9467
--- /dev/null
+++ b/engine/schema/src/com/cloud/dc/dao/DataCenterLinkLocalIpAddressDao.java
@@ -0,0 +1,32 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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.cloud.dc.dao;
+
+import java.util.List;
+
+import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
+import com.cloud.utils.db.GenericDao;
+
+public interface DataCenterLinkLocalIpAddressDao extends GenericDao<DataCenterLinkLocalIpAddressVO, Long>{
+ public DataCenterLinkLocalIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId);
+ public boolean deleteIpAddressByPod(long podId);
+ public void addIpRange(long dcId, long podId, String start, String end);
+ public void releaseIpAddress(String ipAddress, long dcId, long instanceId);
+ public void releaseIpAddress(long nicId, String reservationId);
+ public List<DataCenterLinkLocalIpAddressVO> listByPodIdDcId(long podId, long dcId);
+ public int countIPs(long podId, long dcId, boolean onlyCountAllocated);
+}