From 6cd87d2e21f9bd9972d715138676d2d2e2afdd7c Mon Sep 17 00:00:00 2001 From: Sateesh Chodapuneedi Date: Thu, 23 May 2013 12:28:17 +0530 Subject: [PATCH] CLOUDSTACK-1963 New mapping model for CloudStack zone and Vmware datacenter Support for DB changes for Vmware datacenter objects Support for DB changes to store mapping with CloudStack zones. Signed-off-by: Sateesh Chodapuneedi --- .../hypervisor/vmware/VmwareDatacenter.java | 36 ++++ .../hypervisor/vmware/VmwareDatacenterVO.java | 160 ++++++++++++++++++ .../vmware/VmwareDatacenterZoneMap.java | 30 ++++ .../vmware/VmwareDatacenterZoneMapVO.java | 78 +++++++++ .../vmware/dao/VmwareDatacenterDao.java | 65 +++++++ .../vmware/dao/VmwareDatacenterDaoImpl.java | 104 ++++++++++++ .../dao/VmwareDatacenterZoneMapDao.java | 35 ++++ .../dao/VmwareDatacenterZoneMapDaoImpl.java | 61 +++++++ 8 files changed, 569 insertions(+) create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java create mode 100644 plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java new file mode 100644 index 00000000000..6d6d2ebf0eb --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenter.java @@ -0,0 +1,36 @@ +// 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.hypervisor.vmware; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface VmwareDatacenter extends Identity, InternalIdentity { + + String getVmwareDatacenterName(); + + String getGuid(); + + String getVcenterHost(); + + long getId(); + + String getPassword(); + + String getUser(); +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java new file mode 100644 index 00000000000..a13e59e5cb4 --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterVO.java @@ -0,0 +1,160 @@ +// 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.hypervisor.vmware; + +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.Table; + +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.db.Encrypt; + +/** + * VmwareDatacenterVO contains information of Vmware Datacenter associated with a CloudStack zone. + */ + +@Entity +@Table(name="vmware_data_center") +public class VmwareDatacenterVO implements VmwareDatacenter { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "guid") + private String guid; + + @Column(name = "name") + private String name; + + @Column(name = "vcenter_host") + private String vCenterHost; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "username") + private String user; + + @Encrypt + @Column(name = "password") + private String password; + + @Override + public String getUuid() { + return uuid; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getVmwareDatacenterName() { + return name; + } + + @Override + public String getGuid() { + return guid; + } + + @Override + public String getUser() { + return user; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getVcenterHost() { + return vCenterHost; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setGuid(String guid) { + this.guid = guid; + } + + public void setVmwareDatacenterName(String name) { + this.name = name; + } + + public void setVcenterHost(String vCenterHost) { + this.vCenterHost = vCenterHost; + } + + public void setUser(String user) { + this.user = user; ; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String toString() { + return new StringBuilder("VmwareDatacenter[").append(guid).append("]").toString(); + } + + @Override + public int hashCode() { + return NumbersUtil.hash(id); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof VmwareDatacenterVO) { + return ((VmwareDatacenterVO)obj).getId() == this.getId(); + } else { + return false; + } + } + + public VmwareDatacenterVO(String guid, String name, String vCenterHost, String user, String password) { + this.uuid = UUID.randomUUID().toString(); + this.name = name; + this.guid = guid; + this.vCenterHost = vCenterHost; + this.user = user; + this.password = password; + } + + public VmwareDatacenterVO(long id, String guid, String name, String vCenterHost, String user, String password) { + this(guid, name, vCenterHost, user, password); + this.id = id; + } + + public VmwareDatacenterVO() { + this.uuid = UUID.randomUUID().toString(); + } + +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.java new file mode 100644 index 00000000000..f70a5414de8 --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMap.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.hypervisor.vmware; + +import org.apache.cloudstack.api.InternalIdentity; + +import com.cloud.org.Grouping; + +public interface VmwareDatacenterZoneMap extends Grouping, InternalIdentity { + public long getId(); + + public long getZoneId(); + + public long getVmwareDcId(); +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java new file mode 100644 index 00000000000..93b0e2670cb --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareDatacenterZoneMapVO.java @@ -0,0 +1,78 @@ +//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.hypervisor.vmware; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + + +//NOTE: This particular table is totally internal to the CS MS. +//Do not ever include a uuid/guid field in this table. We just +//need it map zone ids with VMware datacenter Ids. + +@Entity +@Table(name="vmware_data_center_zone_map") +public class VmwareDatacenterZoneMapVO implements VmwareDatacenterZoneMap { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="id") + private long id; + + @Column(name="zone_id") + private long zoneId; + + @Column(name="vmware_data_center_id") + private long vmwareDcId; + + public VmwareDatacenterZoneMapVO(long zoneId, long vmwareDcId) { + this.zoneId = zoneId; + this.vmwareDcId = vmwareDcId; + } + + public VmwareDatacenterZoneMapVO() { + // Do nothing. + } + + @Override + public long getId() { + return id; + } + + @Override + public long getZoneId() { + return zoneId; + } + + @Override + public long getVmwareDcId() { + return vmwareDcId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + + public void setVmwareDcId(long vmwareDcId) { + this.vmwareDcId = vmwareDcId; + } +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java new file mode 100644 index 00000000000..2754e91d26c --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDao.java @@ -0,0 +1,65 @@ +// 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.hypervisor.vmware.dao; + +import java.util.List; + +import com.cloud.hypervisor.vmware.VmwareDatacenterVO; +import com.cloud.utils.db.GenericDao; + +public interface VmwareDatacenterDao extends GenericDao { + + /** + * Return a VMware Datacenter given guid + * @param guid of VMware datacenter + * @return VmwareDatacenterVO for the VMware datacenter having the specified guid. + */ + VmwareDatacenterVO getVmwareDatacenterByGuid(String guid); + + /** + * Return a VMware Datacenter given name and vCenter host. + * For legacy zones multiple records will be present in the table. + * @param name of VMware datacenter + * @param vCenter host + * @return VmwareDatacenterVO for the VMware datacenter with given name and + * belonging to specified vCenter host. + */ + List getVmwareDatacenterByNameAndVcenter(String name, String vCenterHost); + + /** + * Return a list of VMware Datacenter given name. + * @param name of Vmware datacenter + * @return list of VmwareDatacenterVO for VMware datacenters having the specified name. + */ + List listVmwareDatacenterByName(String name); + + /** + * Return a list of VMware Datacenters belonging to specified vCenter + * @param vCenter Host + * @return list of VmwareDatacenterVO for all VMware datacenters belonging to + * specified vCenter + */ + List listVmwareDatacenterByVcenter(String vCenterHost); + + /** + * Lists all associated VMware datacenter on the management server. + * @return list of VmwareDatacenterVO for all associated VMware datacenters + */ + List listAllVmwareDatacenters(); + +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java new file mode 100644 index 00000000000..8324e93409a --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterDaoImpl.java @@ -0,0 +1,104 @@ +// 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.hypervisor.vmware.dao; + +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.hypervisor.vmware.VmwareDatacenterVO; +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.SearchCriteria.Op; + +@Component +@Local(value=VmwareDatacenterDao.class) @DB(txn=false) +public class VmwareDatacenterDaoImpl extends GenericDaoBase implements VmwareDatacenterDao { + protected static final Logger s_logger = Logger.getLogger(VmwareDatacenterDaoImpl.class); + + final SearchBuilder nameSearch; + final SearchBuilder guidSearch; + final SearchBuilder vcSearch; + final SearchBuilder nameVcSearch; + final SearchBuilder fullTableSearch; + + public VmwareDatacenterDaoImpl() { + super(); + + nameSearch = createSearchBuilder(); + nameSearch.and("name", nameSearch.entity().getVmwareDatacenterName(), Op.EQ); + nameSearch.done(); + + nameVcSearch = createSearchBuilder(); + nameVcSearch.and("name", nameVcSearch.entity().getVmwareDatacenterName(), Op.EQ); + nameVcSearch.and("vCenterHost", nameVcSearch.entity().getVcenterHost(), Op.EQ); + nameVcSearch.done(); + + vcSearch = createSearchBuilder(); + vcSearch.and("vCenterHost", vcSearch.entity().getVcenterHost(), Op.EQ); + vcSearch.done(); + + guidSearch = createSearchBuilder(); + guidSearch.and("guid", guidSearch.entity().getGuid(), Op.EQ); + guidSearch.done(); + + fullTableSearch = createSearchBuilder(); + fullTableSearch.done(); + } + + @Override + public VmwareDatacenterVO getVmwareDatacenterByGuid(String guid) { + SearchCriteria sc = guidSearch.create(); + sc.setParameters("guid", guid); + return findOneBy(sc); + } + + @Override + public List getVmwareDatacenterByNameAndVcenter(String name, String vCenterHost) { + SearchCriteria sc = guidSearch.create(); + sc.setParameters("name", name); + sc.setParameters("vCenterHost", vCenterHost); + return search(sc, null); + } + + @Override + public List listVmwareDatacenterByName(String name) { + SearchCriteria sc = guidSearch.create(); + sc.setParameters("name", name); + return search(sc, null); + } + + @Override + public List listVmwareDatacenterByVcenter(String vCenterHost) { + SearchCriteria sc = vcSearch.create(); + sc.setParameters("vCenterHost", vCenterHost); + return search(sc, null); + } + + @Override + public List listAllVmwareDatacenters() { + SearchCriteria sc = fullTableSearch.create(); + return search(sc, null); + } + +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java new file mode 100644 index 00000000000..be693aaac0c --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDao.java @@ -0,0 +1,35 @@ +// 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.hypervisor.vmware.dao; + +import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO; +import com.cloud.utils.db.GenericDao; + +public interface VmwareDatacenterZoneMapDao extends GenericDao { + /** + * @param id of zone + * @return map object of VMware datacenter & zone + */ + VmwareDatacenterZoneMapVO findByZoneId(long zoneId); + + /** + * @param id of VMware datacenter + * @return map object of VMware datacenter & zone + */ + VmwareDatacenterZoneMapVO findByVmwareDcId(long vmwareDcId); +} diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java new file mode 100644 index 00000000000..1c1326954c9 --- /dev/null +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/dao/VmwareDatacenterZoneMapDaoImpl.java @@ -0,0 +1,61 @@ +//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.hypervisor.vmware.dao; + +import javax.ejb.Local; + +import org.springframework.stereotype.Component; + +import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; + +@Component +@Local(value=VmwareDatacenterZoneMapDao.class) +public class VmwareDatacenterZoneMapDaoImpl extends GenericDaoBase + implements VmwareDatacenterZoneMapDao { + + protected final SearchBuilder zoneSearch; + protected final SearchBuilder vmwareDcSearch; + + public VmwareDatacenterZoneMapDaoImpl() { + zoneSearch = createSearchBuilder(); + zoneSearch.and("zoneId", zoneSearch.entity().getZoneId(), Op.EQ); + zoneSearch.done(); + + vmwareDcSearch = createSearchBuilder(); + vmwareDcSearch.and("vmwareDcId", vmwareDcSearch.entity().getVmwareDcId(), Op.EQ); + vmwareDcSearch.done(); + } + + @Override + public VmwareDatacenterZoneMapVO findByZoneId(long zoneId) { + SearchCriteria sc = zoneSearch.create(); + sc.setParameters("zoneId", zoneId); + return findOneBy(sc); + } + + @Override + public VmwareDatacenterZoneMapVO findByVmwareDcId(long vmwareDcId) { + SearchCriteria sc = vmwareDcSearch.create(); + sc.setParameters("vmwareDcId", vmwareDcId); + return findOneBy(sc); + } +}