Added check for legacy zones. Improved log statements.

Signed-off-by: Sateesh Chodapuneedi <sateesh@apache.org>
This commit is contained in:
Sateesh Chodapuneedi 2013-05-31 13:11:12 +05:30
parent 4b67b1d36a
commit 55b3e69733
9 changed files with 238 additions and 4 deletions

View File

@ -79,6 +79,7 @@
<bean id="vmwareContextFactory" class="com.cloud.hypervisor.vmware.resource.VmwareContextFactory" />
<bean id="VmwareDatacenterDaoImpl" class="com.cloud.hypervisor.vmware.dao.VmwareDatacenterDaoImpl" />
<bean id="VmwareDatacenterZoneMapDaoImpl" class="com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDaoImpl" />
<bean id="LegacyZoneDaoImpl" class="com.cloud.hypervisor.vmware.dao.LegacyZoneDaoImpl" />
<!--
Nicira support components

View File

@ -0,0 +1,28 @@
//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;
public interface LegacyZone extends InternalIdentity {
long getId();
long getZoneId();
}

View File

@ -0,0 +1,81 @@
//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;
import com.cloud.utils.NumbersUtil;
/**
* LegacyZoneVO contains id of CloudStack zone containing clusters from multiple VMware vCetners and/or VMware Datacenters.
*/
@Entity
@Table(name="legacy_zones")
public class LegacyZoneVO implements LegacyZone {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "zone_id")
private long zoneId;
@Override
public long getId() {
return id;
}
@Override
public long getZoneId() {
return zoneId;
}
@Override
public int hashCode() {
return NumbersUtil.hash(id);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof LegacyZoneVO) {
return ((LegacyZoneVO)obj).getId() == this.getId();
} else {
return false;
}
}
public LegacyZoneVO() {
}
public LegacyZoneVO(long zoneId) {
this.id = zoneId;
}
public LegacyZoneVO(long id, long zoneId) {
this.id = id;
this.zoneId = zoneId;
}
}

View File

@ -149,7 +149,7 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
}
Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
boolean legacyZone = false;
boolean legacyZone = _vmwareMgr.isLegacyZone(dcId);
//Check if NOT a legacy zone.
if (!legacyZone) {
String updatedInventoryPath = validateCluster(dcId, url, username, password);
@ -455,15 +455,15 @@ public class VmwareServerDiscoverer extends DiscovererBase implements
if (!vCenterHost.equalsIgnoreCase(url.getHost())) {
msg = "This cluster " + clusterName + " belongs to vCenter " + url.getHost()
+ " .But this zone is associated with VMware DC from vCenter " + vCenterHost
+ ". But this zone is associated with VMware DC from vCenter " + vCenterHost
+ ". Make sure the cluster being added belongs to vCenter " + vCenterHost
+ " and DC " + vmwareDcNameFromDb;
+ " and VMware DC " + vmwareDcNameFromDb;
s_logger.error(msg);
throw new DiscoveryException(msg);
} else if (!vmwareDcNameFromDb.equalsIgnoreCase(vmwareDcNameFromApi)) {
msg = "This cluster " + clusterName + " belongs to VMware DC " + vmwareDcNameFromApi
+ " .But this zone is associated with VMware DC " + vmwareDcNameFromDb
+ ". Make sure the cluster being added belongs to DC " + vmwareDcNameFromDb
+ ". Make sure the cluster being added belongs to VMware DC " + vmwareDcNameFromDb
+ " in vCenter " + vCenterHost;
s_logger.error(msg);
throw new DiscoveryException(msg);

View File

@ -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.hypervisor.vmware.dao;
import java.util.List;
import com.cloud.hypervisor.vmware.LegacyZoneVO;
import com.cloud.utils.db.GenericDao;
public interface LegacyZoneDao extends GenericDao<LegacyZoneVO, Long> {
/**
* @param id of zone
* @return zone id of legacy zone
*/
LegacyZoneVO findByZoneId(String zoneId);
/**
* Lists all legacy CloudStack zones
* @return list of ids of legacy CloudStack zones
*/
List<LegacyZoneVO> listAllLegacyZones();
}

View File

@ -0,0 +1,66 @@
// 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.LegacyZoneVO;
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=LegacyZoneDao.class) @DB(txn=false)
public class LegacyZoneDaoImpl extends GenericDaoBase<LegacyZoneVO, Long> implements LegacyZoneDao {
protected static final Logger s_logger = Logger.getLogger(LegacyZoneDaoImpl.class);
final SearchBuilder<LegacyZoneVO> zoneSearch;
final SearchBuilder<LegacyZoneVO> fullTableSearch;
public LegacyZoneDaoImpl() {
super();
zoneSearch = createSearchBuilder();
zoneSearch.and("zoneId", zoneSearch.entity().getZoneId(), Op.EQ);
zoneSearch.done();
fullTableSearch = createSearchBuilder();
fullTableSearch.done();
}
@Override
public LegacyZoneVO findByZoneId(String zoneId) {
SearchCriteria<LegacyZoneVO> sc = zoneSearch.create();
sc.setParameters("zoneId", zoneId);
return findOneBy(sc);
}
@Override
public List<LegacyZoneVO> listAllLegacyZones() {
SearchCriteria<LegacyZoneVO> sc = fullTableSearch.create();
return search(sc, null);
}
}

View File

@ -66,4 +66,6 @@ public interface VmwareManager {
String getPrivateVSwitchName(long dcId, HypervisorType hypervisorType);
public String getRootDiskController();
boolean isLegacyZone(long dcId);
}

View File

@ -67,10 +67,12 @@ import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
import com.cloud.hypervisor.vmware.LegacyZoneVO;
import com.cloud.hypervisor.vmware.VmwareCleanupMaid;
import com.cloud.hypervisor.vmware.VmwareDatacenterService;
import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;
import com.cloud.hypervisor.vmware.dao.LegacyZoneDao;
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
import com.cloud.hypervisor.vmware.mo.CustomFieldConstants;
@ -147,6 +149,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
@Inject DataCenterDao _dcDao;
@Inject VmwareDatacenterDao _vmwareDcDao;
@Inject VmwareDatacenterZoneMapDao _vmwareDcZoneMapDao;
@Inject LegacyZoneDao _legacyZoneDao;
String _mountParent;
StorageLayer _storage;
@ -1143,4 +1146,14 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
}
return uri;
}
@Override
public boolean isLegacyZone(long dcId) {
boolean isLegacyZone = false;
LegacyZoneVO legacyZoneVo = _legacyZoneDao.findById(dcId);
if (legacyZoneVo != null) {
isLegacyZone = true;
}
return isLegacyZone;
}
}

View File

@ -73,6 +73,7 @@ import com.cloud.exception.ResourceInUseException;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
import com.cloud.hypervisor.vmware.dao.LegacyZoneDao;
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
import com.cloud.hypervisor.vmware.manager.VmwareManager;
@ -370,6 +371,11 @@ public class VmwareDatacenterApiUnitTest {
return Mockito.mock(ClusterVSMMapDao.class);
}
@Bean
public LegacyZoneDao legacyZoneDao() {
return Mockito.mock(LegacyZoneDao.class);
}
@Bean
public ConfigurationDao configurationDao() {
return Mockito.mock(ConfigurationDao.class);