Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 9 additions & 8 deletions compute/src/main/java/org/zstack/compute/VmNicUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.zstack.core.Platform.argerr;
import static org.zstack.header.vm.VmInstanceConstant.VM_NIC_QOS_MAX;
import static org.zstack.header.vm.VmInstanceConstant.VM_NIC_QOS_MIN;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

public class VmNicUtils {
public static void validateVmParms(List<VmNicParam> vmNicParms, List<String> l3Uuids, List<String> supportNicDriverTypes) {
Expand All @@ -22,45 +23,45 @@ public static void validateVmParms(List<VmNicParam> vmNicParms, List<String> l3U

List<String> l3UuidsInParms = vmNicParms.stream().map(VmNicParam::getL3NetworkUuid).distinct().collect(Collectors.toList());
if (l3UuidsInParms.size() != vmNicParms.size()) {
throw new ApiMessageInterceptionException(argerr("duplicate nic params"));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10000, "duplicate nic params"));
}

for (VmNicParam nic : vmNicParms) {
String l3 = nic.getL3NetworkUuid();
if (StringUtils.isEmpty(l3)) {
throw new ApiMessageInterceptionException(argerr("l3NetworkUuid of vm nic can not be null"));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10001, "l3NetworkUuid of vm nic can not be null"));
}
if (!CollectionUtils.isEmpty(l3Uuids) && !l3Uuids.contains(nic.getL3NetworkUuid())) {
throw new ApiMessageInterceptionException(argerr("l3NetworkUuid of vm nic is not in l3[%s]", l3Uuids));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10002, "l3NetworkUuid of vm nic is not in l3[%s]", l3Uuids));
}

if (nic.getOutboundBandwidth() != null) {
if (nic.getOutboundBandwidth() < VM_NIC_QOS_MIN || nic.getOutboundBandwidth() > VM_NIC_QOS_MAX) {
throw new ApiMessageInterceptionException(argerr("outbound bandwidth[%d] of vm nic is out of [8192, 32212254720]", nic.getOutboundBandwidth()));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10003, "outbound bandwidth[%d] of vm nic is out of [8192, 32212254720]", nic.getOutboundBandwidth()));
}
}

if (nic.getInboundBandwidth() != null) {
if (nic.getInboundBandwidth() < VM_NIC_QOS_MIN || nic.getInboundBandwidth() > VM_NIC_QOS_MAX) {
throw new ApiMessageInterceptionException(argerr("inbound bandwidth[%d] of vm nic is out of [8192, 32212254720]", nic.getInboundBandwidth()));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10004, "inbound bandwidth[%d] of vm nic is out of [8192, 32212254720]", nic.getInboundBandwidth()));
}
}

if (nic.getMultiQueueNum() != null ) {
if (nic.getMultiQueueNum() < 1 || nic.getMultiQueueNum() > 256) {
throw new ApiMessageInterceptionException(argerr("multi queue num[%d] of vm nic is out of [1,256]", nic.getMultiQueueNum()));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10005, "multi queue num[%d] of vm nic is out of [1,256]", nic.getMultiQueueNum()));
}
}

if (nic.getState() != null) {
if (!asList(VmNicState.enable.toString(), VmNicState.disable.toString()).contains(nic.getState())) {
throw new ApiMessageInterceptionException(argerr("vm nic of l3[uuid:%s] state[%s] is not %s or %s ", nic.getL3NetworkUuid(), nic.getState(), VmNicState.enable.toString(), VmNicState.disable.toString()));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10006, "vm nic of l3[uuid:%s] state[%s] is not %s or %s ", nic.getL3NetworkUuid(), nic.getState(), VmNicState.enable.toString(), VmNicState.disable.toString()));
}
}

String driverType = nic.getDriverType();
if (!StringUtils.isEmpty(driverType) && !CollectionUtils.isEmpty(supportNicDriverTypes) && !supportNicDriverTypes.contains(driverType)){
throw new ApiMessageInterceptionException(argerr("vm nic driver %s not support yet", driverType));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_10007, "vm nic driver %s not support yet", driverType));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.zstack.utils.logging.CLogger;
import org.zstack.utils.Utils;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;


@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
Expand Down Expand Up @@ -172,7 +173,7 @@ public void allocate() {
}

if (candidates.isEmpty()) {
fail(Platform.operr("no host found in clusters that has attached to L2Networks which have L3Networks%s", spec.getL3NetworkUuids()));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10036, "no host found in clusters that has attached to L2Networks which have L3Networks%s", spec.getL3NetworkUuids()));
} else {
next(candidates);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.persistence.TypedQuery;
import java.util.List;
import java.util.Set;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class AttachedPrimaryStorageAllocatorFlow extends AbstractHostAllocatorFlow {
private static final CLogger logger = Utils.getLogger(AttachedPrimaryStorageAllocatorFlow.class);
Expand Down Expand Up @@ -76,7 +77,7 @@ public String call(VolumeInventory arg) {
candidates = allocate(psuuids, vm);

if (candidates.isEmpty()) {
fail(Platform.operr("no host found in clusters that have attached to primary storage %s", psuuids));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10023, "no host found in clusters that have attached to primary storage %s", psuuids));
} else {
next(candidates);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.zstack.utils.function.Function;

import java.util.*;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

/**
*/
Expand All @@ -38,7 +39,7 @@ public void allocate() {

VmInstanceInventory vm = spec.getVmInstance();
if (vm.getRootVolume() == null || !VolumeStatus.Ready.toString().equals(vm.getRootVolume().getStatus())) {
fail(Platform.operr("cannot find root volume of vm[uuid:%s]", vm.getUuid()));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10031, "cannot find root volume of vm[uuid:%s]", vm.getUuid()));
}

List<String> requiredPsUuids = CollectionUtils.transformToList(vm.getAllVolumes(), new Function<String, VolumeInventory>() {
Expand Down Expand Up @@ -81,7 +82,7 @@ public String call(VolumeInventory arg) {
}

if (candidates.isEmpty()) {
fail(Platform.operr("no host found in clusters which have attached to all primary storage %s where vm[uuid:%s]'s volumes locate",
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10032, "no host found in clusters which have attached to all primary storage %s where vm[uuid:%s]'s volumes locate",
requiredPsUuids, vm.getUuid()));
} else {
next(candidates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.zstack.utils.function.Function;

import java.util.List;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class AvoidHostAllocatorFlow extends AbstractHostAllocatorFlow {
Expand All @@ -27,7 +28,7 @@ public HostVO call(HostVO arg) {
});

if (ret.isEmpty()) {
fail(Platform.operr("after rule out avoided host%s, there is no host left in candidates", spec.getAvoidHostUuids()));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10035, "after rule out avoided host%s, there is no host left in candidates", spec.getAvoidHostUuids()));
} else {
next(ret);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.zstack.core.Platform.inerr;
import static org.zstack.core.Platform.operr;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

/**
* Created by xing5 on 2016/8/17.
Expand Down Expand Up @@ -59,7 +60,7 @@ public void allocate() {
List<String> possiblePrimaryStorageTypes = spec.getBackupStoragePrimaryStorageMetrics().get(type);
if (possiblePrimaryStorageTypes == null) {
throw new OperationFailureException(inerr(
"the image[uuid:%s] is on the backup storage[uuid:%s, type:%s] that doesn't have metrics defined" +
ORG_ZSTACK_COMPUTE_ALLOCATOR_10015, "the image[uuid:%s] is on the backup storage[uuid:%s, type:%s] that doesn't have metrics defined" +
" in conf/springConfigXml/HostAllocatorManager.xml. The developer should add its primary storage metrics",
spec.getImage().getUuid(), spec.getRequiredBackupStorageUuid(), type
));
Expand All @@ -69,7 +70,7 @@ public void allocate() {
if (result.isEmpty()) {
String name = spec.getImage().getName();
throw new OperationFailureException(operr(
"The image[uuid:%s, name:%s] is on the backup storage[uuid:%s, type:%s] that requires to work with primary storage[types:%s]," +
ORG_ZSTACK_COMPUTE_ALLOCATOR_10016, "The image[uuid:%s, name:%s] is on the backup storage[uuid:%s, type:%s] that requires to work with primary storage[types:%s]," +
"however, no host found suitable to work with those primary storage", spec.getImage().getUuid(), name,
spec.getRequiredBackupStorageUuid(),spec.getImage().getType(), possiblePrimaryStorageTypes
));
Expand All @@ -78,13 +79,13 @@ public void allocate() {
result = findHostsByPrimaryStorageUuids(psUuids);
if (result.isEmpty()) {
throw new OperationFailureException(operr(
"The image[uuid:%s] is on the backup storage[uuid:%s, type:%s] that requires to work with primary storage[uuids:%s]," +
ORG_ZSTACK_COMPUTE_ALLOCATOR_10017, "The image[uuid:%s] is on the backup storage[uuid:%s, type:%s] that requires to work with primary storage[uuids:%s]," +
"however, no host found suitable to work with those primary storage", spec.getImage().getUuid(),
spec.getRequiredBackupStorageUuid(), type, psUuids)
);
}
} else {
throw new OperationFailureException(operr("the backup storage[uuid:%s, type:%s] requires bound" +
throw new OperationFailureException(operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10018, "the backup storage[uuid:%s, type:%s] requires bound" +
" primary storage, however, the primary storage has not been added", spec.getRequiredBackupStorageUuid(), bsType));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.persistence.TypedQuery;
import java.util.ArrayList;
import java.util.List;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class DesignatedHostAllocatorFlow extends AbstractHostAllocatorFlow {
private static final CLogger logger = Utils.getLogger(DesignatedHostAllocatorFlow.class);
Expand Down Expand Up @@ -105,7 +106,7 @@ public void allocate() {
if (spec.getHypervisorType() != null) {
args.append(String.format("hypervisorType=%s", spec.getHypervisorType())).append(" ");
}
fail(Platform.operr("No host with %s found", args));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10007, "No host with %s found", args));
} else {
next(candidates);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.zstack.header.errorcode.OperationFailureException;
import org.zstack.utils.Utils;
import org.zstack.utils.logging.CLogger;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

/**
* Created by frank on 7/2/2015.
Expand All @@ -33,7 +34,7 @@ public void allocate() {
logger.debug(String.format("after being filtered by HostAllocatorFilterExtensionPoint[%s], candidates num: %s", filter.getClass(), candidates.size()));

if (candidates.isEmpty()) {
fail(Platform.operr("after filtering, HostAllocatorFilterExtensionPoint[%s] returns zero candidate host, it means: %s", filter.getClass().getSimpleName(), filter.filterErrorReason()));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10008, "after filtering, HostAllocatorFilterExtensionPoint[%s] returns zero candidate host, it means: %s", filter.getClass().getSimpleName(), filter.filterErrorReason()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.zstack.core.Platform.argerr;

import java.util.List;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

/**
* Created with IntelliJ IDEA.
Expand Down Expand Up @@ -54,7 +55,7 @@ public APIMessage intercept(APIMessage msg) throws ApiMessageInterceptionExcepti
private void validate(APIGetCandidateBackupStorageForCreatingImageMsg msg) {
if (msg.getVolumeSnapshotUuid() == null && msg.getVolumeUuid() == null) {
throw new ApiMessageInterceptionException(argerr(
"either volumeUuid or volumeSnapshotUuid must be set"
ORG_ZSTACK_COMPUTE_ALLOCATOR_10033, "either volumeUuid or volumeSnapshotUuid must be set"
));
}
}
Expand All @@ -72,7 +73,7 @@ private void validate(APIGetCpuMemoryCapacityMsg msg) {
}

if (!pass && !msg.isAll()) {
throw new ApiMessageInterceptionException(argerr("zoneUuids, clusterUuids, hostUuids must at least have one be none-empty list, or all is set to true"));
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10034, "zoneUuids, clusterUuids, hostUuids must at least have one be none-empty list, or all is set to true"));
}

if (msg.isAll() && (msg.getZoneUuids() == null || msg.getZoneUuids().isEmpty())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static org.zstack.core.Platform.err;
import static org.zstack.core.Platform.inerr;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

/**
*/
Expand Down Expand Up @@ -101,10 +102,10 @@ private void done() {
// in case a wrong flow returns an empty result set
if (result.isEmpty()) {
if (isDryRun) {
dryRunCompletion.fail(err(HostAllocatorError.NO_AVAILABLE_HOST,
dryRunCompletion.fail(err(ORG_ZSTACK_COMPUTE_ALLOCATOR_10026, HostAllocatorError.NO_AVAILABLE_HOST,
"host allocation flow doesn't indicate any details"));
} else {
completion.fail(err(HostAllocatorError.NO_AVAILABLE_HOST,
completion.fail(err(ORG_ZSTACK_COMPUTE_ALLOCATOR_10027, HostAllocatorError.NO_AVAILABLE_HOST,
"host allocation flow doesn't indicate any details"));
}
return;
Expand Down Expand Up @@ -145,7 +146,7 @@ private void runFlow(AbstractHostAllocatorFlow flow) {
}
} catch (Throwable t) {
logger.warn("unhandled throwable", t);
completion.fail(inerr(t.toString()));
completion.fail(inerr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10028, t.toString()));
}
}

Expand Down Expand Up @@ -228,7 +229,7 @@ public void fail(ErrorCode errorCode) {
lastFlow.getClass().getName(), errorCode.getDetails()));
this.errorCode = errorCode;
} else {
this.errorCode = err(HostAllocatorError.NO_AVAILABLE_HOST, seriesErrorWhenPagination.iterator().next(), "unable to allocate hosts; due to pagination is enabled, " +
this.errorCode = err(ORG_ZSTACK_COMPUTE_ALLOCATOR_10029, HostAllocatorError.NO_AVAILABLE_HOST, seriesErrorWhenPagination.iterator().next(), "unable to allocate hosts; due to pagination is enabled, " +
"there might be several allocation failures happened before;" +
" the error list is %s", seriesErrorWhenPagination.stream().map(ErrorCode::getDetails).collect(Collectors.toList()));
logger.debug(this.errorCode.getDetails());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

import static org.zstack.core.Platform.operr;
import static org.zstack.utils.CollectionDSL.list;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

public class HostAllocatorManagerImpl extends AbstractService implements HostAllocatorManager, VmAbnormalLifeCycleExtensionPoint {
private static final CLogger logger = Utils.getLogger(HostAllocatorManagerImpl.class);
Expand Down Expand Up @@ -945,7 +946,7 @@ public void run() {

trigger.next();
} catch (UnableToReserveHostCapacityException e) {
trigger.fail(operr(e.getMessage()));
trigger.fail(operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10021, e.getMessage()));
}
}

Expand All @@ -968,7 +969,7 @@ public void run() {

trigger.next();
} catch (UnableToReserveHostCapacityException e) {
trigger.fail(operr(e.getMessage()));
trigger.fail(operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10022, e.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.List;
import java.util.stream.Collectors;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class HostCapacityAllocatorFlow extends AbstractHostAllocatorFlow {
Expand Down Expand Up @@ -62,7 +63,7 @@ public void allocate() {
ret = reserveMgr.filterOutHostsByReservedCapacity(ret, spec.getCpuCapacity(), spec.getMemoryCapacity());

if (ret.isEmpty()) {
fail(Platform.operr("no host having cpu[%s], memory[%s bytes] found",
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10030, "no host having cpu[%s], memory[%s bytes] found",
spec.getCpuCapacity(), spec.getMemoryCapacity()));
} else {
next(ret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.stream.Collectors;

import static org.zstack.utils.CollectionUtils.*;
import static org.zstack.utils.clouderrorcode.CloudOperationsErrorCode.*;

/**
* Filter out hosts that do not match the operating system of the specific host
Expand Down Expand Up @@ -69,7 +70,7 @@ public void allocate() {
.collect(Collectors.toList());

if (matchedHosts.isEmpty()) {
fail(Platform.operr("no candidate host has version[%s]", currentHostOs));
fail(Platform.operr(ORG_ZSTACK_COMPUTE_ALLOCATOR_10009, "no candidate host has version[%s]", currentHostOs));
} else {
next(matchedHosts);
}
Expand Down
Loading