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 <sateesh@apache.org>
This commit is contained in:
Sateesh Chodapuneedi 2013-05-23 12:28:17 +05:30
parent 99e9f5d308
commit 6cd87d2e21
8 changed files with 569 additions and 0 deletions

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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<VmwareDatacenterVO, Long> {
/**
* 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<VmwareDatacenterVO> 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<VmwareDatacenterVO> 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<VmwareDatacenterVO> listVmwareDatacenterByVcenter(String vCenterHost);
/**
* Lists all associated VMware datacenter on the management server.
* @return list of VmwareDatacenterVO for all associated VMware datacenters
*/
List<VmwareDatacenterVO> listAllVmwareDatacenters();
}

View File

@ -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<VmwareDatacenterVO, Long> implements VmwareDatacenterDao {
protected static final Logger s_logger = Logger.getLogger(VmwareDatacenterDaoImpl.class);
final SearchBuilder<VmwareDatacenterVO> nameSearch;
final SearchBuilder<VmwareDatacenterVO> guidSearch;
final SearchBuilder<VmwareDatacenterVO> vcSearch;
final SearchBuilder<VmwareDatacenterVO> nameVcSearch;
final SearchBuilder<VmwareDatacenterVO> 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<VmwareDatacenterVO> sc = guidSearch.create();
sc.setParameters("guid", guid);
return findOneBy(sc);
}
@Override
public List<VmwareDatacenterVO> getVmwareDatacenterByNameAndVcenter(String name, String vCenterHost) {
SearchCriteria<VmwareDatacenterVO> sc = guidSearch.create();
sc.setParameters("name", name);
sc.setParameters("vCenterHost", vCenterHost);
return search(sc, null);
}
@Override
public List<VmwareDatacenterVO> listVmwareDatacenterByName(String name) {
SearchCriteria<VmwareDatacenterVO> sc = guidSearch.create();
sc.setParameters("name", name);
return search(sc, null);
}
@Override
public List<VmwareDatacenterVO> listVmwareDatacenterByVcenter(String vCenterHost) {
SearchCriteria<VmwareDatacenterVO> sc = vcSearch.create();
sc.setParameters("vCenterHost", vCenterHost);
return search(sc, null);
}
@Override
public List<VmwareDatacenterVO> listAllVmwareDatacenters() {
SearchCriteria<VmwareDatacenterVO> sc = fullTableSearch.create();
return search(sc, null);
}
}

View File

@ -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<VmwareDatacenterZoneMapVO, Long> {
/**
* @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);
}

View File

@ -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<VmwareDatacenterZoneMapVO, Long>
implements VmwareDatacenterZoneMapDao {
protected final SearchBuilder<VmwareDatacenterZoneMapVO> zoneSearch;
protected final SearchBuilder<VmwareDatacenterZoneMapVO> 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<VmwareDatacenterZoneMapVO> sc = zoneSearch.create();
sc.setParameters("zoneId", zoneId);
return findOneBy(sc);
}
@Override
public VmwareDatacenterZoneMapVO findByVmwareDcId(long vmwareDcId) {
SearchCriteria<VmwareDatacenterZoneMapVO> sc = vmwareDcSearch.create();
sc.setParameters("vmwareDcId", vmwareDcId);
return findOneBy(sc);
}
}