mirror of https://github.com/apache/cloudstack.git
Fix travis failures by removing dependency of vmware from storage.
Added a new command class to verify the vCenter details provided while adding primary storage
This commit is contained in:
parent
19745ea049
commit
40934ba9ff
|
|
@ -0,0 +1,40 @@
|
|||
// 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.agent.api;
|
||||
|
||||
public class ValidateVcenterDetailsCommand extends Command {
|
||||
|
||||
String vCenterServerAddress;
|
||||
|
||||
public ValidateVcenterDetailsCommand(String vCenterServerAddress) {
|
||||
this.vCenterServerAddress = vCenterServerAddress;
|
||||
}
|
||||
|
||||
public String getvCenterServerAddress() {
|
||||
return vCenterServerAddress;
|
||||
}
|
||||
|
||||
public void setvCenterServerAddress(String vCenterServerAddress) {
|
||||
this.vCenterServerAddress = vCenterServerAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
// under the License.
|
||||
package com.cloud.hypervisor.vmware.resource;
|
||||
|
||||
import com.cloud.agent.api.ValidateVcenterDetailsCommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.storage.configdrive.ConfigDrive;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
|
|
@ -569,6 +570,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
answer = execute((GetUnmanagedInstancesCommand) cmd);
|
||||
} else if (clz == PrepareUnmanageVMInstanceCommand.class) {
|
||||
answer = execute((PrepareUnmanageVMInstanceCommand) cmd);
|
||||
} else if (clz == ValidateVcenterDetailsCommand.class) {
|
||||
answer = execute((ValidateVcenterDetailsCommand) cmd);
|
||||
} else {
|
||||
answer = Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
|
|
@ -7261,4 +7264,18 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||
|
||||
return new PrepareUnmanageVMInstanceAnswer(cmd, true, "OK");
|
||||
}
|
||||
|
||||
private Answer execute(ValidateVcenterDetailsCommand cmd) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Executing resource ValidateVcenterDetailsCommand " + _gson.toJson(cmd));
|
||||
}
|
||||
String vCenterServerAddress = cmd.getvCenterServerAddress();
|
||||
VmwareContext context = getServiceContext();
|
||||
|
||||
if (vCenterServerAddress.equals(context.getServerAddress())) {
|
||||
return new Answer(cmd, true, "success");
|
||||
} else {
|
||||
return new Answer(cmd, false, "Provided vCenter server address is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,12 +33,6 @@
|
|||
<artifactId>cloud-engine-storage-volume</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-plugin-hypervisor-vmware</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.cloud.agent.api.Answer;
|
|||
import com.cloud.agent.api.CreateStoragePoolCommand;
|
||||
import com.cloud.agent.api.DeleteStoragePoolCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.ValidateVcenterDetailsCommand;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.StorageConflictException;
|
||||
|
|
@ -30,10 +31,6 @@ import com.cloud.host.Host;
|
|||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.vmware.VmwareDatacenterVO;
|
||||
import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMapVO;
|
||||
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterDao;
|
||||
import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.storage.OCFS2Manager;
|
||||
|
|
@ -126,10 +123,6 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
|
|||
StoragePoolAutomation storagePoolAutmation;
|
||||
@Inject
|
||||
protected HostDao _hostDao;
|
||||
@Inject
|
||||
private VmwareDatacenterZoneMapDao vmwareDatacenterZoneMapDao;
|
||||
@Inject
|
||||
private VmwareDatacenterDao vmwareDcDao;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
|
@ -258,7 +251,7 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
|
|||
parameters.setUserInfo(userInfo);
|
||||
} else if (scheme.equalsIgnoreCase("PreSetup")) {
|
||||
if (StringUtils.isNotBlank(hypervisorType) && HypervisorType.getType(hypervisorType).equals(HypervisorType.VMware)) {
|
||||
validateVcenterDetails(zoneId, storageHost);
|
||||
validateVcenterDetails(zoneId, podId, clusterId,storageHost);
|
||||
}
|
||||
parameters.setType(StoragePoolType.PreSetup);
|
||||
parameters.setHost(storageHost);
|
||||
|
|
@ -266,7 +259,7 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
|
|||
parameters.setPath(hostPath);
|
||||
} else if (scheme.equalsIgnoreCase("DatastoreCluster")) {
|
||||
if (StringUtils.isNotBlank(hypervisorType) && HypervisorType.getType(hypervisorType).equals(HypervisorType.VMware)) {
|
||||
validateVcenterDetails(zoneId, storageHost);
|
||||
validateVcenterDetails(zoneId, podId, clusterId,storageHost);
|
||||
}
|
||||
parameters.setType(StoragePoolType.DatastoreCluster);
|
||||
parameters.setHost(storageHost);
|
||||
|
|
@ -371,15 +364,31 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
|
|||
return dataStoreHelper.createPrimaryDataStore(parameters);
|
||||
}
|
||||
|
||||
private void validateVcenterDetails(long zoneId, String storageHost) {
|
||||
VmwareDatacenterZoneMapVO vmwareDcZoneMap = vmwareDatacenterZoneMapDao.findByZoneId(zoneId);
|
||||
if (vmwareDcZoneMap != null) {
|
||||
Long associatedVmwareDcId = vmwareDcZoneMap.getVmwareDcId();
|
||||
VmwareDatacenterVO associatedVmwareDc = vmwareDcDao.findById(associatedVmwareDcId);
|
||||
if (!associatedVmwareDc.getVcenterHost().equals(storageHost)) {
|
||||
throw new InvalidParameterValueException("Provided vCenter server details does not match with the existing vCenter in zone id: " + zoneId);
|
||||
private void validateVcenterDetails(Long zoneId, Long podId, Long clusterId, String storageHost) {
|
||||
|
||||
List<HostVO> allHosts =
|
||||
_resourceMgr.listAllUpHosts(Host.Type.Routing, clusterId, podId, zoneId);
|
||||
if (allHosts.isEmpty()) {
|
||||
throw new CloudRuntimeException("No host up to associate a storage pool with in zone: " + zoneId + " pod: " + podId + " cluster: " + clusterId);
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
for (HostVO h : allHosts) {
|
||||
ValidateVcenterDetailsCommand cmd = new ValidateVcenterDetailsCommand(storageHost);
|
||||
final Answer answer = agentMgr.easySend(h.getId(), cmd);
|
||||
if (answer != null && answer.getResult()) {
|
||||
s_logger.info("Successfully validated vCenter details provided");
|
||||
return;
|
||||
} else {
|
||||
if (answer != null) {
|
||||
throw new InvalidParameterValueException("Provided vCenter server details does not match with the existing vCenter in zone id: " + zoneId);
|
||||
} else {
|
||||
String msg = "Can not validate vCenter through host " + h.getId() + " due to ValidateVcenterDetailsCommand returns null";
|
||||
s_logger.warn(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new CloudRuntimeException("Could not validate vCenter details through any of the hosts with in zone: " + zoneId + ", pod: " + podId + ", cluster: " + clusterId);
|
||||
}
|
||||
|
||||
protected boolean createStoragePool(long hostId, StoragePool pool) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue