diff --git a/api/src/com/cloud/agent/api/to/S3TO.java b/api/src/com/cloud/agent/api/to/S3TO.java index 8a2f09dc5ab..b1b692a8bad 100644 --- a/api/src/com/cloud/agent/api/to/S3TO.java +++ b/api/src/com/cloud/agent/api/to/S3TO.java @@ -18,6 +18,8 @@ package com.cloud.agent.api.to; import java.util.Date; +import com.cloud.agent.api.LogLevel; +import com.cloud.agent.api.LogLevel.Log4jLevel; import com.cloud.storage.DataStoreRole; import com.cloud.utils.S3Utils; @@ -25,7 +27,9 @@ public final class S3TO implements S3Utils.ClientOptions, DataStoreTO { private Long id; private String uuid; + @LogLevel(Log4jLevel.Off) private String accessKey; + @LogLevel(Log4jLevel.Off) private String secretKey; private String endPoint; private String bucketName; @@ -68,10 +72,12 @@ public final class S3TO implements S3Utils.ClientOptions, DataStoreTO { @Override public boolean equals(final Object thatObject) { - if (this == thatObject) + if (this == thatObject) { return true; - if (thatObject == null || getClass() != thatObject.getClass()) + } + if (thatObject == null || getClass() != thatObject.getClass()) { return false; + } final S3TO thatS3TO = (S3TO) thatObject; diff --git a/api/src/com/cloud/agent/manager/allocator/HostAllocator.java b/api/src/com/cloud/agent/manager/allocator/HostAllocator.java index fcd1fc10072..14525aa52de 100755 --- a/api/src/com/cloud/agent/manager/allocator/HostAllocator.java +++ b/api/src/com/cloud/agent/manager/allocator/HostAllocator.java @@ -47,7 +47,7 @@ public interface HostAllocator extends Adapter { * @return List List of hosts that are suitable for VM allocation **/ - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo); + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo); /** * Determines which physical hosts are suitable to @@ -62,7 +62,7 @@ public interface HostAllocator extends Adapter { * @return List List of hosts that are suitable for VM allocation **/ - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity); + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity); /** * Determines which physical hosts are suitable to @@ -77,7 +77,7 @@ public interface HostAllocator extends Adapter { * @param boolean considerReservedCapacity (default should be true, set to false if host capacity calculation should not look at reserved capacity) * @return List List of hosts that are suitable for VM allocation **/ - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity); public static int RETURN_UPTO_ALL = -1; diff --git a/api/src/com/cloud/deploy/DeploymentClusterPlanner.java b/api/src/com/cloud/deploy/DeploymentClusterPlanner.java index 8b15ea56e8f..ca73267e732 100644 --- a/api/src/com/cloud/deploy/DeploymentClusterPlanner.java +++ b/api/src/com/cloud/deploy/DeploymentClusterPlanner.java @@ -18,9 +18,7 @@ package com.cloud.deploy; import java.util.List; -import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.exception.InsufficientServerCapacityException; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; /** @@ -38,10 +36,10 @@ public interface DeploymentClusterPlanner extends DeploymentPlanner { * avoid these data centers, pods, clusters, or hosts. * @return DeployDestination for that virtual machine. */ - List orderClusters(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) + List orderClusters(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException; - PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile, + PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException; } diff --git a/api/src/com/cloud/deploy/DeploymentPlanner.java b/api/src/com/cloud/deploy/DeploymentPlanner.java index 769da39f3ff..741a8048a0a 100644 --- a/api/src/com/cloud/deploy/DeploymentPlanner.java +++ b/api/src/com/cloud/deploy/DeploymentPlanner.java @@ -29,7 +29,6 @@ import com.cloud.host.Host; import com.cloud.org.Cluster; import com.cloud.storage.StoragePool; import com.cloud.utils.component.Adapter; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; /** @@ -48,7 +47,7 @@ public interface DeploymentPlanner extends Adapter { * @return DeployDestination for that virtual machine. */ @Deprecated - DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException; + DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException; /** * check() is called right before the virtual machine starts to make sure @@ -65,7 +64,7 @@ public interface DeploymentPlanner extends Adapter { * @return true if it's okay to start; false if not. If false, the exclude list will include what should be * excluded. */ - boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude); + boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude); /** * canHandle is called before plan to determine if the plan can do the allocation. Planers should be exclusive so @@ -80,7 +79,7 @@ public interface DeploymentPlanner extends Adapter { * avoid these data centers, pods, clusters, or hosts. * @return true if it's okay to allocate; false or not */ - boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid); + boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid); public enum AllocationAlgorithm { random, diff --git a/server/src/com/cloud/ha/FenceBuilder.java b/api/src/com/cloud/ha/FenceBuilder.java similarity index 89% rename from server/src/com/cloud/ha/FenceBuilder.java rename to api/src/com/cloud/ha/FenceBuilder.java index 6f7413eeddc..41bde71b99d 100644 --- a/server/src/com/cloud/ha/FenceBuilder.java +++ b/api/src/com/cloud/ha/FenceBuilder.java @@ -16,9 +16,9 @@ // under the License. package com.cloud.ha; -import com.cloud.host.HostVO; +import com.cloud.host.Host; import com.cloud.utils.component.Adapter; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; public interface FenceBuilder extends Adapter { /** @@ -27,5 +27,5 @@ public interface FenceBuilder extends Adapter { * @param vm vm * @param host host where the vm was running on. */ - public Boolean fenceOff(VMInstanceVO vm, HostVO host); + public Boolean fenceOff(VirtualMachine vm, Host host); } diff --git a/server/src/com/cloud/ha/Investigator.java b/api/src/com/cloud/ha/Investigator.java similarity index 85% rename from server/src/com/cloud/ha/Investigator.java rename to api/src/com/cloud/ha/Investigator.java index a414156d389..a5de1ba5e1b 100644 --- a/server/src/com/cloud/ha/Investigator.java +++ b/api/src/com/cloud/ha/Investigator.java @@ -16,10 +16,10 @@ // under the License. package com.cloud.ha; -import com.cloud.host.HostVO; +import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.utils.component.Adapter; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; public interface Investigator extends Adapter { /** @@ -27,7 +27,7 @@ public interface Investigator extends Adapter { * * @param vm to work on. */ - public Boolean isVmAlive(VMInstanceVO vm, HostVO host); + public Boolean isVmAlive(VirtualMachine vm, Host host); - public Status isAgentAlive(HostVO agent); + public Status isAgentAlive(Host agent); } diff --git a/api/src/com/cloud/hypervisor/HypervisorGuru.java b/api/src/com/cloud/hypervisor/HypervisorGuru.java index 47ca17a84a3..182f06ae968 100644 --- a/api/src/com/cloud/hypervisor/HypervisorGuru.java +++ b/api/src/com/cloud/hypervisor/HypervisorGuru.java @@ -36,7 +36,7 @@ public interface HypervisorGuru extends Adapter { * @param vm * @return */ - VirtualMachineTO implement(VirtualMachineProfile vm); + VirtualMachineTO implement(VirtualMachineProfile vm); /** * Give hypervisor guru opportunity to decide if certain command needs to be delegated to other host, mainly to secondary storage VM host diff --git a/api/src/com/cloud/network/NetworkMigrationResponder.java b/api/src/com/cloud/network/NetworkMigrationResponder.java index 6283cc54128..951e1c2b4d2 100644 --- a/api/src/com/cloud/network/NetworkMigrationResponder.java +++ b/api/src/com/cloud/network/NetworkMigrationResponder.java @@ -38,7 +38,7 @@ public interface NetworkMigrationResponder { * @param context * @return true when operation was successful. */ - public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context); + public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context); /** * Cancel for migration preparation. @@ -52,7 +52,7 @@ public interface NetworkMigrationResponder { * @param src The context nic migrates from. * @param dst The context nic migrates to. */ - public void rollbackMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst); + public void rollbackMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst); /** * Commit the migration resource. @@ -66,5 +66,5 @@ public interface NetworkMigrationResponder { * @param src the context nic migrates from. * @param dst the context nic migrates to. */ - public void commitMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst); + public void commitMigration(NicProfile nic, Network network, VirtualMachineProfile vm, ReservationContext src, ReservationContext dst); } diff --git a/api/src/com/cloud/network/Networks.java b/api/src/com/cloud/network/Networks.java index 5aede053d50..c76c3d4a473 100755 --- a/api/src/com/cloud/network/Networks.java +++ b/api/src/com/cloud/network/Networks.java @@ -23,7 +23,7 @@ import com.cloud.utils.exception.CloudRuntimeException; /** * Network includes all of the enums used within networking. - * + * */ public class Networks { @@ -66,8 +66,8 @@ public class Networks { Pvlan("pvlan", String.class), UnDecided(null, null); - private String scheme; - private Class type; + private final String scheme; + private final Class type; private BroadcastDomainType(String scheme, Class type) { this.scheme = scheme; @@ -75,14 +75,16 @@ public class Networks { } /** - * @return scheme to be used in broadcast uri. Null indicates that this type does not have broadcast tags. + * @return scheme to be used in broadcast uri. Null indicates that this + * type does not have broadcast tags. */ public String scheme() { return scheme; } /** - * @return type of the value in the broadcast uri. Null indicates that this type does not have broadcast tags. + * @return type of the value in the broadcast uri. Null indicates that + * this type does not have broadcast tags. */ public Class type() { return type; @@ -90,9 +92,56 @@ public class Networks { public URI toUri(T value) { try { - return new URI(scheme + "://" + value); + // do we need to check that value does not contain a scheme + // part? + if (value.toString().contains(":")) + return new URI(value.toString()); + else + return new URI(scheme, value.toString(), null); } catch (URISyntaxException e) { - throw new CloudRuntimeException("Unable to convert to broadcast URI: " + value); + throw new CloudRuntimeException( + "Unable to convert to broadcast URI: " + value); + } + } + + public static BroadcastDomainType getTypeOf(URI uri) { + return getType(uri.getScheme()); + } + + public static BroadcastDomainType getTypeOf(String str) + throws URISyntaxException { + return getTypeOf(new URI(str)); + } + + public static BroadcastDomainType getType(String scheme) { + if (scheme == null) { + return UnDecided; + } + for (BroadcastDomainType type : values()) { + if (scheme.equalsIgnoreCase(type.scheme())) { + return type; + } + } + return UnDecided; + } + + public static String getValue(String uriString) + throws URISyntaxException { + return getValue(new URI(uriString)); + } + + public static String getValue(URI uri) { + BroadcastDomainType type = getTypeOf(uri); + if (type == Vlan) { + // do complicated stuff for backward compatibility + try { + Long.parseLong(uri.getSchemeSpecificPart()); + return uri.getSchemeSpecificPart(); + } catch (NumberFormatException e) { + return uri.getHost(); + } + } else { + return uri.getSchemeSpecificPart(); } } }; @@ -110,8 +159,7 @@ public class Networks { Vpn; public static boolean isSystemNetwork(TrafficType trafficType) { - if (Storage.equals(trafficType) - || Management.equals(trafficType) + if (Storage.equals(trafficType) || Management.equals(trafficType) || Control.equals(trafficType)) { return true; } @@ -163,11 +211,18 @@ public class Networks { public URI toUri(T value) { try { - // assert(this!=Vlan || value.getClass().isAssignableFrom(Integer.class)) : + // assert(this!=Vlan || + // value.getClass().isAssignableFrom(Integer.class)) : + // do we need to check that value does not contain a scheme + // part? // "Why are you putting non integer into vlan url"; - return new URI(scheme + "://" + value.toString()); + if (value.toString().contains(":")) + return new URI(value.toString()); + else + return new URI(scheme, value.toString(), null); } catch (URISyntaxException e) { - throw new CloudRuntimeException("Unable to convert to isolation type URI: " + value); + throw new CloudRuntimeException( + "Unable to convert to isolation type URI: " + value); } } } @@ -176,7 +231,7 @@ public class Networks { Vlan("vlan"), VSwitch("vswitch"); - private String scheme; + private final String scheme; private BroadcastScheme(String scheme) { this.scheme = scheme; diff --git a/api/src/com/cloud/network/element/DhcpServiceProvider.java b/api/src/com/cloud/network/element/DhcpServiceProvider.java index 6363d7cd22e..62c650be313 100644 --- a/api/src/com/cloud/network/element/DhcpServiceProvider.java +++ b/api/src/com/cloud/network/element/DhcpServiceProvider.java @@ -27,7 +27,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public interface DhcpServiceProvider extends NetworkElement { - boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; + boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; + boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/element/NetworkElement.java b/api/src/com/cloud/network/element/NetworkElement.java index d89c2a3c403..5f603ce6fbd 100644 --- a/api/src/com/cloud/network/element/NetworkElement.java +++ b/api/src/com/cloud/network/element/NetworkElement.java @@ -71,7 +71,7 @@ public interface NetworkElement extends Adapter { * @throws ResourceUnavailableException * @throws InsufficientNetworkCapacityException */ - boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException; @@ -85,7 +85,7 @@ public interface NetworkElement extends Adapter { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, + boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException; /** diff --git a/api/src/com/cloud/network/element/UserDataServiceProvider.java b/api/src/com/cloud/network/element/UserDataServiceProvider.java index d9ddf9329ff..29cd5ae9377 100644 --- a/api/src/com/cloud/network/element/UserDataServiceProvider.java +++ b/api/src/com/cloud/network/element/UserDataServiceProvider.java @@ -27,8 +27,8 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public interface UserDataServiceProvider extends NetworkElement { - public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; - boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException; - boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException; - boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException; + public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; + boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException; + boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException; + boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException; } diff --git a/api/src/com/cloud/network/guru/NetworkGuru.java b/api/src/com/cloud/network/guru/NetworkGuru.java index 4a9b871e240..4127233d3aa 100755 --- a/api/src/com/cloud/network/guru/NetworkGuru.java +++ b/api/src/com/cloud/network/guru/NetworkGuru.java @@ -127,7 +127,7 @@ public interface NetworkGuru extends Adapter { * @throws InsufficientAddressCapacityException if there are not addresses * to be assigned. */ - NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException; + NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException; /** * Once a guest network is implemented, then the virtual machine must @@ -147,7 +147,7 @@ public interface NetworkGuru extends Adapter { * @throws ConcurrentOperationException if there are multiple operations * happening on this guest network or vm. */ - void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException; + void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException; /** * When a virtual machine is stopped, the NetworkGuru is informed via the @@ -158,7 +158,7 @@ public interface NetworkGuru extends Adapter { * @param reservationId reservation id passed to it in the ReservationContext * @return true if release is successful or false if unsuccessful. */ - boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId); + boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId); /** * When a virtual machine is destroyed, the NetworkGuru is informed via @@ -169,7 +169,7 @@ public interface NetworkGuru extends Adapter { * @param nic nic that the vm was using to access the guest network. * @param vm virtual machine being destroyed. */ - void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm); + void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm); /** * @deprecated This method should not be here in the first place. What does this really mean? Is it always persisted diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java index c172fbff422..0a968bc415f 100755 --- a/api/src/com/cloud/vm/VirtualMachine.java +++ b/api/src/com/cloud/vm/VirtualMachine.java @@ -158,7 +158,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I } } - public static final String IsDynamicScalingEnabled = "enable.dynamic.scaling"; + static final String IsDynamicScalingEnabled = "enable.dynamic.scaling"; public enum Event { CreateRequested, @@ -182,27 +182,28 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I }; public enum Type { - User, - DomainRouter, - ConsoleProxy, - SecondaryStorageVm, - ElasticIpVm, - ElasticLoadBalancerVm, - InternalLoadBalancerVm, + User(false), + DomainRouter(true), + ConsoleProxy(true), + SecondaryStorageVm(true), + ElasticIpVm(true), + ElasticLoadBalancerVm(true), + InternalLoadBalancerVm(true), /* * UserBareMetal is only used for selecting VirtualMachineGuru, there is no * VM with this type. UserBareMetal should treat exactly as User. */ - UserBareMetal; + UserBareMetal(false); - public static boolean isSystemVM(VirtualMachine.Type vmtype) { - if (DomainRouter.equals(vmtype) - || ConsoleProxy.equals(vmtype) - || SecondaryStorageVm.equals(vmtype) || InternalLoadBalancerVm.equals(vmtype)) { - return true; - } - return false; + boolean _isUsedBySystem; + + private Type(boolean isUsedBySystem) { + _isUsedBySystem = isUsedBySystem; + } + + public boolean isUsedBySystem() { + return _isUsedBySystem; } } @@ -211,39 +212,39 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I * reference this VM. You can build names that starts with this name and it * guarantees uniqueness for things related to the VM. */ - public String getInstanceName(); + String getInstanceName(); /** * @return the host name of the virtual machine. If the user did not * specify the host name when creating the virtual machine then it is * defaults to the instance name. */ - public String getHostName(); + String getHostName(); /** * @return the ip address of the virtual machine. */ - public String getPrivateIpAddress(); + String getPrivateIpAddress(); /** * @return mac address. */ - public String getPrivateMacAddress(); + String getPrivateMacAddress(); /** * @return password of the host for vnc purposes. */ - public String getVncPassword(); + String getVncPassword(); /** * @return the state of the virtual machine */ - // public State getState(); + // State getState(); /** * @return template id. */ - public long getTemplateId(); + long getTemplateId(); @@ -252,49 +253,51 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I * * @return guestOSId */ - public long getGuestOSId(); + long getGuestOSId(); /** * @return pod id. */ - public Long getPodIdToDeployIn(); + Long getPodIdToDeployIn(); /** * @return data center id. */ - public long getDataCenterId(); + long getDataCenterId(); /** * @return id of the host it was assigned last time. */ - public Long getLastHostId(); + Long getLastHostId(); @Override - public Long getHostId(); + Long getHostId(); /** * @return should HA be enabled for this machine? */ - public boolean isHaEnabled(); + boolean isHaEnabled(); /** * @return should limit CPU usage to the service offering? */ - public boolean limitCpuUse(); + boolean limitCpuUse(); /** * @return date when machine was created */ - public Date getCreated(); + Date getCreated(); - public long getServiceOfferingId(); + long getServiceOfferingId(); - public Long getDiskOfferingId(); + Long getDiskOfferingId(); Type getType(); HypervisorType getHypervisorType(); - public Map getDetails(); + Map getDetails(); + + long getUpdated(); } diff --git a/api/src/com/cloud/vm/VirtualMachineProfile.java b/api/src/com/cloud/vm/VirtualMachineProfile.java index 6861372d08d..3da8397fd0e 100644 --- a/api/src/com/cloud/vm/VirtualMachineProfile.java +++ b/api/src/com/cloud/vm/VirtualMachineProfile.java @@ -19,9 +19,7 @@ package com.cloud.vm; import java.util.List; import java.util.Map; -import com.cloud.agent.api.to.DataTO; import com.cloud.agent.api.to.DiskTO; -import com.cloud.agent.api.to.VolumeTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; import com.cloud.template.VirtualMachineTemplate; @@ -33,10 +31,8 @@ import com.cloud.user.Account; * on what the virtual machine profile should look like before it is * actually started on the hypervisor. * - * @param - * a VirtualMachine */ -public interface VirtualMachineProfile { +public interface VirtualMachineProfile { public static class Param { @@ -69,7 +65,7 @@ public interface VirtualMachineProfile { /** * @return the virtual machine that backs up this profile. */ - T getVirtualMachine(); + VirtualMachine getVirtualMachine(); /** * @return service offering for this virtual machine. diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java index e3a9b62c6ce..8e9fabd3f60 100644 --- a/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java +++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java @@ -21,7 +21,6 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.exception.AffinityConflictException; import com.cloud.utils.component.Adapter; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public interface AffinityGroupProcessor extends Adapter { @@ -37,7 +36,7 @@ public interface AffinityGroupProcessor extends Adapter { * @param avoid * avoid these data centers, pods, clusters, or hosts. */ - void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) + void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException; /** @@ -57,6 +56,6 @@ public interface AffinityGroupProcessor extends Adapter { * @param plannedDestination * deployment destination where VM is planned to be deployed */ - boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) + boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) throws AffinityConflictException; } \ No newline at end of file diff --git a/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java b/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java index 325ab80e047..779ca326b3a 100644 --- a/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java +++ b/api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java @@ -21,7 +21,6 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.exception.AffinityConflictException; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public class AffinityProcessorBase extends AdapterBase implements AffinityGroupProcessor { @@ -29,7 +28,7 @@ public class AffinityProcessorBase extends AdapterBase implements AffinityGroupP protected String _type; @Override - public void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) + public void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException { } @@ -44,7 +43,7 @@ public class AffinityProcessorBase extends AdapterBase implements AffinityGroupP } @Override - public boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) + public boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination) throws AffinityConflictException { return true; } diff --git a/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java b/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java index 191e9589a65..4d5d4f4429e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java @@ -28,6 +28,7 @@ import org.apache.cloudstack.api.response.ResourceLimitResponse; import org.apache.log4j.Logger; import com.cloud.configuration.ResourceLimit; +import com.cloud.configuration.Resource.ResourceOwnerType; @APICommand(name = "listResourceLimits", description="Lists resource limits.", responseObject=ResourceLimitResponse.class) public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd { @@ -42,11 +43,19 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="Lists resource limits by ID.") private Long id; - @Parameter(name=ApiConstants.RESOURCE_TYPE, type=CommandType.INTEGER, description="Type of resource to update. Values are 0, 1, 2, 3, and 4. 0 - Instance. Number of instances a user can create. " + - "1 - IP. Number of public IP addresses a user can own. " + - "2 - Volume. Number of disk volumes a user can create." + - "3 - Snapshot. Number of snapshots a user can create." + - "4 - Template. Number of templates that a user can register/create.") + @Parameter(name=ApiConstants.RESOURCE_TYPE, type=CommandType.INTEGER, description="Type of resource to update. Values are 0, 1, 2, 3, and 4." + + "0 - Instance. Number of instances a user can create. " + + "1 - IP. Number of public IP addresses an account can own. " + + "2 - Volume. Number of disk volumes an account can own." + + "3 - Snapshot. Number of snapshots an account can own." + + "4 - Template. Number of templates an account can register/create." + + "5 - Project. Number of projects an account can own." + + "6 - Network. Number of networks an account can own." + + "7 - VPC. Number of VPC an account can own." + + "8 - CPU. Number of CPU an account can allocate for his resources." + + "9 - Memory. Amount of RAM an account can allocate for his resources." + + "10 - Primary Storage. Amount of Primary storage an account can allocate for his resoruces." + + "11 - Secondary Storage. Amount of Secondary storage an account can allocate for his resources.") private Integer resourceType; ///////////////////////////////////////////////////// diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java index 9689a994fcd..e3c1bf2a7b9 100644 --- a/api/src/org/apache/cloudstack/context/CallContext.java +++ b/api/src/org/apache/cloudstack/context/CallContext.java @@ -110,7 +110,9 @@ public class CallContext { CallContext callingContext = new CallContext(callingUser, callingAccount, contextId); s_currentContext.set(callingContext); NDC.push("ctx-" + UuidUtils.first(contextId)); - s_logger.debug("Setting calling context: " + callingContext); + if (s_logger.isTraceEnabled()) { + s_logger.trace("Registered: " + callingContext); + } return callingContext; } @@ -161,11 +163,13 @@ public class CallContext { public static CallContext unregister() { CallContext context = s_currentContext.get(); if (context == null) { - s_logger.trace("No context to remove"); + s_logger.debug("No context to remove"); return null; } s_currentContext.remove(); - s_logger.debug("Context removed " + context); + if (s_logger.isTraceEnabled()) { + s_logger.trace("Unregistered: " + context); + } String contextId = context.getContextId(); String sessionIdOnStack = null; String sessionIdPushedToNDC = "ctx-" + UuidUtils.first(contextId); @@ -210,9 +214,9 @@ public class CallContext { @Override public String toString() { - return new StringBuffer("CallContext[acct=").append(account.getId()) + return new StringBuffer("CCtxt[acct=").append(account.getId()) .append("; user=").append(user.getId()) - .append("; session=").append(contextId) + .append("; id=").append(contextId) .append("]").toString(); } } diff --git a/api/test/com/cloud/network/NetworksTest.java b/api/test/com/cloud/network/NetworksTest.java new file mode 100644 index 00000000000..31114e86283 --- /dev/null +++ b/api/test/com/cloud/network/NetworksTest.java @@ -0,0 +1,76 @@ +// 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.network; + +import java.net.URISyntaxException; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.cloud.network.Networks.BroadcastDomainType; + +/** + * @author dhoogland + * + */ +public class NetworksTest { + + @Before + public void setUp() { + } + + @Test + public void emptyBroadcastDomainTypeTest() throws URISyntaxException { + BroadcastDomainType type = BroadcastDomainType.getTypeOf(""); + Assert.assertEquals( + "an empty uri should mean a broadcasttype of undecided", + BroadcastDomainType.UnDecided, type); + } + + @Test + public void vlanBroadcastDomainTypeTest() throws URISyntaxException { + String uri1 = "vlan://1"; + String uri2 = "vlan:2"; + BroadcastDomainType type1 = BroadcastDomainType.getTypeOf(uri1); + BroadcastDomainType type2 = BroadcastDomainType.getTypeOf(uri2); + String id1 = BroadcastDomainType.getValue(uri1); + String id2 = BroadcastDomainType.getValue(uri2); + Assert.assertEquals("uri1 should be of broadcasttype vlan", + BroadcastDomainType.Vlan, type1); + Assert.assertEquals("uri2 should be of broadcasttype vlan", + BroadcastDomainType.Vlan, type2); + Assert.assertEquals("id1 should be \"1\"", "1", id1); + Assert.assertEquals("id1 should be \"2\"", "2", id2); + } + + @Test + public void otherTypesTest() throws URISyntaxException { + String bogeyUri = "lswitch://1"; + String uri2 = "mido:2"; + BroadcastDomainType type1 = BroadcastDomainType.getTypeOf(bogeyUri); + BroadcastDomainType type2 = BroadcastDomainType.getTypeOf(uri2); + String id1 = BroadcastDomainType.getValue(bogeyUri); + String id2 = BroadcastDomainType.getValue(uri2); + Assert.assertEquals("uri1 should be of broadcasttype vlan", + BroadcastDomainType.Lswitch, type1); + Assert.assertEquals("uri2 should be of broadcasttype vlan", + BroadcastDomainType.Mido, type2); + Assert.assertEquals("id1 should be \"//1\"", "//1", id1); + Assert.assertEquals("id1 should be \"2\"", "2", id2); + } +} diff --git a/docs/en-US/changed-API-commands-4.2.xml b/docs/en-US/changed-API-commands-4.2.xml index 2dd5a3b05ea..b1008875a51 100644 --- a/docs/en-US/changed-API-commands-4.2.xml +++ b/docs/en-US/changed-API-commands-4.2.xml @@ -18,114 +18,1116 @@ specific language governing permissions and limitations under the License. --> -
+
Changed API Commands in 4.2 + + - Parameter Name + API Commands Description + + listNetworkACLs + The following new request parameters are added: aclid (optional), action + (optional), protocol (optional) + The following new response parameters are added: aclid, action, + number + + + copyTemplate + + The following new response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + listRouters + + The following new response parameters are added: ip6dns1, ip6dns2, + role + + + updateConfiguration + The following new request parameters are added: accountid (optional), + clusterid (optional), storageid (optional), zoneid (optional) + The following new response parameters are added: id, scope + + + listVolumes + The following request parameter is removed: details + The following new response parameter is added: displayvolume + + + suspendProject + + The following new response parameters are added: cpuavailable, cpulimit, cputotal, + ipavailable, iplimit, iptotal, memoryavailable, memorylimit, memorytotal, + networkavailable, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal, snapshotavailable, snapshotlimit, + snapshottotal, templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, + vmrunning, vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, + vpcavailable, vpclimit, vpctotal + + + listRemoteAccessVpns + + The following new response parameters are added: id + + + registerTemplate + The following new request parameters are added: imagestoreuuid (optional), + isdynamicallyscalable (optional), isrouting (optional) + The following new response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + addTrafficMonitor + + The following response parameters are removed: privateinterface, privatezone, + publicinterface, publiczone, usageinterface, username + + + createTemplate + The following response parameters are removed: clusterid, clustername, + disksizeallocated, disksizetotal, disksizeused, ipaddress, path, podid, podname, + state, tags, type + The following new response parameters are added: account, accountid, bootable, + checksum, crossZones, details, displaytext, domain, domainid, format, hostid, + hostname, hypervisor, isdynamicallyscalable, isextractable, isfeatured, ispublic, + isready, ostypeid, ostypename, passwordenabled, project, projectid, removed, size, + sourcetemplateid, sshkeyenabled, status, templatetag, templatetype, + tags + + + listLoadBalancerRuleInstances + + The following new response parameters are added: diskioread, diskiowrite, + diskkbsread, diskkbswrite, displayvm, isdynamicallyscalable, + affinitygroup + + + migrateVolume + The following new request parameters is added: livemigrate (optional) + The following new response parameters is added: displayvolume + + + createAccount + The following new request parameters are added: accountid (optional), userid + (optional) + The following new response parameters are added: accountdetails, cpuavailable, + cpulimit, cputotal, defaultzoneid, ipavailable, iplimit, iptotal, iscleanuprequired, + isdefault, memoryavailable, memorylimit, memorytotal, name, networkavailable, + networkdomain, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, projectavailable, projectlimit, + projecttotal, receivedbytes, secondarystorageavailable, secondarystoragelimit, + secondarystoragetotal, sentbytes, snapshotavailable, snapshotlimit, snapshottotal, + templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, vmrunning, + vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, vpcavailable, vpclimit, + vpctotal, user + The following parameters are removed: account, accountid, apikey, created, email, + firstname, lastname, secretkey, timezone, username + + + updatePhysicalNetwork + The following new request parameters is added: removevlan (optional) + + + + listTrafficMonitors + + The following response parameters are removed: privateinterface, privatezone, + publicinterface, publiczone, usageinterface, username + + + attachIso + + The following new response parameters are added: diskioread, diskiowrite, + diskkbsread, diskkbswrite, displayvm, isdynamicallyscalable, + affinitygroup + + + listProjects + The following new request parameters are added: cpuavailable, cpulimit, + cputotal, ipavailable, iplimit, iptotal, memoryavailable, memorylimit, memorytotal, + networkavailable, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal, snapshotavailable, snapshotlimit, + snapshottotal, templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, + vmrunning, vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, + vpcavailable, vpclimit, vpctotal + + + enableAccount + + The following new response parameters are added: cpuavailable, cpulimit, cputotal, + isdefault, memoryavailable, memorylimit, memorytotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal + + + listPublicIpAddresses + + The following new response parameters are added: isportable, vmipaddress + + + + enableStorageMaintenance + + The following new response parameters are added: hypervisor, scope, + suitableformigration + + + listLoadBalancerRules + The following new request parameters is added: networkid (optional) + The following new response parameters is added: networkid + + + stopRouter + + The following new response parameters are added: ip6dns1, ip6dns2, role + + + + listClusters + + The following new response parameters are added: cpuovercommitratio, + memoryovercommitratio + + + attachVolume + + The following new response parameter is added: displayvolume + + + updateVPCOffering + The following request parameters is made mandatory: id + + + resetSSHKeyForVirtualMachine + The following new request parameter is added: keypair (required) + The following parameter is removed: name + The following new response parameters are added: diskioread, diskiowrite, + diskkbsread, diskkbswrite, displayvm, isdynamicallyscalable, + affinitygroup + + + updateCluster + The following new request parameters are added: cpuovercommitratio + (optional), memoryovercommitratio (optional) + The following new response parameters are added: cpuovercommitratio, + memoryovercommitratio + + + listPrivateGateways + The following new response parameters are added: aclid, sourcenatsupported + + + + ldapConfig + The following new request parameters are added: listall (optional) + The following parameters has been made optional: searchbase, hostname, + queryfilter + The following new response parameter is added: ssl + + + listTemplates + + The following new response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + listNetworks + + The following new response parameters are added: aclid, displaynetwork, ip6cidr, + ip6gateway, ispersistent, networkcidr, reservediprange + + + restartNetwork + + The following new response parameters are added: isportable, vmipaddress + + + + prepareTemplate + + The following new response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + rebootVirtualMachine + + The following new response parameters are added: diskioread, diskiowrite, + diskkbsread, diskkbswrite, displayvm, isdynamicallyscalable, + affinitygroup + + + changeServiceForRouter + The following new request parameters are added: aclid (optional), action + (optional), protocol (optional) + The following new response parameters are added: id, scope + + + updateZone + The following new request parameters are added: ip6dns1 (optional), ip6dns2 + (optional) + The following new response parameters are added: ip6dns1, ip6dns2 + + + ldapRemove + + The following new response parameters are added: ssl + + + updateServiceOffering + + The following new response parameters are added: deploymentplanner, isvolatile + + + + updateStoragePool + + The following new response parameters are added: hypervisor, scope, + suitableformigration + + + listFirewallRules + The following request parameter is removed: traffictype + The following new response parameters are added: networkid + + + updateUser + + The following new response parameters are added: iscallerchilddomain, isdefault + + + + updateProject + + The following new response parameters are added: cpuavailable, cpulimit, cputotal, + ipavailable, iplimit, iptotal, memoryavailable, memorylimit, memorytotal, + networkavailable, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal, snapshotavailable, snapshotlimit, + snapshottotal, templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, + vmrunning, vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, + vpcavailable, vpclimit, vpctotal + + + updateTemplate + The following new request parameters are added: isdynamicallyscalable + (optional), isrouting (optional) + The following new response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + disableUser + + The following new response parameters are added: iscallerchilddomain, isdefault + + + + activateProject + + The following new response parameters are added: cpuavailable, cpulimit, cputotal, + ipavailable, iplimit, iptotal, memoryavailable, memorylimit, memorytotal, + networkavailable, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal, snapshotavailable, snapshotlimit, + snapshottotal, templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, + vmrunning, vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, + vpcavailable, vpclimit, vpctotal + + + createNetworkACL + The following new request parameters are added: aclid (optional), action + (optional), number (optional) + The following request parameter is now optional: networkid + The following new response parameters are added: aclid, action, number + + + + enableStaticNat + The following new request parameters are added: vmguestip (optional) + + + + registerIso + The following new request parameters are added: imagestoreuuid (optional), + isdynamicallyscalable (optional) + The following new response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + createIpForwardingRule + + The following new response parameter is added: vmguestip + + + resetPasswordForVirtualMachine + + The following new response parameters are added: diskioread, diskiowrite, + diskkbsread, diskkbswrite, displayvm, isdynamicallyscalable, + affinitygroup + + + createVolume + The following new request parameter is added: displayvolume (optional) + The following new response parameter is added: displayvolume + + + startRouter + + The following new response parameters are added: ip6dns1, ip6dns2, role + + + + listCapabilities + The following new response parameters are added: apilimitinterval and + apilimitmax. + See . + + + createServiceOffering + The following new request parameters are added: deploymentplanner (optional), + isvolatile (optional), serviceofferingdetails (optional). + isvolatie indicates whether the service offering includes Volatile VM capability, + which will discard the VM's root disk and create a new one on reboot. See . + The following new response parameters are added: deploymentplanner, isvolatile + + + + restoreVirtualMachine + The following request parameter is added: templateID (optional). This is used + to point to the new template ID when the base image is updated. See . + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + createNetwork + The following new request parameters are added: aclid (optional), + displaynetwork (optional), endipv6 (optional), ip6cidr (optional), ip6gateway + (optional), isolatedpvlan (optional), startipv6 (optional) + The following new response parameters are added: aclid, displaynetwork, ip6cidr, + ip6gateway, ispersistent, networkcidr, reservediprange + createVlanIpRange + The following new request parameters are added: startipv6, endipv6, + ip6gateway, ip6cidr + Changed parameters: startip (is now optional) + The following new response parameters are added: startipv6, endipv6, ip6gateway, + ip6cidr + + + CreateZone + The following new request parameters are added: ip6dns1, ip6dns2 + The following new response parameters are added: ip6dns1, ip6dns2 + + + deployVirtualMachine + The following request parameters are added: affinitygroupids (optional), + affinitygroupnames (optional), displayvm (optional), ip6address (optional) + The following request parameter is modified: iptonetworklist has a new possible + value, ipv6 + The following new response parameters are added: diskioread, diskiowrite, + diskkbsread, diskkbswrite, displayvm, isdynamicallyscalable, + affinitygroup + + - No new parameter has been added. However, the current functionality has been - extended to add guest IPs from a different subnet in shared networks in a Basic zone. - Ensure that you provide netmask and gateway if you are adding guest IPs from a - different subnet. + createNetworkOffering + + + The following request parameters are added: details (optional), + egressdefaultpolicy (optional), ispersistent (optional) + ispersistent determines if the network or network offering created or listed by + using this offering are persistent or not. + The following response parameters are added: details, egressdefaultpolicy, + ispersistent - updateResourceLimit - Added the following resource types to the resourcetype - request parameter to set the limits: + listNetworks + + + The following request parameters is added: isPersistent. + This parameter determines if the network or network offering created or listed by + using this offering are persistent or not. + + + + + listNetworkOfferings + + + The following request parameters is added: isPersistent. + This parameter determines if the network or network offering created or listed by + using this offering are persistent or not. + For listNetworkOfferings, the following response parameter has been added: + details, egressdefaultpolicy, ispersistent + + + + + addF5LoadBalancer + configureNetscalerLoadBalancer + addNetscalerLoadBalancer + listF5LoadBalancers + configureF5LoadBalancer + listNetscalerLoadBalancers + + + The following response parameter is removed: inline. + + + + + listRouters + + + For nic responses, the following fields have been added. - CPU + ip6address - RAM + ip6gateway - primary storage - - - secondary storage - - - network rate + ip6cidr - updateResourceCount - Added the following resource types to the resourcetype - request parameter to set the limits: - - - CPU - - - RAM - - - primary storage - - - secondary storage - - - network rate - - + listVirtualMachines + + + The following request parameters are added: affinitygroupid (optional), vpcid + (optional) + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup - listResourceLimits - Added the following resource types to the resourcetype - request parameter: + listRouters + listZones + + + For DomainRouter and DataCenter response, the following fields have been + added. - CPU + ip6dns1 - RAM - - - primary storage - - - secondary storage - - - network rate + ip6dns2 + For listZones, the following optional request parameters are added: name, + networktype - UpdatePhysicalNetwork + listFirewallRules + createFirewallRule - Added the following request parameters: - - - vlan (adds a new VLAN range to the existing VLAN range) - - - removelan (removes the specified VLAN range) - - - - The removevlan and vlan parameters can be used together. If the VLAN range that - you are trying to remove is in use, the operation will not succeed. - + The following request parameter is added: traffictype (optional). + The following response parameter is added: networkid + + + + listUsageRecords + The following response parameter is added: virtualsize. + + + + + deleteIso + + + The following request parameter is removed: forced + + + + addCluster + The following request parameters are added: cpuovercommitratio (optional), + guestvswitchtype (optional), guestvswitchtype (optional), memoryovercommitratio + (optional), publicvswitchtype (optional), publicvswitchtype (optional) + See . + The following request parameters are added: cpuovercommitratio, + memoryovercommitratio + + + + updateCluster + The following request parameters are added: cpuovercommitratio, + ramovercommitratio + See . + + + + + createStoragePool + + + The following request parameters are added: hypervisor (optional), provider + (optional), scope (optional) + The following request parameters have been made mandatory: podid, clusterid + See . + The following response parameter has been added: hypervisor, scope, + suitableformigration + + + + listStoragePools + The following request parameter is added: scope (optional) + See . + The following response parameters are added: hypervisor, scope, + suitableformigration + + + + updateDiskOffering + + + The following response parameter is added: displayoffering + + + + + changeServiceForVirtualMachine + + + The following response parameter are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + recoverVirtualMachine + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + listCapabilities + + + The following response parameters are added: apilimitinterval, apilimitmax + + + + + createRemoteAccessVpn + + + The following response parameters are added: id + + + + + startVirtualMachine + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + detachIso + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + updateVPC + + + The following request parameters has been made mandatory: id, name + + + + + associateIpAddress + + + The following request parameters are added: isportable (optional), regionid + (optional) + The following response parameters are added: isportable, vmipaddress + + + + + listProjectAccounts + + + The following response parameters are added: cpuavailable, cpulimit, cputotal, + ipavailable, iplimit, iptotal, memoryavailable, memorylimit, memorytotal, + networkavailable, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal, snapshotavailable, snapshotlimit, + snapshottotal, templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, + vmrunning, vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, + vpcavailable, vpclimit, vpctotal + + + + + disableAccount + + + The following response parameters are added: cpuavailable, cpulimit, cputotal, + isdefault, memoryavailable, memorylimit, memorytotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal + + + + + listPortForwardingRules + + + The following response parameters are added: vmguestip + + + + + migrateVirtualMachine + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + cancelStorageMaintenance + + + The following response parameters are added: hypervisor, scope, + suitableformigration + + + + + createPortForwardingRule + + The following request parameter is added: vmguestip (optional) The + following response parameter is added: vmguestip + + + + addVpnUser + + + The following response parameter is added: state + + + + + createVPCOffering + + + The following request parameter is added: serviceproviderlist (optional) + + + + + assignVirtualMachine + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + listConditions + + + The following response parameters are added: account, counter, domain, domainid, + project, projectid, relationaloperator, threshold + Removed response parameters: name, source, value + + + + + createPrivateGateway + + + The following request parameters are added: aclid (optional), sourcenatsupported + (optional) + The following response parameters are added: aclid, sourcenatsupported + + + + + updateVirtualMachine + + + The following request parameters are added: displayvm (optional), + isdynamicallyscalable (optional) + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + destroyRouter + + + The following response parameters are added: ip6dns1, ip6dns2, role + + + + + listServiceOfferings + + + The following response parameters are added: deploymentplanner, isvolatile + + + + + listUsageRecords + + + The following response parameters are removed: virtualsize + + + + + createProject + + + The following response parameters are added: cpuavailable, cpulimit, cputotal, + ipavailable, iplimit, iptotal, memoryavailable, memorylimit, memorytotal, + networkavailable, networklimit, networktotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal, snapshotavailable, snapshotlimit, + snapshottotal, templateavailable, templatelimit, templatetotal, vmavailable, vmlimit, + vmrunning, vmstopped, vmtotal, volumeavailable, volumelimit, volumetotal, + vpcavailable, vpclimit, vpctotal + + + + + enableUser + + + The following response parameters are added: iscallerchilddomain, isdefault + + + + + + createLoadBalancerRule + + + The following response parameter is added: networkid + + + + + updateAccount + + + The following response parameters are added: cpuavailable, cpulimit, cputotal, + isdefault, memoryavailable, memorylimit, memorytotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal + + + + + copyIso + + + The following response parameters are added: isdynamicallyscalable, sshkeyenabled + + + + + + uploadVolume + + + The following request parameters are added: imagestoreuuid (optional), projectid + (optional + The following response parameters are added: displayvolume + + + + + createDomain + + + The following request parameter is added: domainid (optional) + + + + + stopVirtualMachine + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + listAccounts + + + The following response parameters are added: cpuavailable, cpulimit, cputotal, + isdefault, memoryavailable, memorylimit, memorytotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal + + + + + createSnapshot + + + The following response parameter is added: zoneid + + + + + updateIso + + + The following request parameters are added: isdynamicallyscalable (optional), + isrouting (optional) + The following response parameters are added: isdynamicallyscalable, + sshkeyenabled + + + + + listIpForwardingRules + + + The following response parameter is added: vmguestip + + + + + updateNetwork + + + The following request parameters are added: displaynetwork (optional), guestvmcidr + (optional) + The following response parameters are added: aclid, displaynetwork, ip6cidr, + ip6gateway, ispersistent, networkcidr, reservediprange + + + + + destroyVirtualMachine + + + The following response parameters are added: diskioread, diskiowrite, diskkbsread, + diskkbswrite, displayvm, isdynamicallyscalable, affinitygroup + + + + + createDiskOffering + + + The following request parameter is added: displayoffering (optional) + The following response parameter is added: displayoffering + + + + + rebootRouter + + + The following response parameters are added: ip6dns1, ip6dns2, role + + + + + listConfigurations + + + The following request parameters are added: accountid (optional), clusterid + (optional), storageid (optional), zoneid (optional) + The following response parameters are added: id, scope + + + + + createUser + + + The following request parameter is added: userid (optional) + The following response parameters are added: iscallerchilddomain, isdefault + + + + + listDiskOfferings + + + The following response parameter is added: displayoffering + + + + + detachVolume + + + The following response parameter is added: displayvolume + + + + + deleteUser + + + The following response parameters are added: displaytext, success + Removed parameters: id, account, accountid, accounttype, apikey, created, domain, + domainid, email, firstname, lastname, secretkey, state, timezone, username + + + + + listSnapshots + + + The following request parameter is added: zoneid (optional) + The following response parameter is added: zoneid + + + + + markDefaultZoneForAccount + + + The following response parameters are added: cpuavailable, cpulimit, cputotal, + isdefault, memoryavailable, memorylimit, memorytotal, primarystorageavailable, + primarystoragelimit, primarystoragetotal, secondarystorageavailable, + secondarystoragelimit, secondarystoragetotal + + + + + restartVPC + + + The following request parameters are made mandatory: id + + + + + updateHypervisorCapabilities + + + The following response parameters are added: hypervisor, hypervisorversion, + maxdatavolumeslimit, maxguestslimit, maxhostspercluster, securitygroupenabled, + storagemotionenabled + Removed parameters: cpunumber, cpuspeed, created, defaultuse, displaytext, domain, + domainid, hosttags, issystem, limitcpuuse, memory, name, networkrate, offerha, + storagetype, systemvmtype, tags + + + + + updateLoadBalancerRule + + + The following response parameter is added: networkid + + + + + listVlanIpRanges + + + The following response parameters are added: endipv6, ip6cidr, ip6gateway, + startipv6 + + + + + listHypervisorCapabilities + + + The following response parameters are added: maxdatavolumeslimit, + maxhostspercluster, storagemotionenabled + + + + + updateNetworkOffering + + + The following response parameters are added: details, egressdefaultpolicy, + ispersistent + + + + + createVirtualRouterElement + + + The following request parameters are added: providertype (optional) + + + + + listVpnUsers + + + The following response parameter is added: state + + + + + listUsers + + + The following response parameters are added: iscallerchilddomain, isdefault + + + + + + listSupportedNetworkServices + + + The following response parameter is added: provider + + + + + listIsos + + + The following response parameters are added: isdynamicallyscalable, sshkeyenabled + diff --git a/docs/en-US/gsoc-midsummer-ian.xml b/docs/en-US/gsoc-midsummer-ian.xml index 348418f6969..c62cdc3545e 100644 --- a/docs/en-US/gsoc-midsummer-ian.xml +++ b/docs/en-US/gsoc-midsummer-ian.xml @@ -11,9 +11,9 @@ 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 @@ -23,6 +23,317 @@ -->
- Mid-Summer Progress Updates - This section describes ... + Mid-Summer Progress Updates for Ian Duffy - "Ldap User Provisioning" + This section describes my progress with the project titled "LDAP User Provisioning". +
+ Introduction + + Progress on my project is moving along smoothly. The Cloudstack community along with my mentor Abhi have been very accomodating. Since the community bonding period communication has been consistent and the expectations have been clear. Sebastien, head mentor has given us great guidance. I have enjoyed their teaching style. I found it was a nice gradual build up starting with creating a simple document update patch to eventually submitting a new Cloudstack Plugin. + + + I am pleased with my progress on the project to date. I feel as if the goals set out in my proposal are very doable and that they should be achieved. + +
+
+ Continuous Integration with Jenkins + + In order to try deliver working solutions of good quality I felt it would be a good idea to implement a continuous integration environment using Jenkins. The idea of this would be to automatically build and test my code. This was welcomed and aided by community members greatly. + + + The pipeline for this is as follows: + + + + + + + jenkins-pipeline.png: Screenshot of the build pipeline. + + + + + + Acquire Code Base - This pulls down the latest Cloudstack codebase and builds it executing all unit tests. + + + + + Static Analysis - This runs tests on my code to ensure quality and good practice. This is being achieved with sonar source. + + + + + Integration Tests - This deploys the Cloudstack database. Brings up the Cloudstack Manager with jetty and their simulator. All checkin/integration tests are ran and then the jetty server is shutdown. + + + + + Package(Only exists on my local Jenkins) - The codebase is packaged up into an RPM and placed onto a local yum repo. If the time allows this will be used for future automated acceptance testing. + + + + + If your are interested in this I have created a screencast on youtube which walks through it: Continuous testing environment + +
+
+ Ldap Plugin implementation + + At the start of the coding stage I began to review the current LDAP implementation. This includes: + + + + + The user authenticator - This enables LDAP users to login to Cloudstack once the user exists within the internal Cloudstack database. + + + + + LDAPConfig -This allows for adding LDAP configuration. This is detailed over here: ldapConfig API reference This did not allow multiple configurations. + + + + + LDAPRemove - This allows for removing the LDAP configuration + + + + + UI features. Global settings -> LDAP configuration allowed for the addition of a single LDAP server using the LDAPConfig command and the removal of an LDAP server using the LDAPRemove command. + + + + + After reviewing this code and implementation for some time I realised that it wasn't the most maintainable code. I realised I could extend it if required. But it would involve creating more unmaintainable code and it would be messy. This goes against my own principles of developing quality. This made me make the steep but justified decision to completely redo the LDAP implementation within Cloudstack. By doing this I did expanded the scope of the project. + + + I began to research the most appropriate way of structuring this. I started of by redoing the implementation. This meant creating the following classes(Excluding DAOs): + + + + + LdapManager: Manages all LDAP connections. + + + + + LdapConfiguration: Supplies all configuration from within the Cloudstack database or defaults where required. + + + + + LdapUserManager: Handles any interaction with LDAP user information. + + + + + LdapUtils: Supplies static helpers, e.g. escape search queries, get attributes from search queries. + + + + + LdapContextFactory: Manages the creation of contexts. + + + + + LdapAuthenticator: Supplies an authenticator to Cloudstack using the LdapManager. + + + + + From this I had a solid foundation for creating API commands to allow the user to interact with an LDAP server. I went on to create the following commands: + + + + + LdapAddConfiguration - This allows for adding multiple LDAP configurations. Each configuration is just seen as a hostname and port. + + + + + + + add-ldap-configuration.png: Screenshot of API response. + + + + + + + + add-ldap-configuration-failure.png: Screenshot of API response. + + + + + + LdapDeleteConfiguration - This allows for the deletion of an LDAP configuration based on its hostname. + + + + + + + delete-ldap-configuration.png: Screenshot of API response. + + + + + + + + delete-ldap-configuration-failure.png: Screenshot of API response. + + + + + + LdapListConfiguration - This lists all of the LDAP configurations that exist within the database. + + + + + + + list-ldap-configuration.png: Screenshot of the build pipeline. + + + + + + LdapListAllUsers - This lists all the users within LDAP. + + + + + + + ldap-list-users.png: Screenshot of the build pipeline. + + + + + + Along with this global configuration options were added, this includes: + + + + + LDAP basedn: This allows the user to set the basedn for their LDAP configuration + + + + + LDAP bind password: This allows the user to set the password to use for binding to LDAP for creating the system context. If this is left blank along with bind principal then anonymous binding is used. + + + + + LDAP bind principal: This allows the user to set the principle to use for binding with LDAP for creating the system context. If this is left blank along with the bind password then anonymous binding is used. + + + + + LDAP email attribute: This sets out the attribute to use for getting the users email address. Within both OpenLDAP and ActiveDirectory this is mail. For this reason this is set to mail by default. + + + + + LDAP realname attribute: This sets out the attribute to use for getting the users realname. Within both OpenLDAP and ActiveDiretory this is cn. For this reason this is set to cn by default. + + + + + LDAP username attribute: This sets out the attribute to use for getting the users username. Within OpenLDAP this is uid and within ActiveDirectory this is samAccountName. In order to comply with posix standards this is set as uid by default. + + + + + LDAP user object: This sets out the object type of user accounts within LDAP. Within OpenLDAP this is inetOrgPerson and within ActiveDirectory this is user. Again, in order to comply with posix standards this is set as inetOrgperson by default. + + + + + With this implementation I believe it allows for a much more extendable and flexible approach. The whole implementation is abstracted from the Cloudstack codebase using the "plugin" model. This allows all of the LDAP features to be contained within one place. Along with this the implementation supplies a good foundation. A side affect of redoing the implementation allowed me to add support for multiple LDAP servers. This means failover is support, so for example, if you have a standard ActiveDirectory with primary and secondary domain controller. Both can be added to Cloudstack which will allow it to failover to either one assume one of them is down. + + + The API changes required me to update the UI interface within Cloudstack. With the improved API implementation this was easier. The Global Settings -> Ldap Configuration page has support for multiple LDAP servers however it only requires a hostname and port. All "global" ldap settings are set within the global settings page. + + + + + + + ldap-global-settings.png: Screenshot the LDAP related settings within global settings. + + + + + + + + ldap-configuration.png: Screenshot of the LDAP configuration page. + + +
+
+ Add accounts UI + + Extending the UI to allow for easy provisioning of LDAP users is currently a work in progress. At the moment I have a 'working' implementation, see below screenshot. I am in need of assistance with it and am waiting on a review to be looked at. + + + + + + + ldap-account-addition.png: Screenshot of add user screen when LDAP is enabled. + + +
+
+ Testing + + Unit tests have 92% code coverage within the LDAP Plugin. The unit tests were wrote in groovy using the spock framework. This allowed for a BDD style of of testing. + + + Integration tests have been wrote in python using the marvin test framework for Cloudstack. This test configures a LDAP server and attempts to login as an LDAP user. The plugin comes with an embedded LDAP server for testing purposes. + + Execute integration tests: + nosetests --with-marvin --marvin-config=setup/dev/local.cfg test/integration/component/test_ldap.py --loa + Start embedded LDAP server: + mvn -pl :cloud-plugin-user-authenticator-ldap ldap:run +
+
+ Conclusion + + I am very pleased with the learning outcomes of this project so far. I have been exposed to many things that my college's computer science curriculum does not cover. This includes: + + + + Usage of source control management tools(git) and dealing with code collaboration + + + Usage of a dependency manager and build tool(maven) + + + Usage of continous testing environments(jenkins) + + + Usage of an IDE(eclipse) + + + Exposure to testing, both unit and integration tests + + + Exposure to a functional programming language(groovy) + + + Exposure to web development libraries(jQuery) + + + + The experience gained from this project is invalueable and it is great that the Google Summer Of Code program exist. + +
diff --git a/docs/en-US/gsoc-midsummer.xml b/docs/en-US/gsoc-midsummer.xml index ffb031a90c7..74ca62a107e 100644 --- a/docs/en-US/gsoc-midsummer.xml +++ b/docs/en-US/gsoc-midsummer.xml @@ -11,9 +11,9 @@ 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 diff --git a/docs/en-US/images/add-ldap-configuration-failure.png b/docs/en-US/images/add-ldap-configuration-failure.png new file mode 100644 index 00000000000..4da295a8eb9 Binary files /dev/null and b/docs/en-US/images/add-ldap-configuration-failure.png differ diff --git a/docs/en-US/images/add-ldap-configuration.png b/docs/en-US/images/add-ldap-configuration.png new file mode 100644 index 00000000000..e041eb2a065 Binary files /dev/null and b/docs/en-US/images/add-ldap-configuration.png differ diff --git a/docs/en-US/images/delete-ldap-configuration-failure.png b/docs/en-US/images/delete-ldap-configuration-failure.png new file mode 100644 index 00000000000..b5b50e0b7e5 Binary files /dev/null and b/docs/en-US/images/delete-ldap-configuration-failure.png differ diff --git a/docs/en-US/images/delete-ldap.png b/docs/en-US/images/delete-ldap.png new file mode 100644 index 00000000000..c97bb4c47c3 Binary files /dev/null and b/docs/en-US/images/delete-ldap.png differ diff --git a/docs/en-US/images/jenkins-pipeline.png b/docs/en-US/images/jenkins-pipeline.png new file mode 100644 index 00000000000..0788c26a485 Binary files /dev/null and b/docs/en-US/images/jenkins-pipeline.png differ diff --git a/docs/en-US/images/ldap-account-addition.png b/docs/en-US/images/ldap-account-addition.png new file mode 100644 index 00000000000..0c8573ff9c9 Binary files /dev/null and b/docs/en-US/images/ldap-account-addition.png differ diff --git a/docs/en-US/images/ldap-configuration.png b/docs/en-US/images/ldap-configuration.png new file mode 100644 index 00000000000..c840e597e1b Binary files /dev/null and b/docs/en-US/images/ldap-configuration.png differ diff --git a/docs/en-US/images/ldap-global-settings.png b/docs/en-US/images/ldap-global-settings.png new file mode 100644 index 00000000000..0567de84374 Binary files /dev/null and b/docs/en-US/images/ldap-global-settings.png differ diff --git a/docs/en-US/images/ldap-list-users.png b/docs/en-US/images/ldap-list-users.png new file mode 100644 index 00000000000..aedcb0600b1 Binary files /dev/null and b/docs/en-US/images/ldap-list-users.png differ diff --git a/docs/en-US/images/list-ldap-configuration.png b/docs/en-US/images/list-ldap-configuration.png new file mode 100644 index 00000000000..6d75674c583 Binary files /dev/null and b/docs/en-US/images/list-ldap-configuration.png differ diff --git a/docs/en-US/removed-api-4.2.xml b/docs/en-US/removed-api-4.2.xml new file mode 100644 index 00000000000..cf4ab741cf3 --- /dev/null +++ b/docs/en-US/removed-api-4.2.xml @@ -0,0 +1,144 @@ + + +%BOOK_ENTITIES; +]> + +
+ Removed APIs + + + deleteCiscoNexusVSM (Deletes a Cisco Nexus VSM device) + + + enableCiscoNexusVSM (Enables a Cisco Nexus VSM device) + + + disableCiscoNexusVSM (Disables a Cisco Nexus VSM device) + + + listCiscoNexusVSMs (Retrieves a Cisco Nexus 1000v Virtual Switch Manager device + associated with a Cluster) + + + addBaremetalHost (Adds a new host.) + + + addExternalFirewall (Adds an external firewall appliance) + + + deleteExternalFirewall (Deletes an external firewall appliance.) + + + listExternalFirewalls (Lists external firewall appliances.) + + + addExternalLoadBalancer (Adds F5 external load balancer appliance.) + + + deleteExternalLoadBalancer (Deletes a F5 external load balancer appliance added in a + zone.) + + + listExternalLoadBalancers (Lists F5 external load balancer appliances added in a + zone.) + + + createVolumeOnFiler (Creates a volume.) + + + destroyVolumeOnFiler (Destroys a volume.) + + + listVolumesOnFiler (Lists volumes.) + + + createLunOnFiler (Creates a LUN from a pool.) + + + destroyLunOnFiler (Destroys a LUN.) + + + listLunsOnFiler (Lists LUN.) + + + associateLun (Associates a LUN with a guest IQN.) + + + dissociateLun (Dissociates a LUN.) + + + createPool (Creates a pool.) + + + deletePool (Deletes a pool.) + + + modifyPool (Modifies pool.) + + + listPools (Lists pool.) + + + addF5LoadBalancer (Adds a F5 BigIP load balancer device.) + + + configureF5LoadBalancer (Configures a F5 load balancer device.) + + + deleteF5LoadBalancer (Deletes a F5 load balancer device.) + + + listF5LoadBalancers (Lists F5 load balancer devices.) + + + listF5LoadBalancerNetworks (Lists network that are using a F5 load balancer device.) + + + + addSrxFirewall (Adds a SRX firewall device.) + + + deleteSrxFirewall (Deletes a SRX firewall device.) + + + configureSrxFirewall (Configures a SRX firewall device) + + + listSrxFirewalls (Lists SRX firewall devices in a physical network) + + + listSrxFirewallNetworks (Lists network that are using SRX firewall device) + + + addNetscalerLoadBalancer (Adds a netscaler load balancer device) + + + deleteNetscalerLoadBalancer (Deletes a netscaler load balancer device) + + + configureNetscalerLoadBalancer (Configures a netscaler load balancer device) + + + listNetscalerLoadBalancers (Lists netscaler load balancer devices) + + + listNetscalerLoadBalancerNetworks (Lists network that are using a netscaler load + balancer device) + + +
diff --git a/docs/en-US/whats-new.xml b/docs/en-US/whats-new.xml index 295b53220e1..c129c1e9ff5 100644 --- a/docs/en-US/whats-new.xml +++ b/docs/en-US/whats-new.xml @@ -25,6 +25,8 @@
What's New in the API for 4.2 + +
What's New in the API for 4.1 diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java index eccf0f4f6e1..54808c195c5 100644 --- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java +++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java @@ -23,7 +23,6 @@ import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.storage.StoragePool; import com.cloud.utils.component.Adapter; import com.cloud.vm.DiskProfile; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; /** @@ -44,7 +43,7 @@ public interface StoragePoolAllocator extends Adapter { * @return List List of storage pools that are suitable for the * VM **/ - List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, + List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo); static int RETURN_UPTO_ALL = -1; diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java index 6dd5844cbc9..204b832ab4a 100755 --- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java @@ -22,6 +22,9 @@ import java.util.UUID; import javax.inject.Inject; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; @@ -29,16 +32,14 @@ import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMEntityDao; import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner; -import com.cloud.deploy.DeploymentPlanningManager; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.deploy.DeploymentPlanningManager; import com.cloud.exception.AffinityConflictException; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; @@ -128,7 +129,7 @@ public class VMEntityManagerImpl implements VMEntityManager { } - protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) { + protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) { VirtualMachine vm = vmProfile.getVirtualMachine(); long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId()); @@ -146,7 +147,7 @@ public class VMEntityManagerImpl implements VMEntityManager { //load vm instance and offerings and call virtualMachineManagerImpl //FIXME: profile should work on VirtualMachineEntity VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm); DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null); if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){ plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId()); @@ -156,7 +157,7 @@ public class VMEntityManagerImpl implements VMEntityManager { List vols = _volsDao.findReadyRootVolumesByInstance(vm.getId()); if(!vols.isEmpty()){ VolumeVO vol = vols.get(0); - StoragePool pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(vol.getPoolId()); + StoragePool pool = (StoragePool)dataStoreMgr.getPrimaryDataStore(vol.getPoolId()); if (!pool.isInMaintenance()) { long rootVolDcId = pool.getDataCenterId(); @@ -224,8 +225,7 @@ public class VMEntityManagerImpl implements VMEntityManager { DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null); try { - VMInstanceVO vmDeployed = _itMgr.start(vm, params, _userDao.findById(new Long(caller)), - _accountDao.findById(vm.getAccountId()), reservedPlan); + _itMgr.start(vm.getUuid(), params, reservedPlan); } catch (Exception ex) { // Retry the deployment without using the reservation plan DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null); @@ -234,31 +234,27 @@ public class VMEntityManagerImpl implements VMEntityManager { plan.setAvoids(reservedPlan.getAvoids()); } - _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), - plan); + _itMgr.start(vm.getUuid(), params, plan); } } else { // no reservation found. Let VirtualMachineManager retry - _itMgr.start(vm, params, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), null); + _itMgr.start(vm.getUuid(), params, null); } } @Override public boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException { - - VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid()); - return _itMgr.stop(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId())); - + _itMgr.stop(vmEntityVO.getUuid()); + return true; } @Override public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException{ VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid()); - return _itMgr.destroy(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId())); - - + _itMgr.destroy(vm.getUuid()); + return true; } } diff --git a/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java index f8f25ea2582..b0cb85d40bf 100755 --- a/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java +++ b/engine/schema/src/com/cloud/offerings/NetworkOfferingVO.java @@ -436,4 +436,8 @@ public class NetworkOfferingVO implements NetworkOffering { public void setConcurrentConnections(Integer concurrent_connections) { this.concurrent_connections = concurrent_connections; } + + public void setPublicLb(boolean publicLb) { + this.publicLb = publicLb; + } } diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java index 0cf6b5b1109..d4b7b6d353b 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java @@ -90,6 +90,7 @@ public class Upgrade410to420 implements DbUpgrade { correctExternalNetworkDevicesSetup(conn); removeFirewallServiceFromSharedNetworkOfferingWithSGService(conn); fix22xKVMSnapshots(conn); + setKVMSnapshotFlag(conn); addIndexForAlert(conn); fixBaremetalForeignKeys(conn); // storage refactor related migration @@ -297,9 +298,46 @@ public class Upgrade410to420 implements DbUpgrade { */ } - private void updatePrimaryStore(Connection conn) { - PreparedStatement sql = null; - PreparedStatement sql2 = null; + //KVM snapshot flag: only turn on if Customers is using snapshot; + private void setKVMSnapshotFlag(Connection conn) { + s_logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); + PreparedStatement pstmt = null; + ResultSet rs = null; + try { + int numRows = 0; + pstmt = conn.prepareStatement("select count(*) from `cloud`.`snapshots` where hypervisor_type = 'KVM'"); + rs = pstmt.executeQuery(); + if(rs.next()){ + numRows = rs.getInt(1); + } + rs.close(); + pstmt.close(); + if (numRows > 0){ + //Add the configuration flag + pstmt = conn.prepareStatement("UPDATE `cloud`.`configuration` SET value = ? WHERE name = 'KVM.snapshot.enabled'"); + pstmt.setString(1, "true"); + pstmt.executeUpdate(); + } + } catch (SQLException e) { + throw new CloudRuntimeException("Failed to read the snapshot table for KVM upgrade. ", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + + if (pstmt != null) { + pstmt.close(); + } + } catch (SQLException e) { + } + } + s_logger.debug("Done set KVM snapshot flag. "); + } + + private void updatePrimaryStore(Connection conn) { + PreparedStatement sql = null; + PreparedStatement sql2 = null; try { sql = conn.prepareStatement("update storage_pool set storage_provider_name = ? , scope = ? where pool_type = 'Filesystem' or pool_type = 'LVM'"); sql.setString(1, DataStoreProvider.DEFAULT_PRIMARY); diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java index 8cbc6b64dea..e8f98e9ca26 100644 --- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -398,6 +398,10 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem Long oldHostId = vmi.getHostId(); Long oldUpdated = vmi.getUpdated(); Date oldUpdateDate = vmi.getUpdateTime(); + if ( newState.equals(oldState) && newHostId != null && newHostId.equals(oldHostId) ) { + // state is same, don't need to update + return true; + } SearchCriteria sc = StateChangeSearch.create(); sc.setParameters("id", vmi.getId()); diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java index 00c693f0b57..e17306a2b9c 100644 --- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java +++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java @@ -49,6 +49,8 @@ import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; +import com.cloud.agent.api.storage.MigrateVolumeAnswer; +import com.cloud.agent.api.storage.MigrateVolumeCommand; import com.cloud.agent.api.to.DataObjectType; import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataTO; @@ -64,6 +66,7 @@ import com.cloud.storage.DataStoreRole; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; import com.cloud.storage.VolumeManager; +import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.VMTemplateDao; @@ -330,6 +333,30 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } + protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) { + VolumeInfo volume = (VolumeInfo)srcData; + StoragePool destPool = (StoragePool)this.dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary); + MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool); + EndPoint ep = selector.select(volume.getDataStore()); + MigrateVolumeAnswer answer = (MigrateVolumeAnswer) ep.sendMessage(command); + + if (answer == null || !answer.getResult()) { + throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool); + } else { + // Update the volume details after migration. + VolumeVO volumeVo = this.volDao.findById(volume.getId()); + Long oldPoolId = volume.getPoolId(); + volumeVo.setPath(answer.getVolumePath()); + volumeVo.setFolder(destPool.getPath()); + volumeVo.setPodId(destPool.getPodId()); + volumeVo.setPoolId(destPool.getId()); + volumeVo.setLastPoolId(oldPoolId); + this.volDao.update(volume.getId(), volumeVo); + } + + return answer; + } + @Override public Void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback callback) { Answer answer = null; @@ -347,7 +374,12 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } else if (destData.getType() == DataObjectType.VOLUME && srcData.getType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary && destData.getDataStore().getRole() == DataStoreRole.Primary) { - answer = copyVolumeBetweenPools(srcData, destData); + if (srcData.getId() == destData.getId()) { + // The volume has to be migrated across storage pools. + answer = migrateVolumeToPool(srcData, destData); + } else { + answer = copyVolumeBetweenPools(srcData, destData); + } } else if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.SNAPSHOT) { answer = copySnapshot(srcData, destData); } else { diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java index e369c1c033e..be0ce4e6b99 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java @@ -100,6 +100,13 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory { @Override public TemplateInfo getTemplate(DataObject obj, DataStore store) { - return this.getTemplate(obj.getId(), store); + TemplateObject tmpObj = (TemplateObject) this.getTemplate(obj.getId(), store); + // carry over url set in passed in data object, for copyTemplate case + // where url is generated on demand and not persisted in DB. + // need to think of a more generic way to pass these runtime information + // carried through DataObject post 4.2 + TemplateObject origTmpl = (TemplateObject) obj; + tmpObj.setUrl(origTmpl.getUrl()); + return tmpObj; } } diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java index 89e09748ea3..851377e8d74 100755 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java @@ -27,10 +27,11 @@ import java.util.Random; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; + import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.log4j.Logger; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterVO; @@ -49,7 +50,6 @@ import com.cloud.user.Account; import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.DiskProfile; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator { @@ -99,12 +99,12 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement } protected abstract List select(DiskProfile dskCh, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo); @Override public List allocateToPool(DiskProfile dskCh, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { List pools = select(dskCh, vmProfile, plan, avoid, returnUpTo); return reOrder(pools, vmProfile, plan); @@ -144,7 +144,7 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement } protected List reOrder(List pools, - VirtualMachineProfile vmProfile, DeploymentPlan plan) { + VirtualMachineProfile vmProfile, DeploymentPlan plan) { if (pools == null) { return null; } diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java index 41afa837b52..b1105ba31a7 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java @@ -25,18 +25,18 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; +import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; + import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.offering.ServiceOffering; import com.cloud.storage.StoragePool; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.vm.DiskProfile; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @Component @@ -49,7 +49,7 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat DiskOfferingDao _diskOfferingDao; @Override - protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, + protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { s_logger.debug("ClusterScopeStoragePoolAllocator looking for storage pool"); @@ -91,7 +91,7 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat if (suitablePools.size() == returnUpTo) { break; } - StoragePool pol = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId()); + StoragePool pol = (StoragePool) dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, pol, dskCh, plan)) { suitablePools.add(pol); } else { diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java index 979ea73cd23..15b44071f81 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java @@ -49,7 +49,7 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl boolean _storagePoolCleanupEnabled; @Override - public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, + public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { s_logger.debug("GarbageCollectingStoragePoolAllocator looking for storage pool"); if (!_storagePoolCleanupEnabled) { diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java index 4056fe756a1..310f4a1ff64 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java @@ -65,7 +65,7 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { ConfigurationDao _configDao; @Override - protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, + protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { List suitablePools = new ArrayList(); diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/UseLocalForRootAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/UseLocalForRootAllocator.java index d0571382191..6d7ac9300a1 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/UseLocalForRootAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/UseLocalForRootAllocator.java @@ -42,7 +42,7 @@ public class UseLocalForRootAllocator extends LocalStoragePoolAllocator implemen @Override public List allocateToPool(DiskProfile dskCh, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { DataCenterVO dc = _dcDao.findById(plan.getDataCenterId()); if (!dc.isLocalStorageEnabled()) { diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java index 300d932a31c..0288b172ca2 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java @@ -56,7 +56,7 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { @Override protected List select(DiskProfile dskCh, - VirtualMachineProfile vmProfile, + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { s_logger.debug("ZoneWideStoragePoolAllocator to find storage pool"); List suitablePools = new ArrayList(); diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java index bbd6b6e12d1..c3f52ffcf29 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java +++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java @@ -191,8 +191,9 @@ public class DefaultEndPointSelector implements EndPointSelector { // we can arbitrarily pick one ssvm to do that task List ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId); if (ssAHosts == null || ssAHosts.isEmpty()) { + s_logger.info("No running ssvm is found, so command will be sent to LocalHostEndPoint"); return LocalHostEndpoint.getEndpoint(); // use local host as endpoint in - // case of no ssvm existing + // case of no ssvm existing } Collections.shuffle(ssAHosts); HostVO host = ssAHosts.get(0); diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 89313e4b338..5919c273bc2 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -639,7 +639,7 @@ public class VolumeServiceImpl implements VolumeService { srcVolume.processEvent(Event.OperationSuccessed); destVolume.processEvent(Event.OperationSuccessed, result.getAnswer()); - srcVolume.getDataStore().delete(srcVolume); + // srcVolume.getDataStore().delete(srcVolume); future.complete(res); } catch (Exception e) { res.setResult(e.toString()); @@ -1045,6 +1045,13 @@ public class VolumeServiceImpl implements VolumeService { List toBeDownloaded = new ArrayList(dbVolumes); for (VolumeDataStoreVO volumeStore : dbVolumes) { VolumeVO volume = _volumeDao.findById(volumeStore.getVolumeId()); + if (volume == null ){ + s_logger.warn("Volume_store_ref shows that volume " + volumeStore.getVolumeId() + " is on image store " + storeId + + ", but the volume is not found in volumes table, potentially some bugs in deleteVolume, so we just treat this volume to be deleted and mark it as destroyed"); + volumeStore.setDestroyed(true); + _volumeStoreDao.update(volumeStore.getId(), volumeStore); + continue; + } // Exists then don't download if (volumeInfos.containsKey(volume.getId())) { TemplateProp volInfo = volumeInfos.remove(volume.getId()); diff --git a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh index f2f8a49339e..a5b02398086 100755 --- a/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh +++ b/patches/systemvm/debian/config/opt/cloud/bin/vpc_ipassoc.sh @@ -76,8 +76,9 @@ add_an_ip () { if [ $old_state -eq 0 ] then sudo ip link set $ethDev up - sudo arping -c 3 -I $ethDev -A -U -s $pubIp $pubIp fi + sudo arping -c 1 -I $ethDev -A -U -s $pubIp $pubIp + sudo arping -c 1 -I $ethDev -A -U -s $pubIp $pubIp local tableNo=${ethDev:3} sudo iptables-save -t mangle | grep "PREROUTING -i $ethDev -m state --state NEW -j CONNMARK --set-xmark" 2>/dev/null if [ $? -gt 0 ] diff --git a/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java b/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java index a0eb56cbb8a..21693592e69 100644 --- a/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java +++ b/plugins/affinity-group-processors/explicit-dedication/src/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java @@ -23,9 +23,10 @@ import java.util.Set; import javax.ejb.Local; import javax.inject.Inject; +import org.apache.log4j.Logger; + import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; -import org.apache.log4j.Logger; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; @@ -82,7 +83,7 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement * This IncludeList is then used to update the avoid list for a given data center. */ @Override - public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, + public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException { VirtualMachine vm = vmProfile.getVirtualMachine(); List vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType()); diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java index 1569c7ecd69..c4a847d5e0b 100644 --- a/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java +++ b/plugins/affinity-group-processors/host-anti-affinity/src/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java @@ -66,7 +66,7 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements protected VMReservationDao _reservationDao; @Override - public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, + public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException { VirtualMachine vm = vmProfile.getVirtualMachine(); @@ -118,7 +118,7 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements } @Override - public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) + public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) throws AffinityConflictException { if (plannedDestination.getHost() == null) { diff --git a/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java b/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java index be016cb2507..6eee28d7a94 100644 --- a/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java +++ b/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java @@ -67,7 +67,7 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements Deploy } @Override - public List orderClusters(VirtualMachineProfile vmProfile, + public List orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { List clusterList = super.orderClusters(vmProfile, plan, avoid); Set hostsToAvoid = avoid.getHostsToAvoid(); @@ -251,7 +251,7 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements Deploy } @Override - public PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile, + public PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { // Check if strict or preferred mode should be used. boolean preferred = isServiceOfferingUsingPlannerInPreferredMode(vmProfile.getServiceOfferingId()); diff --git a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java index 02124a2ff20..73fd2490c29 100644 --- a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java +++ b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java @@ -176,8 +176,7 @@ public class ImplicitPlannerTest { public void checkWhenDcInAvoidList() throws InsufficientServerCapacityException { DataCenterVO mockDc = mock(DataCenterVO.class); ExcludeList avoids = mock(ExcludeList.class); - @SuppressWarnings("unchecked") - VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); + VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); VMInstanceVO vm = mock(VMInstanceVO.class); DataCenterDeployment plan = mock(DataCenterDeployment.class); @@ -193,8 +192,7 @@ public class ImplicitPlannerTest { @Test public void checkStrictModeWithCurrentAccountVmsPresent() throws InsufficientServerCapacityException { - @SuppressWarnings("unchecked") - VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); + VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); DataCenterDeployment plan = mock(DataCenterDeployment.class); ExcludeList avoids = new ExcludeList(); @@ -230,7 +228,7 @@ public class ImplicitPlannerTest { @Test public void checkStrictModeHostWithCurrentAccountVmsFull() throws InsufficientServerCapacityException { @SuppressWarnings("unchecked") - VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); + VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); DataCenterDeployment plan = mock(DataCenterDeployment.class); ExcludeList avoids = new ExcludeList(); @@ -268,7 +266,7 @@ public class ImplicitPlannerTest { @Test public void checkStrictModeNoHostsAvailable() throws InsufficientServerCapacityException { @SuppressWarnings("unchecked") - VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); + VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); DataCenterDeployment plan = mock(DataCenterDeployment.class); ExcludeList avoids = new ExcludeList(); @@ -289,7 +287,7 @@ public class ImplicitPlannerTest { @Test public void checkPreferredModePreferredHostAvailable() throws InsufficientServerCapacityException { @SuppressWarnings("unchecked") - VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); + VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); DataCenterDeployment plan = mock(DataCenterDeployment.class); ExcludeList avoids = new ExcludeList(); @@ -328,7 +326,7 @@ public class ImplicitPlannerTest { @Test public void checkPreferredModeNoHostsAvailable() throws InsufficientServerCapacityException { @SuppressWarnings("unchecked") - VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); + VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class); DataCenterDeployment plan = mock(DataCenterDeployment.class); ExcludeList avoids = new ExcludeList(); @@ -347,7 +345,7 @@ public class ImplicitPlannerTest { assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty())); } - private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDeployment plan) { + private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDeployment plan) { DataCenterVO mockDc = mock(DataCenterVO.class); VMInstanceVO vm = mock(VMInstanceVO.class); UserVmVO userVm = mock(UserVmVO.class); diff --git a/plugins/deployment-planners/user-concentrated-pod/src/com/cloud/deploy/UserConcentratedPodPlanner.java b/plugins/deployment-planners/user-concentrated-pod/src/com/cloud/deploy/UserConcentratedPodPlanner.java index d917893719e..2d734259ef5 100644 --- a/plugins/deployment-planners/user-concentrated-pod/src/com/cloud/deploy/UserConcentratedPodPlanner.java +++ b/plugins/deployment-planners/user-concentrated-pod/src/com/cloud/deploy/UserConcentratedPodPlanner.java @@ -41,7 +41,7 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo * @return List ordered list of Cluster Ids */ @Override - protected List reorderClusters(long id, boolean isZone, Pair, Map> clusterCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ + protected List reorderClusters(long id, boolean isZone, Pair, Map> clusterCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ List clusterIdsByCapacity = clusterCapacityInfo.first(); if(vmProfile.getOwner() == null || !isZone){ return clusterIdsByCapacity; @@ -118,7 +118,7 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo * @return List ordered list of Pod Ids */ @Override - protected List reorderPods(Pair, Map> podCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ + protected List reorderPods(Pair, Map> podCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ List podIdsByCapacity = podCapacityInfo.first(); if(vmProfile.getOwner() == null){ return podIdsByCapacity; diff --git a/plugins/deployment-planners/user-dispersing/src/com/cloud/deploy/UserDispersingPlanner.java b/plugins/deployment-planners/user-dispersing/src/com/cloud/deploy/UserDispersingPlanner.java index 2b0b1588802..d70eb319e42 100755 --- a/plugins/deployment-planners/user-dispersing/src/com/cloud/deploy/UserDispersingPlanner.java +++ b/plugins/deployment-planners/user-dispersing/src/com/cloud/deploy/UserDispersingPlanner.java @@ -46,7 +46,7 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment * @return List ordered list of Cluster Ids */ @Override - protected List reorderClusters(long id, boolean isZone, Pair, Map> clusterCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ + protected List reorderClusters(long id, boolean isZone, Pair, Map> clusterCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ List clusterIdsByCapacity = clusterCapacityInfo.first(); if(vmProfile.getOwner() == null){ return clusterIdsByCapacity; @@ -76,7 +76,7 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment * @return List ordered list of Pod Ids */ @Override - protected List reorderPods(Pair, Map> podCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ + protected List reorderPods(Pair, Map> podCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ List podIdsByCapacity = podCapacityInfo.first(); if(vmProfile.getOwner() == null){ return podIdsByCapacity; diff --git a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java index 303e438419a..d4a62779df1 100755 --- a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java +++ b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java @@ -47,13 +47,13 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { @Inject private ResourceManager _resourceMgr; @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) { return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true); } @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { long dcId = plan.getDataCenterId(); Long podId = plan.getPodId(); @@ -109,7 +109,7 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { } @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) { long dcId = plan.getDataCenterId(); diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalGuru.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalGuru.java index 03ba3fae61b..b2f12879bd0 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalGuru.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalGuru.java @@ -5,20 +5,20 @@ // 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. -// +// // Automatically generated by addcopyright.py at 01/29/2013 // Apache License, Version 2.0 (the "License"); you may not use this // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// +// // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.baremetal.manager; @@ -38,7 +38,6 @@ import com.cloud.hypervisor.HypervisorGuruBase; import com.cloud.storage.GuestOSVO; import com.cloud.storage.dao.GuestOSDao; import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.VMInstanceDao; @@ -59,7 +58,7 @@ public class BareMetalGuru extends HypervisorGuruBase implements HypervisorGuru } @Override - public VirtualMachineTO implement(VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); VMInstanceVO vo = _vmDao.findById(vm.getId()); diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java index e6ddcbeae41..cf3ceedfe81 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java @@ -23,20 +23,21 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.dc.*; -import com.cloud.dc.ClusterDetailsDao; import org.apache.log4j.Logger; import com.cloud.capacity.CapacityManager; -import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.ClusterDetailsDao; +import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenter; +import com.cloud.dc.Pod; import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner; -import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.host.Host; import com.cloud.host.HostVO; @@ -45,7 +46,6 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; import com.cloud.org.Cluster; import com.cloud.resource.ResourceManager; -import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @@ -63,7 +63,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { @Inject protected ClusterDetailsDao _clusterDetailsDao; @Override - public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { + public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { VirtualMachine vm = vmProfile.getVirtualMachine(); ServiceOffering offering = vmProfile.getServiceOffering(); String hostTag = null; @@ -143,7 +143,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { } @Override - public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { + public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { return vm.getHypervisorType() == HypervisorType.BareMetal; } @@ -163,7 +163,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { } @Override - public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude) { + public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude) { // TODO Auto-generated method stub return false; } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java index 77958ae6a1c..772898dca2b 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java @@ -5,20 +5,20 @@ // 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. -// +// // Automatically generated by addcopyright.py at 01/29/2013 // Apache License, Version 2.0 (the "License"); you may not use this // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// +// // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.baremetal.networkservice; @@ -31,10 +31,11 @@ import java.util.Map; import javax.ejb.Local; import javax.inject.Inject; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd; import org.apache.cloudstack.api.ListBaremetalPxePingServersCmd; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.baremetal.IpmISetBootDevCommand; @@ -68,7 +69,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachineProfile; @Local(value=BaremetalPxeService.class) @@ -82,7 +82,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements @Override - public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, DeployDestination dest, ReservationContext context) { + public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, DeployDestination dest, ReservationContext context) { SearchCriteriaService sc = SearchCriteria2.create(BaremetalPxeVO.class); sc.addAnd(sc.getEntity().getDeviceType(), Op.EQ, BaremetalPxeType.PING.toString()); sc.addAnd(sc.getEntity().getPodId(), Op.EQ, dest.getPod().getId()); @@ -127,7 +127,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements @Override - public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl) { + public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl) { List nics = _nicDao.listByVmId(vm.getId()); if (nics.size() != 1) { throw new CloudRuntimeException("Wrong nic number " + nics.size() + " of vm " + vm.getId()); @@ -168,7 +168,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements if (cmd.getPhysicalNetworkId() == null || cmd.getUrl() == null || cmd.getUsername() == null || cmd.getPassword() == null) { throw new IllegalArgumentException("At least one of the required parameters(physical network id, url, username, password) is null"); - } + } pNetwork = _physicalNetworkDao.findById(cmd.getPhysicalNetworkId()); if (pNetwork == null) { @@ -188,7 +188,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements HostPodVO pod = _podDao.findById(cmd.getPodId()); if (pod == null) { throw new IllegalArgumentException("Could not find pod with ID: " + cmd.getPodId()); - } + } List pxes = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.BaremetalPxe, null, cmd.getPodId(), zoneId); if (pxes.size() != 0) { diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java index 6d14e3f1a0c..7501882df28 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java @@ -76,7 +76,7 @@ public class BaremetaNetworkGuru extends DirectPodBasedNetworkGuru { PodVlanMapDao _podVlanDao; @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (dest.getHost().getHypervisorType() != HypervisorType.BareMetal) { super.reserve(nic, network, vm, dest, context); @@ -149,7 +149,7 @@ public class BaremetaNetworkGuru extends DirectPodBasedNetworkGuru { s_logger.debug("Allocated a nic " + nic + " for " + vm); } - private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network, String requiredIp) + private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network, String requiredIp) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(pod.getDataCenterId()); if (nic.getIp4Address() == null) { diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java index 96d702d7501..1eb1c74d2b3 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java @@ -103,7 +103,7 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv @Override @DB - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { Host host = dest.getHost(); if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) { @@ -122,7 +122,7 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; } @@ -158,7 +158,7 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv return true; } - public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (vm.getHypervisorType() != HypervisorType.BareMetal || !canHandle(dest, network.getTrafficType(), network.getGuestType())) { return false; @@ -167,7 +167,7 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv } @Override - public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { //TODO Add support for baremetal return true; } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManager.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManager.java index 9c007318368..8a83c329552 100644 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManager.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManager.java @@ -47,7 +47,7 @@ public interface BaremetalDhcpManager extends Manager, PluggableService { DHCPD, } - boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException; + boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException; BaremetalDhcpVO addDchpServer(AddBaremetalDhcpCmd cmd); diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java index 17e4481c535..1e2ad54157c 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java @@ -133,7 +133,7 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh } @Override - public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, + public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { Long zoneId = profile.getVirtualMachine().getDataCenterId(); Long podId = profile.getVirtualMachine().getPodIdToDeployIn(); diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java index 5858e7ebd61..9a6c1c69a11 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java @@ -5,9 +5,9 @@ // 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 @@ -27,10 +27,11 @@ import java.util.Map; import javax.ejb.Local; import javax.inject.Inject; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.ListBaremetalPxePingServersCmd; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.baremetal.IpmISetBootDevCommand; @@ -62,7 +63,6 @@ import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachineProfile; @Local(value = BaremetalPxeService.class) @@ -84,7 +84,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple VMTemplateDao _tmpDao; @Override - public boolean prepare(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) { + public boolean prepare(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) { NetworkVO nwVO = _nwDao.findById(nic.getNetworkId()); SearchCriteriaService sc = SearchCriteria2.create(BaremetalPxeVO.class); sc.addAnd(sc.getEntity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString()); diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java index 7b8d528b4b4..82094d8ff46 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeElement.java @@ -111,7 +111,7 @@ public class BaremetalPxeElement extends AdapterBase implements NetworkElement { @Override @DB - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) { return false; @@ -138,7 +138,7 @@ public class BaremetalPxeElement extends AdapterBase implements NetworkElement { } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManager.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManager.java index 7984ddd9750..73243b5657b 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManager.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManager.java @@ -5,20 +5,20 @@ // 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. -// +// // Automatically generated by addcopyright.py at 01/29/2013 // Apache License, Version 2.0 (the "License"); you may not use this // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// +// // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.baremetal.networkservice; @@ -37,7 +37,6 @@ import com.cloud.utils.component.Manager; import com.cloud.utils.component.PluggableService; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachineProfile; public interface BaremetalPxeManager extends Manager, PluggableService { @@ -58,7 +57,7 @@ public interface BaremetalPxeManager extends Manager, PluggableService { List listPxeServers(ListBaremetalPxePingServersCmd cmd); - boolean addUserData(NicProfile nic, VirtualMachineProfile vm); + boolean addUserData(NicProfile nic, VirtualMachineProfile vm); public static final Network.Service BAREMETAL_PXE_SERVICE = new Network.Service("BaremetalPxeService"); public static final String BAREMETAL_PXE_CAPABILITY = "BaremetalPxe"; diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java index 555adf792d0..4e9a11dcf96 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java @@ -5,20 +5,20 @@ // 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. -// +// // Automatically generated by addcopyright.py at 01/29/2013 // Apache License, Version 2.0 (the "License"); you may not use this // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// +// // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.baremetal.networkservice; @@ -31,11 +31,12 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; + import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd; import org.apache.cloudstack.api.ListBaremetalPxePingServersCmd; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -183,7 +184,7 @@ public class BaremetalPxeManagerImpl extends ManagerBase implements BaremetalPxe } @Override - public boolean addUserData(NicProfile nic, VirtualMachineProfile profile) { + public boolean addUserData(NicProfile nic, VirtualMachineProfile profile) { UserVmVO vm = (UserVmVO) profile.getVirtualMachine(); _vmDao.loadDetails(vm); diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeService.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeService.java index af6a6c8043c..d74e31d501b 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeService.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPxeService.java @@ -5,20 +5,20 @@ // 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. -// +// // Automatically generated by addcopyright.py at 01/29/2013 // Apache License, Version 2.0 (the "License"); you may not use this // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// +// // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.baremetal.networkservice; @@ -29,17 +29,15 @@ import org.apache.cloudstack.api.ListBaremetalPxePingServersCmd; import com.cloud.baremetal.database.BaremetalPxeVO; import com.cloud.deploy.DeployDestination; -import com.cloud.host.Host; import com.cloud.uservm.UserVm; import com.cloud.utils.component.Adapter; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachineProfile; public interface BaremetalPxeService extends Adapter { - public boolean prepare(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context); + public boolean prepare(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context); public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl); @@ -62,5 +60,5 @@ public interface BaremetalPxeService extends Adapter { public static final String PXE_PARAM_PING_STORAGE_SERVER_IP = "pingStorageServerIp"; public static final String PXE_PARAM_PING_ROOT_DIR = "pingDir"; public static final String PXE_PARAM_PING_STORAGE_SERVER_USERNAME = "pingStorageServerUserName"; - public static final String PXE_PARAM_PING_STORAGE_SERVER_PASSWORD = "pingStorageServerPassword"; + public static final String PXE_PARAM_PING_STORAGE_SERVER_PASSWORD = "pingStorageServerPassword"; } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalUserdataElement.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalUserdataElement.java index 49c6fd9b957..524db26d0ee 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalUserdataElement.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalUserdataElement.java @@ -72,7 +72,7 @@ public class BaremetalUserdataElement extends AdapterBase implements NetworkElem } @Override - public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (!canHandle(dest)) { return false; @@ -82,17 +82,17 @@ public class BaremetalUserdataElement extends AdapterBase implements NetworkElem return false; } - return pxeMgr.addUserData(nic, (VirtualMachineProfile) vm); + return pxeMgr.addUserData(nic, (VirtualMachineProfile) vm); } @Override - public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { + public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @Override - public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException { + public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @@ -115,14 +115,14 @@ public class BaremetalUserdataElement extends AdapterBase implements NetworkElem } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // TODO Auto-generated method stub return false; } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub return false; @@ -154,7 +154,7 @@ public class BaremetalUserdataElement extends AdapterBase implements NetworkElem @Override - public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) + public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; diff --git a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmFencer.java b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmFencer.java index 7aefcaa6f12..71d9d0b9ec7 100755 --- a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmFencer.java +++ b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmFencer.java @@ -31,12 +31,13 @@ import com.cloud.agent.api.FenceCommand; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.OperationTimedoutException; import com.cloud.ha.FenceBuilder; +import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; import com.cloud.resource.ResourceManager; +import com.cloud.utils.component.AdapterBase; +import com.cloud.vm.VirtualMachine; @Local(value=FenceBuilder.class) public class OvmFencer extends AdapterBase implements FenceBuilder { @@ -66,7 +67,7 @@ public class OvmFencer extends AdapterBase implements FenceBuilder { } @Override - public Boolean fenceOff(VMInstanceVO vm, HostVO host) { + public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.Ovm) { s_logger.debug("Don't know how to fence non Ovm hosts " + host.getHypervisorType()); return null; diff --git a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmGuru.java b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmGuru.java index cb2cb13f915..206454b1240 100755 --- a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmGuru.java +++ b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmGuru.java @@ -20,12 +20,11 @@ import javax.ejb.Local; import javax.inject.Inject; import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; import com.cloud.hypervisor.HypervisorGuruBase; -import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.GuestOSVO; import com.cloud.storage.dao.GuestOSDao; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @Local(value=HypervisorGuru.class) @@ -41,8 +40,7 @@ public class OvmGuru extends HypervisorGuruBase implements HypervisorGuru { } @Override - public VirtualMachineTO implement( - VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); to.setBootloader(vm.getBootLoaderType()); diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java index 57a38f1d3d8..8f36e1663e6 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java +++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/SimulatorGuru.java @@ -16,18 +16,17 @@ // under the License. package com.cloud.simulator; +import javax.ejb.Local; +import javax.inject.Inject; + import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; import com.cloud.hypervisor.HypervisorGuruBase; import com.cloud.storage.GuestOSVO; import com.cloud.storage.dao.GuestOSDao; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; -import javax.ejb.Local; -import javax.inject.Inject; - @Local(value=HypervisorGuru.class) public class SimulatorGuru extends HypervisorGuruBase implements HypervisorGuru { @@ -43,7 +42,7 @@ public class SimulatorGuru extends HypervisorGuruBase implements HypervisorGuru } @Override - public VirtualMachineTO implement(VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); // Determine the VM's OS description diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsManagerVO.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsManagerVO.java index 416ba959e32..45abf23edd3 100644 --- a/plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsManagerVO.java +++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsManagerVO.java @@ -5,9 +5,9 @@ // 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 @@ -27,6 +27,8 @@ import javax.persistence.Table; import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; +import com.cloud.utils.db.Encrypt; + @Entity @Table(name="ucs_manager") public class UcsManagerVO implements InternalIdentity, Identity { @@ -50,16 +52,19 @@ public class UcsManagerVO implements InternalIdentity, Identity { @Column(name="username") private String username; + @Encrypt @Column(name="password") private String password; - public long getId() { + @Override + public long getId() { return id; } public void setId(long id) { this.id = id; } - public String getUuid() { + @Override + public String getUuid() { return uuid; } public void setUuid(String uuid) { diff --git a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java index ee75f1b1a39..f9e2c5a039b 100755 --- a/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java +++ b/plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManagerImpl.java @@ -22,14 +22,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.AddUcsManagerCmd; import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd; import org.apache.cloudstack.api.ListUcsBladeCmd; @@ -39,7 +39,10 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UcsBladeResponse; import org.apache.cloudstack.api.response.UcsManagerResponse; import org.apache.cloudstack.api.response.UcsProfileResponse; +import org.apache.log4j.Logger; +import com.cloud.configuration.Config; +import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.ClusterDao; @@ -54,6 +57,7 @@ import com.cloud.ucs.database.UcsManagerVO; import com.cloud.ucs.structure.ComputeBlade; import com.cloud.ucs.structure.UcsCookie; import com.cloud.ucs.structure.UcsProfile; +import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.SearchCriteria2; @@ -83,11 +87,86 @@ public class UcsManagerImpl implements UcsManager { private HostDao hostDao; @Inject private DataCenterDao dcDao; + @Inject + private ConfigurationDao configDao; private final Map cookies = new HashMap(); private String name; private int runLevel; private Map params; + private ScheduledExecutorService syncBladesExecutor; + private int syncBladeInterval; + + private class SyncBladesThread implements Runnable { + + private void discoverNewBlades(Map previous, + Map now, UcsManagerVO mgr) { + for (Map.Entry e : now.entrySet()) { + String dn = e.getKey(); + if (previous.keySet().contains(dn)) { + continue; + } + + ComputeBlade nc = e.getValue(); + UcsBladeVO vo = new UcsBladeVO(); + vo.setDn(nc.getDn()); + vo.setUcsManagerId(mgr.getId()); + vo.setUuid(UUID.randomUUID().toString()); + bladeDao.persist(vo); + s_logger.debug(String.format("discovered a new UCS blade[dn:%s] during sync", nc.getDn())); + } + } + + private void decommissionFadedBlade(Map previous, Map now) { + for (Map.Entry e : previous.entrySet()) { + String dn = e.getKey(); + if (now.keySet().contains(dn)) { + continue; + } + + UcsBladeVO vo = e.getValue(); + bladeDao.remove(vo.getId()); + s_logger.debug(String.format("decommission faded blade[dn:%s] during sync", vo.getDn())); + } + } + + private void syncBlades(UcsManagerVO mgr) { + SearchCriteriaService q = SearchCriteria2.create(UcsBladeVO.class); + q.addAnd(q.getEntity().getUcsManagerId(), Op.EQ, mgr.getId()); + List pblades = q.list(); + if (pblades.isEmpty()) { + return; + } + + + Map previousBlades = new HashMap(pblades.size()); + for (UcsBladeVO b : pblades) { + previousBlades.put(b.getDn(), b); + } + + List cblades = listBlades(mgr.getId()); + Map currentBlades = new HashMap(cblades.size()); + for (ComputeBlade c : cblades) { + currentBlades.put(c.getDn(), c); + } + + discoverNewBlades(previousBlades, currentBlades, mgr); + decommissionFadedBlade(previousBlades, currentBlades); + } + + @Override + public void run() { + try { + List mgrs = ucsDao.listAll(); + for (UcsManagerVO mgr : mgrs) { + syncBlades(mgr); + } + } catch (Throwable t) { + s_logger.warn(t.getMessage(), t); + } + } + + } @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -96,6 +175,9 @@ public class UcsManagerImpl implements UcsManager { @Override public boolean start() { + syncBladeInterval = Integer.valueOf(configDao.getValue(Config.UCSSyncBladeInterval.key())); + syncBladesExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("UCS-SyncBlades")); + syncBladesExecutor.scheduleAtFixedRate(new SyncBladesThread(), syncBladeInterval, syncBladeInterval, TimeUnit.SECONDS); return true; } diff --git a/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/ListUcsManagerCmd.java b/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/ListUcsManagerCmd.java index 4d4473d2b8b..228fbcb7330 100755 --- a/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/ListUcsManagerCmd.java +++ b/plugins/hypervisors/ucs/src/org/apache/cloudstack/api/ListUcsManagerCmd.java @@ -36,6 +36,7 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UcsManagerResponse; +import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; @@ -50,7 +51,7 @@ import com.cloud.user.Account; public class ListUcsManagerCmd extends BaseListCmd { public static final Logger s_logger = Logger.getLogger(ListUcsManagerCmd.class); - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the zone id", required=true) + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, description="the zone id", entityType=ZoneResponse.class, required=true) private Long zoneId; @Inject diff --git a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java index 2ed5cafb8e4..dab5064b2d4 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java +++ b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java @@ -11,25 +11,22 @@ // 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 +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.ha; -import java.util.Map; - import javax.ejb.Local; -import javax.naming.ConfigurationException; -import com.cloud.host.HostVO; +import com.cloud.host.Host; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; @Local(value=FenceBuilder.class) public class VmwareFencer extends AdapterBase implements FenceBuilder { @Override - public Boolean fenceOff(VMInstanceVO vm, HostVO host) { + public Boolean fenceOff(VirtualMachine vm, Host host) { return null; } diff --git a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java index a7e67e1bbe1..e5ef5b799cc 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java +++ b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java @@ -11,18 +11,18 @@ // 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 +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.ha; import javax.ejb.Local; -import com.cloud.host.HostVO; +import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; @Local(value=Investigator.class) public class VmwareInvestigator extends AdapterBase implements Investigator { @@ -30,7 +30,7 @@ public class VmwareInvestigator extends AdapterBase implements Investigator { } @Override - public Status isAgentAlive(HostVO agent) { + public Status isAgentAlive(Host agent) { if(agent.getHypervisorType() == HypervisorType.VMware) return Status.Disconnected; @@ -38,7 +38,7 @@ public class VmwareInvestigator extends AdapterBase implements Investigator { } @Override - public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) { if(vm.getHypervisorType() == HypervisorType.VMware) return true; diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index b86b6d97b6f..78a596e9266 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -122,7 +122,7 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru { } @Override - public VirtualMachineTO implement(VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); to.setBootloader(BootloaderType.HVM); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index bbac725eb0e..c7f487e833e 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.concurrent.*; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; @@ -4073,33 +4074,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa return str.replace('/', '-'); } - // This methd can be used to determine if the datastore is active yet. - // When an iSCSI target is created on a host and that target already contains - // the metadata that represents a datastore, the datastore shows up within - // vCenter as existent, but not necessarily active. - // Call this method and pass in the datastore's name to wait, if necessary, - // for the datastore to become active. - private boolean datastoreFileExists(DatastoreMO dsMo, String volumeDatastorePath) { - for (int i = 0; i < 10; i++) { - try { - return dsMo.fileExists(volumeDatastorePath); - } - catch (Exception e) { - if (!e.getMessage().contains("is not accessible")) { - break; - } - } - - try { - Thread.sleep(5000); - } - catch (Exception e) { - } - } - - return false; - } - @Override public ManagedObjectReference handleDatastoreAndVmdkAttach(Command cmd, String iqn, String storageHost, int storagePort, String initiatorUsername, String initiatorPassword, String targetUsername, String targetPassword) throws Exception { @@ -4115,7 +4089,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa String volumeDatastorePath = String.format("[%s] %s.vmdk", dsMo.getName(), dsMo.getName()); - if (!datastoreFileExists(dsMo, volumeDatastorePath)) { + if (!dsMo.fileExists(volumeDatastorePath)) { String dummyVmName = getWorkerName(context, cmd, 0); VirtualMachineMO vmMo = prepareVolumeHostDummyVm(hyperHost, dsMo, dummyVmName); @@ -4209,6 +4183,126 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } } + private void addRemoveInternetScsiTargetsToAllHosts(final boolean add, final List lstTargets, + final List> lstHosts) throws Exception { + VmwareContext context = getServiceContext(); + + ExecutorService executorService = Executors.newFixedThreadPool(lstHosts.size()); + + final List exceptions = new ArrayList(); + + for (Pair hostPair : lstHosts) { + HostMO host = new HostMO(context, hostPair.first()); + HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO(); + + boolean iScsiHbaConfigured = false; + + for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) { + if (hba instanceof HostInternetScsiHba) { + // just finding an instance of HostInternetScsiHba means that we have found at least one configured iSCSI HBA + // at least one iSCSI HBA must be configured before a CloudStack user can use this host for iSCSI storage + iScsiHbaConfigured = true; + + final String iScsiHbaDevice = hba.getDevice(); + + final HostStorageSystemMO hss = hostStorageSystem; + + executorService.submit(new Thread() { + @Override + public void run() { + try { + if (add) { + hss.addInternetScsiStaticTargets(iScsiHbaDevice, lstTargets); + } + else { + hss.removeInternetScsiStaticTargets(iScsiHbaDevice, lstTargets); + } + + hss.rescanHba(iScsiHbaDevice); + hss.rescanVmfs(); + } + catch (Exception ex) { + synchronized (exceptions) { + exceptions.add(ex); + } + } + } + }); + } + } + + if (!iScsiHbaConfigured) { + throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage."); + } + } + + executorService.shutdown(); + + if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) { + throw new Exception("The system timed out before completing the task 'rescanAllHosts'."); + } + + if (exceptions.size() > 0) { + throw new Exception(exceptions.get(0).getMessage()); + } + } + + private void rescanAllHosts(final List> lstHosts) throws Exception { + VmwareContext context = getServiceContext(); + + ExecutorService executorService = Executors.newFixedThreadPool(lstHosts.size()); + + final List exceptions = new ArrayList(); + + for (Pair hostPair : lstHosts) { + HostMO host = new HostMO(context, hostPair.first()); + HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO(); + + boolean iScsiHbaConfigured = false; + + for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) { + if (hba instanceof HostInternetScsiHba) { + // just finding an instance of HostInternetScsiHba means that we have found at least one configured iSCSI HBA + // at least one iSCSI HBA must be configured before a CloudStack user can use this host for iSCSI storage + iScsiHbaConfigured = true; + + final String iScsiHbaDevice = hba.getDevice(); + + final HostStorageSystemMO hss = hostStorageSystem; + + executorService.submit(new Thread() { + @Override + public void run() { + try { + hss.rescanHba(iScsiHbaDevice); + hss.rescanVmfs(); + } + catch (Exception ex) { + synchronized (exceptions) { + exceptions.add(ex); + } + } + } + }); + } + } + + if (!iScsiHbaConfigured) { + throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage."); + } + } + + executorService.shutdown(); + + if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) { + throw new Exception("The system timed out before completing the task 'rescanAllHosts'."); + } + + if (exceptions.size() > 0) { + throw new Exception(exceptions.get(0).getMessage()); + } + } + private ManagedObjectReference createVmfsDatastore(VmwareHypervisorHost hyperHost, String datastoreName, String storageIpAddress, int storagePortNumber, String iqn, String chapName, String chapSecret, String mutualChapName, String mutualChapSecret) throws Exception { VmwareContext context = getServiceContext(); @@ -4242,80 +4336,46 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa lstTargets.add(target); - HostDatastoreSystemMO hostDatastoreSystem = null; - HostStorageSystemMO hostStorageSystem = null; + addRemoveInternetScsiTargetsToAllHosts(true, lstTargets, lstHosts); - final List threads = new ArrayList(); - final List exceptions = new ArrayList(); + rescanAllHosts(lstHosts); - for (Pair hostPair : lstHosts) { - HostMO host = new HostMO(context, hostPair.first()); - hostDatastoreSystem = host.getHostDatastoreSystemMO(); - hostStorageSystem = host.getHostStorageSystemMO(); + HostMO host = new HostMO(context, lstHosts.get(0).first()); + HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO(); - boolean iScsiHbaConfigured = false; - - for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) { - if (hba instanceof HostInternetScsiHba) { - // just finding an instance of HostInternetScsiHba means that we have found at least one configured iSCSI HBA - // at least one iSCSI HBA must be configured before a CloudStack user can use this host for iSCSI storage - iScsiHbaConfigured = true; - - final String iScsiHbaDevice = hba.getDevice(); - - final HostStorageSystemMO hss = hostStorageSystem; - - threads.add(new Thread() { - @Override - public void run() { - try { - hss.addInternetScsiStaticTargets(iScsiHbaDevice, lstTargets); - - hss.rescanHba(iScsiHbaDevice); - hss.rescanVmfs(); - } - catch (Exception ex) { - synchronized (exceptions) { - exceptions.add(ex); - } - } - } - }); - } - } - - if (!iScsiHbaConfigured) { - throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage."); - } - } - - for (Thread thread : threads) { - thread.start(); - } - - for (Thread thread : threads) { - thread.join(); - } - - if (exceptions.size() > 0) { - throw new Exception(exceptions.get(0).getMessage()); - } - - ManagedObjectReference morDs = hostDatastoreSystem.findDatastoreByName(iqn); + ManagedObjectReference morDs = hostDatastoreSystem.findDatastoreByName(datastoreName); if (morDs != null) { return morDs; } + rescanAllHosts(lstHosts); + + HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO(); List lstHostScsiDisks = hostDatastoreSystem.queryAvailableDisksForVmfs(); HostScsiDisk hostScsiDisk = getHostScsiDisk(hostStorageSystem.getStorageDeviceInfo().getScsiTopology(), lstHostScsiDisks, iqn); if (hostScsiDisk == null) { + // check to see if the datastore actually does exist already + morDs = hostDatastoreSystem.findDatastoreByName(datastoreName); + + if (morDs != null) { + return morDs; + } + throw new Exception("A relevant SCSI disk could not be located to use to create a datastore."); } - return hostDatastoreSystem.createVmfsDatastore(datastoreName, hostScsiDisk); + morDs = hostDatastoreSystem.createVmfsDatastore(datastoreName, hostScsiDisk); + + if (morDs != null) { + rescanAllHosts(lstHosts); + + return morDs; + } + + throw new Exception("Unable to create a datastore"); } // the purpose of this method is to find the HostScsiDisk in the passed-in array that exists (if any) because @@ -4363,46 +4423,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa lstTargets.add(target); - final List threads = new ArrayList(); - final List exceptions = new ArrayList(); + addRemoveInternetScsiTargetsToAllHosts(false, lstTargets, lstHosts); - for (Pair hostPair : lstHosts) { - final HostMO host = new HostMO(context, hostPair.first()); - final HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO(); - - for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) { - if (hba instanceof HostInternetScsiHba) { - final String iScsiHbaDevice = hba.getDevice(); - - Thread thread = new Thread() { - @Override - public void run() { - try { - hostStorageSystem.removeInternetScsiStaticTargets(iScsiHbaDevice, lstTargets); - - hostStorageSystem.rescanHba(iScsiHbaDevice); - hostStorageSystem.rescanVmfs(); - } - catch (Exception ex) { - exceptions.add(ex); - } - } - }; - - threads.add(thread); - - thread.start(); - } - } - } - - for (Thread thread : threads) { - thread.join(); - } - - if (exceptions.size() > 0) { - throw new Exception(exceptions.get(0).getMessage()); - } + rescanAllHosts(lstHosts); } protected Answer execute(AttachIsoCommand cmd) { diff --git a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java index 4629b6c2d3e..e1f4a274e29 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java +++ b/plugins/hypervisors/vmware/src/com/cloud/network/element/CiscoNexusVSMElement.java @@ -100,7 +100,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme @Override public boolean prepare(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -109,7 +109,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme @Override public boolean release(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; diff --git a/plugins/hypervisors/xen/src/com/cloud/ha/XenServerFencer.java b/plugins/hypervisors/xen/src/com/cloud/ha/XenServerFencer.java index 737b3b2890b..4708ff3e5bc 100755 --- a/plugins/hypervisors/xen/src/com/cloud/ha/XenServerFencer.java +++ b/plugins/hypervisors/xen/src/com/cloud/ha/XenServerFencer.java @@ -11,7 +11,7 @@ // 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 +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.ha; @@ -31,13 +31,14 @@ import com.cloud.agent.api.FenceAnswer; import com.cloud.agent.api.FenceCommand; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceManager; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; @Local(value=FenceBuilder.class) public class XenServerFencer extends AdapterBase implements FenceBuilder { @@ -49,7 +50,7 @@ public class XenServerFencer extends AdapterBase implements FenceBuilder { @Inject ResourceManager _resourceMgr; @Override - public Boolean fenceOff(VMInstanceVO vm, HostVO host) { + public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.XenServer) { s_logger.debug("Don't know how to fence non XenServer hosts " + host.getHypervisorType()); return null; diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java index c52020e84e8..6dd6f3fb422 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java @@ -11,7 +11,7 @@ // 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 +// KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. package com.cloud.hypervisor; @@ -24,9 +24,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.GuestOSVO; import com.cloud.storage.dao.GuestOSDao; import com.cloud.template.VirtualMachineTemplate.BootloaderType; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; -import com.cloud.vm.VirtualMachineProfileImpl; @Local(value=HypervisorGuru.class) public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru { @@ -42,7 +40,7 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru } @Override - public VirtualMachineTO implement(VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { BootloaderType bt = BootloaderType.PyGrub; if (vm.getBootLoaderType() == BootloaderType.CD) { bt = vm.getBootLoaderType(); diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index e360c984619..bbb077c3b2b 100755 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -579,7 +579,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L cluster.setGuid(startup.getPool()); _clusterDao.update(cluster.getId(), cluster); } else if (! cluster.getGuid().equals(startup.getPool()) ) { - String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + cmd.getPod(); + String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool(); s_logger.warn(msg); throw new CloudRuntimeException(msg); } diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index f80d4b62940..6462ff6c100 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -139,8 +139,6 @@ import com.cloud.agent.api.GetHostStatsAnswer; import com.cloud.agent.api.GetHostStatsCommand; import com.cloud.agent.api.GetStorageStatsAnswer; import com.cloud.agent.api.GetStorageStatsCommand; -import com.cloud.agent.api.GetVmDiskStatsAnswer; -import com.cloud.agent.api.GetVmDiskStatsCommand; import com.cloud.agent.api.GetVmStatsAnswer; import com.cloud.agent.api.GetVmStatsCommand; import com.cloud.agent.api.GetVncPortAnswer; @@ -195,7 +193,6 @@ import com.cloud.agent.api.UnPlugNicAnswer; import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.agent.api.UpgradeSnapshotCommand; -import com.cloud.agent.api.VmDiskStatsEntry; import com.cloud.agent.api.VmStatsEntry; import com.cloud.agent.api.check.CheckSshAnswer; import com.cloud.agent.api.check.CheckSshCommand; @@ -498,8 +495,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return execute((GetHostStatsCommand) cmd); } else if (clazz == GetVmStatsCommand.class) { return execute((GetVmStatsCommand) cmd); - } else if (cmd instanceof GetVmDiskStatsCommand) { - return execute((GetVmDiskStatsCommand) cmd); } else if (clazz == CheckHealthCommand.class) { return execute((CheckHealthCommand) cmd); } else if (clazz == StopCommand.class) { @@ -2636,80 +2631,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return hostStats; } - protected GetVmDiskStatsAnswer execute( GetVmDiskStatsCommand cmd) { - Connection conn = getConnection(); - List vmNames = cmd.getVmNames(); - HashMap> vmDiskStatsNameMap = new HashMap>(); - if( vmNames.size() == 0 ) { - return new GetVmDiskStatsAnswer(cmd, "", cmd.getHostName(),vmDiskStatsNameMap); - } - try { - - // Determine the UUIDs of the requested VMs - List vmUUIDs = new ArrayList(); - - for (String vmName : vmNames) { - VM vm = getVM(conn, vmName); - vmUUIDs.add(vm.getUuid(conn)); - } - - HashMap> vmDiskStatsUUIDMap = getVmDiskStats(conn, cmd, vmUUIDs, cmd.getHostGuid()); - if( vmDiskStatsUUIDMap == null ) { - return new GetVmDiskStatsAnswer(cmd, "", cmd.getHostName(), vmDiskStatsNameMap); - } - - for (String vmUUID : vmDiskStatsUUIDMap.keySet()) { - List vmDiskStatsUUID = vmDiskStatsUUIDMap.get(vmUUID); - String vmName = vmNames.get(vmUUIDs.indexOf(vmUUID)); - for (VmDiskStatsEntry vmDiskStat : vmDiskStatsUUID) { - vmDiskStat.setVmName(vmName); - } - vmDiskStatsNameMap.put(vmName, vmDiskStatsUUID); - } - - return new GetVmDiskStatsAnswer(cmd, "", cmd.getHostName(),vmDiskStatsNameMap); - } catch (XenAPIException e) { - String msg = "Unable to get VM disk stats" + e.toString(); - s_logger.warn(msg, e); - return new GetVmDiskStatsAnswer(cmd, "", cmd.getHostName(),vmDiskStatsNameMap); - } catch (XmlRpcException e) { - String msg = "Unable to get VM disk stats" + e.getMessage(); - s_logger.warn(msg, e); - return new GetVmDiskStatsAnswer(cmd, "", cmd.getHostName(),vmDiskStatsNameMap); - } - } - - private HashMap> getVmDiskStats(Connection conn, GetVmDiskStatsCommand cmd, List vmUUIDs, String hostGuid) { - HashMap> vmResponseMap = new HashMap>(); - - for (String vmUUID : vmUUIDs) { - vmResponseMap.put(vmUUID, new ArrayList()); - } - - try { - for (String vmUUID : vmUUIDs) { - VM vm = VM.getByUuid(conn, vmUUID); - List vmDiskStats = new ArrayList(); - for (VBD vbd : vm.getVBDs(conn)) { - if (!vbd.getType(conn).equals(Types.VbdType.CD)) { - VmDiskStatsEntry stats = new VmDiskStatsEntry(); - VBDMetrics record = vbd.getMetrics(conn); - stats.setPath(vbd.getVDI(conn).getUuid(conn)); - stats.setBytesRead((long)(record.getIoReadKbs(conn) * 1024)); - stats.setBytesWrite((long)(record.getIoWriteKbs(conn) * 1024)); - vmDiskStats.add(stats); - } - } - vmResponseMap.put(vmUUID, vmDiskStats); - } - } catch (Exception e) { - s_logger.warn("Error while collecting disk stats from : ", e); - return null; - } - - return vmResponseMap; - } - protected GetVmStatsAnswer execute( GetVmStatsCommand cmd) { Connection conn = getConnection(); List vmNames = cmd.getVmNames(); diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java index 411feab7339..54623e9d080 100644 --- a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java +++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/element/BigSwitchVnsElement.java @@ -182,7 +182,7 @@ public class BigSwitchVnsElement extends AdapterBase implements @Override public boolean prepare(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -228,7 +228,7 @@ public class BigSwitchVnsElement extends AdapterBase implements @Override public boolean release(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { diff --git a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java index f660b7c7838..52303a43fa1 100644 --- a/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java +++ b/plugins/network-elements/bigswitch-vns/src/com/cloud/network/guru/BigSwitchVnsGuestNetworkGuru.java @@ -211,7 +211,7 @@ public class BigSwitchVnsGuestNetworkGuru extends GuestNetworkGuru { @Override public void reserve(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { @@ -221,7 +221,7 @@ public class BigSwitchVnsGuestNetworkGuru extends GuestNetworkGuru { @Override public boolean release(NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, String reservationId) { // TODO Auto-generated method stub return super.release(nic, vm, reservationId); diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java index de52c21d405..5291ad18ab9 100644 --- a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java +++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/element/CiscoVnmcElement.java @@ -422,7 +422,7 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro @Override public boolean prepare(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -441,7 +441,7 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro @Override public boolean release(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; diff --git a/plugins/network-elements/dns-notifier/src/org/apache/cloudstack/network/element/DnsNotifier.java b/plugins/network-elements/dns-notifier/src/org/apache/cloudstack/network/element/DnsNotifier.java index c421344baba..4a403c4e658 100644 --- a/plugins/network-elements/dns-notifier/src/org/apache/cloudstack/network/element/DnsNotifier.java +++ b/plugins/network-elements/dns-notifier/src/org/apache/cloudstack/network/element/DnsNotifier.java @@ -71,7 +71,7 @@ public class DnsNotifier extends AdapterBase implements NetworkElement { } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // signal to the dns server that this vm is up and running and set the ip address to hostname mapping. vm.getHostName(); @@ -81,7 +81,7 @@ public class DnsNotifier extends AdapterBase implements NetworkElement { } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { vm.getHostName(); nic.getIp4Address(); nic.getIp6Address(); diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/element/ElasticLoadBalancerElement.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/element/ElasticLoadBalancerElement.java index 8b1b4140a8d..fd7274d8e2b 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/element/ElasticLoadBalancerElement.java +++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/element/ElasticLoadBalancerElement.java @@ -123,14 +123,14 @@ public class ElasticLoadBalancerElement extends AdapterBase implements LoadBalan } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { return true; } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java index 601b0343c22..7c0f87b3f9e 100644 --- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java +++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java @@ -127,7 +127,6 @@ import com.cloud.utils.net.Ip; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; -import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineGuru; @@ -140,10 +139,8 @@ import com.cloud.vm.dao.NicDao; @Component @Local(value = { ElasticLoadBalancerManager.class }) -public class ElasticLoadBalancerManagerImpl extends ManagerBase implements -ElasticLoadBalancerManager, VirtualMachineGuru { - private static final Logger s_logger = Logger - .getLogger(ElasticLoadBalancerManagerImpl.class); +public class ElasticLoadBalancerManagerImpl extends ManagerBase implements ElasticLoadBalancerManager, VirtualMachineGuru { + private static final Logger s_logger = Logger.getLogger(ElasticLoadBalancerManagerImpl.class); @Inject IPAddressDao _ipAddressDao; @@ -538,21 +535,15 @@ ElasticLoadBalancerManager, VirtualMachineGuru { private DomainRouterVO start(DomainRouterVO elbVm, User user, Account caller, Map params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting ELB VM " + elbVm); - if (_itMgr.start(elbVm, params, user, caller) != null) { - return _routerDao.findById(elbVm.getId()); - } else { - return null; - } + _itMgr.start(elbVm.getUuid(), params); + return _routerDao.findById(elbVm.getId()); } private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Stopping ELB vm " + elbVm); try { - if (_itMgr.advanceStop( elbVm, forced, user, caller)) { - return _routerDao.findById(elbVm.getId()); - } else { - return null; - } + _itMgr.advanceStop(elbVm.getUuid(), forced); + return _routerDao.findById(elbVm.getId()); } catch (OperationTimedoutException e) { throw new CloudRuntimeException("Unable to stop " + elbVm, e); } @@ -781,13 +772,7 @@ ElasticLoadBalancerManager, VirtualMachineGuru { } @Override - public DomainRouterVO findById(long id) { - return _routerDao.findById(id); - } - - @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - DomainRouterVO elbVm = profile.getVirtualMachine(); + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { List elbNics = profile.getNics(); Long guestNtwkId = null; @@ -867,8 +852,8 @@ ElasticLoadBalancerManager, VirtualMachineGuru { } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { - DomainRouterVO elbVm = profile.getVirtualMachine(); + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { + DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId()); List nics = profile.getNics(); for (NicProfile nic : nics) { @@ -888,7 +873,7 @@ ElasticLoadBalancerManager, VirtualMachineGuru { } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh"); if (answer == null || !answer.getResult()) { s_logger.warn("Unable to ssh to the ELB VM: " + answer.getDetails()); @@ -899,8 +884,8 @@ ElasticLoadBalancerManager, VirtualMachineGuru { } @Override - public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - DomainRouterVO elbVm = profile.getVirtualMachine(); + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId()); DataCenterVO dcVo = _dcDao.findById(elbVm.getDataCenterId()); NicProfile controlNic = null; @@ -953,10 +938,9 @@ ElasticLoadBalancerManager, VirtualMachineGuru { } @Override - public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { if (answer != null) { - VMInstanceVO vm = profile.getVirtualMachine(); - DomainRouterVO elbVm = _routerDao.findById(vm.getId()); + DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId()); processStopOrRebootAnswer(elbVm, answer); } } @@ -966,13 +950,13 @@ ElasticLoadBalancerManager, VirtualMachineGuru { } @Override - public void finalizeExpunge(DomainRouterVO vm) { + public void finalizeExpunge(VirtualMachine vm) { // no-op } @Override - public void prepareStop(VirtualMachineProfile profile) { + public void prepareStop(VirtualMachineProfile profile) { } } diff --git a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java index 80b42e030d8..8ea4d61d9d9 100644 --- a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java +++ b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java @@ -159,13 +159,13 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan } @Override - public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException { return true; } @Override - public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { + public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { return true; } diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java index 18ac13baef4..2376038b135 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java @@ -170,7 +170,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (!canHandle(network, null)) { @@ -218,7 +218,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; } diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java index 06d3f708ac1..1799e60fed1 100644 --- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java +++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java @@ -120,7 +120,7 @@ import com.cloud.vm.dao.NicDao; @Component @Local(value = { InternalLoadBalancerVMManager.class, InternalLoadBalancerVMService.class}) public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements - InternalLoadBalancerVMManager, VirtualMachineGuru { + InternalLoadBalancerVMManager, VirtualMachineGuru { private static final Logger s_logger = Logger .getLogger(InternalLoadBalancerVMManagerImpl.class); static final private String _internalLbVmNamePrefix = "b"; @@ -151,12 +151,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements @Inject ConfigurationServer _configServer; @Override - public DomainRouterVO findById(long id) { - return _internalLbVmDao.findById(id); - } - - @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { //Internal LB vm starts up with 2 Nics @@ -231,8 +226,9 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { - DomainRouterVO internalLbVm = profile.getVirtualMachine(); + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { + + DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId()); List nics = profile.getNics(); for (NicProfile nic : nics) { @@ -248,8 +244,8 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { - DomainRouterVO internalLbVm = profile.getVirtualMachine(); + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { + DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId()); boolean result = true; @@ -297,8 +293,8 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements } @Override - public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - DomainRouterVO internalLbVm = profile.getVirtualMachine(); + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId()); NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control); if (controlNic == null) { @@ -334,15 +330,15 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements } @Override - public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { } @Override - public void finalizeExpunge(DomainRouterVO vm) { + public void finalizeExpunge(VirtualMachine vm) { } @Override - public void prepareStop(VirtualMachineProfile profile) { + public void prepareStop(VirtualMachineProfile profile) { } @Override @@ -391,7 +387,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements return _name; } - protected NicProfile getNicProfileByTrafficType(VirtualMachineProfile profile, TrafficType trafficType) { + protected NicProfile getNicProfileByTrafficType(VirtualMachineProfile profile, TrafficType trafficType) { for (NicProfile nic : profile.getNics()) { if (nic.getTrafficType() == trafficType && nic.getIp4Address() != null) { return nic; @@ -400,7 +396,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements return null; } - protected void finalizeSshAndVersionOnStart(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, NicProfile controlNic) { + protected void finalizeSshAndVersionOnStart(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, NicProfile controlNic) { cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922)); // Update internal lb vm template/scripts version @@ -467,7 +463,7 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements maxconn = offering.getConcurrentConnections().toString(); } LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, guestNic.getIp4Address(), - guestNic.getIp4Address(), internalLbVm.getPrivateIpAddress(), + guestNic.getIp4Address(), internalLbVm.getPrivateIpAddress(), _itMgr.toNicTO(guestNicProfile, internalLbVm.getHypervisorType()), internalLbVm.getVpcId(), maxconn); cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key()); @@ -538,11 +534,8 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements protected VirtualRouter stopInternalLbVm(DomainRouterVO internalLbVm, boolean forced, Account caller, long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException { s_logger.debug("Stopping internal lb vm " + internalLbVm); try { - if (_itMgr.advanceStop(internalLbVm, forced, _accountMgr.getActiveUser(callerUserId), caller)) { - return _internalLbVmDao.findById(internalLbVm.getId()); - } else { - return null; - } + _itMgr.advanceStop(internalLbVm.getUuid(), forced); + return _internalLbVmDao.findById(internalLbVm.getId()); } catch (OperationTimedoutException e) { throw new CloudRuntimeException("Unable to stop " + internalLbVm, e); } @@ -815,16 +808,13 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting Internal LB VM " + internalLbVm); - if (_itMgr.start(internalLbVm, params, _accountMgr.getUserIncludingRemoved(callerUserId), caller, null) != null) { - if (internalLbVm.isStopPending()) { - s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!"); - internalLbVm.setStopPending(false); - internalLbVm = _internalLbVmDao.persist(internalLbVm); - } - return _internalLbVmDao.findById(internalLbVm.getId()); - } else { - return null; + _itMgr.start(internalLbVm.getUuid(), params, null); + if (internalLbVm.isStopPending()) { + s_logger.info("Clear the stop pending flag of Internal LB VM " + internalLbVm.getHostName() + " after start router successfully!"); + internalLbVm.setStopPending(false); + internalLbVm = _internalLbVmDao.persist(internalLbVm); } + return _internalLbVmDao.findById(internalLbVm.getId()); } diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java index 70dafa307e4..f6a92dd993f 100644 --- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java +++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.internallbvmmgr; import java.lang.reflect.Field; -import java.util.Map; import javax.inject.Inject; @@ -34,11 +33,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService; -import com.cloud.deploy.DeploymentPlan; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; -import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -46,10 +43,8 @@ import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; -import com.cloud.user.Account; import com.cloud.user.AccountManager; import com.cloud.user.AccountVO; -import com.cloud.user.User; import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.utils.component.ComponentContext; @@ -112,31 +107,6 @@ public class InternalLBVMServiceTest extends TestCase { Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm); Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null); Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm); - - try { - Mockito.when(_itMgr.start(Mockito.any(DomainRouterVO.class), - Mockito.any(Map.class), Mockito.any(User.class), Mockito.any(Account.class), Mockito.any(DeploymentPlan.class))).thenReturn(validVm); - } catch (InsufficientCapacityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ResourceUnavailableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - try { - Mockito.when(_itMgr.advanceStop(Mockito.any(DomainRouterVO.class), Mockito.any(Boolean.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true); - } catch (ResourceUnavailableException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (OperationTimedoutException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ConcurrentOperationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } @Override diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java b/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java index c00d99abf88..85d6de6817b 100644 --- a/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java +++ b/plugins/network-elements/juniper-srx/src/com/cloud/network/element/JuniperSRXExternalFirewallElement.java @@ -145,13 +145,13 @@ PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer, Junip } @Override - public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException { return true; } @Override - public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { + public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { return true; } diff --git a/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java b/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java index ab6a6def405..b02e51ddb2c 100644 --- a/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java +++ b/plugins/network-elements/midonet/src/com/cloud/network/element/MidoNetElement.java @@ -391,7 +391,7 @@ public class MidoNetElement extends AdapterBase implements * From interface DHCPServiceProvider */ @Override - public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { @@ -455,7 +455,7 @@ public class MidoNetElement extends AdapterBase implements } @Override - public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { + public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { return false; //To change body of implemented methods use File | Settings | File Templates. } @@ -768,7 +768,7 @@ public class MidoNetElement extends AdapterBase implements } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { s_logger.debug("prepare called with network: " + network.toString() + " nic: " + nic.toString() + " vm: " + vm.toString()); @@ -832,7 +832,7 @@ public class MidoNetElement extends AdapterBase implements } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("release called with network: " + network.toString() + " nic: " + nic.toString() + " vm: " + vm.toString()); diff --git a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java index d57affc5827..ac77cf6e07e 100644 --- a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java +++ b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetGuestNetworkGuru.java @@ -145,7 +145,7 @@ public class MidoNetGuestNetworkGuru extends GuestNetworkGuru { @Override public void reserve(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { @@ -156,7 +156,7 @@ public class MidoNetGuestNetworkGuru extends GuestNetworkGuru { @Override public boolean release(NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, String reservationId) { s_logger.debug("release called with nic: " + nic.toString() + " vm: " + vm.toString()); return super.release(nic, vm, reservationId); diff --git a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java index 1daf0bad040..38da02bf6f9 100644 --- a/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java +++ b/plugins/network-elements/midonet/src/com/cloud/network/guru/MidoNetPublicNetworkGuru.java @@ -78,7 +78,7 @@ public class MidoNetPublicNetworkGuru extends PublicNetworkGuru { super(); } - protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, + protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (nic.getIp4Address() == null) { PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), Vlan.VlanType.VirtualNetwork, null, null, false); @@ -117,7 +117,7 @@ public class MidoNetPublicNetworkGuru extends PublicNetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { @@ -148,7 +148,7 @@ public class MidoNetPublicNetworkGuru extends PublicNetworkGuru { } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { s_logger.debug("reserve called with network: " + network.toString() + " nic: " + nic.toString() + " vm: " + vm.toString()); if (nic.getIp4Address() == null) { @@ -157,7 +157,7 @@ public class MidoNetPublicNetworkGuru extends PublicNetworkGuru { } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { s_logger.debug("release called with nic: " + nic.toString() + " vm: " + vm.toString()); return true; } @@ -189,7 +189,7 @@ public class MidoNetPublicNetworkGuru extends PublicNetworkGuru { } @Override @DB - public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { s_logger.debug("deallocate called with network: " + network.toString() + " nic: " + nic.toString() + " vm: " + vm.toString()); if (s_logger.isDebugEnabled()) { s_logger.debug("public network deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address()); diff --git a/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java b/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java index a7d96b0c310..9023c6eefce 100644 --- a/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java +++ b/plugins/network-elements/midonet/test/com/cloud/network/element/MidoNetElementTest.java @@ -97,8 +97,8 @@ public class MidoNetElementTest extends TestCase { //mockVm @SuppressWarnings("unchecked") - VirtualMachineProfile mockVm = - (VirtualMachineProfile)mock(VirtualMachineProfile.class); + VirtualMachineProfile mockVm = + (VirtualMachineProfile)mock(VirtualMachineProfile.class); when(mockVm.getType()).thenReturn(VirtualMachine.Type.User); MidoNetElement elem = new MidoNetElement(); diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java index e7f634772fc..fa51fdcbb8b 100644 --- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java +++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java @@ -200,13 +200,13 @@ public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl impl } @Override - public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException, ResourceUnavailableException { return true; } @Override - public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { + public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { return true; } diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java index c22f669796c..754e7b1c1db 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java @@ -296,7 +296,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer { @Override public boolean prepare(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -373,7 +373,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer { @Override public boolean release(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java index b78d165ddd6..ff238edc600 100644 --- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java +++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java @@ -212,7 +212,7 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru { @Override public void reserve(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { @@ -222,7 +222,7 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru { @Override public boolean release(NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, String reservationId) { // TODO Auto-generated method stub return super.release(nic, vm, reservationId); diff --git a/plugins/network-elements/ovs/src/com/cloud/network/element/OvsElement.java b/plugins/network-elements/ovs/src/com/cloud/network/element/OvsElement.java index 40be5ff7b45..0366143a7e7 100644 --- a/plugins/network-elements/ovs/src/com/cloud/network/element/OvsElement.java +++ b/plugins/network-elements/ovs/src/com/cloud/network/element/OvsElement.java @@ -72,7 +72,7 @@ public class OvsElement extends AdapterBase implements NetworkElement { @Override public boolean prepare(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -92,7 +92,7 @@ public class OvsElement extends AdapterBase implements NetworkElement { @Override public boolean release(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) { diff --git a/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManager.java b/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManager.java index 2a2a935d65a..36fd25fbea3 100644 --- a/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManager.java +++ b/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManager.java @@ -26,7 +26,7 @@ public interface OvsTunnelManager extends Manager { boolean isOvsTunnelEnabled(); - public void VmCheckAndCreateTunnel(VirtualMachineProfile vm, + public void VmCheckAndCreateTunnel(VirtualMachineProfile vm, Network nw, DeployDestination dest); public void CheckAndDestroyTunnel(VirtualMachine vm, Network nw); diff --git a/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java b/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java index b1ecaaccd76..d3db89fb1c5 100644 --- a/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java +++ b/plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsTunnelManagerImpl.java @@ -383,7 +383,7 @@ public class OvsTunnelManagerImpl extends ManagerBase implements OvsTunnelManage @Override public void VmCheckAndCreateTunnel( - VirtualMachineProfile vm, + VirtualMachineProfile vm, Network nw, DeployDestination dest) { CheckAndCreateTunnel(vm.getVirtualMachine(), nw, dest); } diff --git a/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspElement.java b/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspElement.java index 823c16b15e8..6e1461a9778 100644 --- a/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspElement.java +++ b/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/element/SspElement.java @@ -509,7 +509,7 @@ public class SspElement extends AdapterBase implements ConnectivityProvider, Ssp */ @Override public boolean prepare(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { @@ -526,7 +526,7 @@ public class SspElement extends AdapterBase implements ConnectivityProvider, Ssp */ @Override public boolean release(Network network, NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.trace("release"); @@ -569,7 +569,7 @@ public class SspElement extends AdapterBase implements ConnectivityProvider, Ssp @Override public boolean prepareMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) { try { prepare(network, nic, vm, dest, context); @@ -588,7 +588,7 @@ public class SspElement extends AdapterBase implements ConnectivityProvider, Ssp @Override public void rollbackMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { try { release(network, nic, vm, dst); @@ -601,7 +601,7 @@ public class SspElement extends AdapterBase implements ConnectivityProvider, Ssp @Override public void commitMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { try { release(network, nic, vm, src); diff --git a/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java b/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java index 6d5d871eb99..3deded92632 100644 --- a/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java +++ b/plugins/network-elements/stratosphere-ssp/src/org/apache/cloudstack/network/guru/SspGuestNetworkGuru.java @@ -119,7 +119,7 @@ public class SspGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr @Override public void reserve(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { @@ -129,7 +129,7 @@ public class SspGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr @Override public boolean release(NicProfile nic, - VirtualMachineProfile vm, + VirtualMachineProfile vm, String reservationId) { Network network = _networkDao.findById(nic.getNetworkId()); _sspMgr.deleteNicEnv(network, nic, new ReservationContextImpl(reservationId, null, null)); @@ -143,7 +143,7 @@ public class SspGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr @Override public boolean prepareMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) { try { reserve(nic, network, vm, dest, context); @@ -159,14 +159,14 @@ public class SspGuestNetworkGuru extends GuestNetworkGuru implements NetworkMigr @Override public void rollbackMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { release(nic, vm, dst.getReservationId()); } @Override public void commitMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { release(nic, vm, src.getReservationId()); } diff --git a/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java b/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java index fda787f479d..025a9693f98 100644 --- a/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java +++ b/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java @@ -38,7 +38,7 @@ public class RandomStoragePoolAllocator extends AbstractStoragePoolAllocator { private static final Logger s_logger = Logger.getLogger(RandomStoragePoolAllocator.class); @Override - public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, + public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { List suitablePools = new ArrayList(); diff --git a/server/src/com/cloud/agent/manager/AgentAttache.java b/server/src/com/cloud/agent/manager/AgentAttache.java index 2cedc4d474f..92ce17bc6d3 100755 --- a/server/src/com/cloud/agent/manager/AgentAttache.java +++ b/server/src/com/cloud/agent/manager/AgentAttache.java @@ -337,26 +337,14 @@ public abstract class AgentAttache { checkAvailability(req.getCommands()); long seq = req.getSequence(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Request seq: " + seq); - } - if (listener != null) { registerListener(seq, listener); } else if (s_logger.isDebugEnabled()) { s_logger.debug(log(seq, "Routed from " + req.getManagementServerId())); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("waiting to send " + seq); - } - synchronized(this) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("entering synchronize block for sending " + seq); - } - if (isClosed()) { throw new AgentUnavailableException("The link to the agent has been closed", _id); } diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index edc0d9d4c5c..46b864485fe 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -538,9 +538,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } Request req = new Request(hostId, _nodeId, cmds, commands.stopOnError(), true); req.setSequence(agent.getNextSequence()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("AgentManager sending request"); - } + agent.send(req, listener); return req.getSequence(); } diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java index 4329c7017e6..088591fee8d 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java @@ -105,13 +105,13 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { CapacityManager _capacityMgr; @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) { return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true); } @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) { long dcId = plan.getDataCenterId(); @@ -195,7 +195,7 @@ public class FirstFitAllocator extends AdapterBase implements HostAllocator { } @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { long dcId = plan.getDataCenterId(); Long podId = plan.getPodId(); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitRoutingAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitRoutingAllocator.java index 102c6a56358..912a3257046 100644 --- a/server/src/com/cloud/agent/manager/allocator/impl/FirstFitRoutingAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/FirstFitRoutingAllocator.java @@ -32,7 +32,7 @@ import com.cloud.vm.VirtualMachineProfile; @Local(value={HostAllocator.class}) public class FirstFitRoutingAllocator extends FirstFitAllocator { @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) { try { NDC.push("FirstFitRoutingAllocator"); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/RecreateHostAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/RecreateHostAllocator.java index 3b659c02741..bb4051f94c4 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/RecreateHostAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/RecreateHostAllocator.java @@ -69,7 +69,7 @@ public class RecreateHostAllocator extends FirstFitRoutingAllocator { @Inject ResourceManager _resourceMgr; @Override - public List allocateTo(VirtualMachineProfile vm,DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vm,DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) { List hosts = super.allocateTo(vm, plan, type, avoid, returnUpTo); diff --git a/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java index 3c69694346c..6b586d11694 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/TestingAllocator.java @@ -42,19 +42,19 @@ public class TestingAllocator extends AdapterBase implements HostAllocator { Long _routingHost; @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) { return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true); } @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { return allocateTo(vmProfile, plan, type, avoid, returnUpTo, considerReservedCapacity); } @Override - public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, + public List allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) { List availableHosts = new ArrayList(); Host host = null; diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 9b7cd274a2e..bff36c711fc 100755 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -502,6 +502,18 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { } } + private float getOverProvisioningFactor(long clusterId, short capacityType) { + float overProvisioinigFactor = 1f; + switch (capacityType) { + case Capacity.CAPACITY_TYPE_CPU: + overProvisioinigFactor = Float.parseFloat(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), clusterId)); + break; + case Capacity.CAPACITY_TYPE_MEMORY: + overProvisioinigFactor = Float.parseFloat(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(), Config.ConfigurationParameterScope.cluster.toString(), clusterId)); + break; + } + return overProvisioinigFactor; + } public void checkForAlerts(){ @@ -561,28 +573,27 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { for( ClusterVO cluster : clusterList){ for (Short capacityType : clusterCapacityTypes){ List capacity = new ArrayList(); - float overProvFactor = 1f; + float overProvFactor = getOverProvisioningFactor(cluster.getId(), capacityType); capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId()); // cpu and memory allocated capacity notification threshold can be defined at cluster level, so getting the value if they are defined at cluster level - double capacityValue = 0; + double threshold = 0; switch (capacityType) { case Capacity.CAPACITY_TYPE_STORAGE: capacity.add(getUsedStats(capacityType, cluster.getDataCenterId(), cluster.getPodId(), cluster.getId())); - capacityValue = Double.parseDouble(_configServer.getConfigValue(Config.StorageCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); break; case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED: - capacityValue = Double.parseDouble(_configServer.getConfigValue(Config.StorageAllocatedCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = Double.parseDouble(_configServer.getConfigValue(Config.StorageAllocatedCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); break; case Capacity.CAPACITY_TYPE_CPU: - overProvFactor = ApiDBUtils.getCpuOverprovisioningFactor(); - capacityValue = Double.parseDouble(_configServer.getConfigValue(Config.CPUCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = Double.parseDouble(_configServer.getConfigValue(Config.CPUCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); break; case Capacity.CAPACITY_TYPE_MEMORY: - capacityValue = Double.parseDouble(_configServer.getConfigValue(Config.MemoryCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); + threshold = Double.parseDouble(_configServer.getConfigValue(Config.MemoryCapacityThreshold.key(), Config.ConfigurationParameterScope.cluster.toString(), cluster.getId())); break; default: - capacityValue = _capacityTypeThresholdMap.get(capacityType); + threshold = _capacityTypeThresholdMap.get(capacityType); } if (capacity == null || capacity.size() == 0){ continue; @@ -590,7 +601,7 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager { double totalCapacity = capacity.get(0).getTotalCapacity() * overProvFactor; double usedCapacity = capacity.get(0).getUsedCapacity() + capacity.get(0).getReservedCapacity(); - if (totalCapacity != 0 && usedCapacity/totalCapacity > capacityValue){ + if (totalCapacity != 0 && usedCapacity/totalCapacity > threshold){ generateEmailAlert(ApiDBUtils.findZoneById(cluster.getDataCenterId()), ApiDBUtils.findPodById(cluster.getPodId()), cluster, totalCapacity, usedCapacity, capacityType); } diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 95f17af53b9..08af964b6ba 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -189,14 +189,14 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer public static ApiServer getInstance() { return s_instance; } - - @Override - public boolean configure(String name, Map params) - throws ConfigurationException { - init(); - return true; - } - + + @Override + public boolean configure(String name, Map params) + throws ConfigurationException { + init(); + return true; + } + public void init() { Integer apiPort = null; // api port, null by default SearchCriteria sc = _configDao.createSearchCriteria(); @@ -293,12 +293,13 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer parameterMap.put(param.getName(), new String[] { param.getValue() }); } - // Get the type of http method being used. + // Get the type of http method being used. parameterMap.put("httpmethod", new String[] { request.getRequestLine().getMethod() }); // Check responseType, if not among valid types, fallback to JSON - if (!(responseType.equals(BaseCmd.RESPONSE_TYPE_JSON) || responseType.equals(BaseCmd.RESPONSE_TYPE_XML))) + if (!(responseType.equals(BaseCmd.RESPONSE_TYPE_JSON) || responseType.equals(BaseCmd.RESPONSE_TYPE_XML))) { responseType = BaseCmd.RESPONSE_TYPE_XML; + } try { // always trust commands from API port, user context will always be UID_SYSTEM/ACCOUNT_ID_SYSTEM @@ -318,7 +319,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer throw e; } } finally { - s_accessLogger.info(sb.toString()); + s_accessLogger.info(StringUtils.cleanString(sb.toString())); CallContext.unregister(); } } @@ -370,7 +371,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer cmdObj.configure(); cmdObj.setFullUrlParams(paramMap); cmdObj.setResponseType(responseType); - cmdObj.setHttpMethod(paramMap.get("httpmethod").toString()); + cmdObj.setHttpMethod(paramMap.get("httpmethod").toString()); // This is where the command is either serialized, or directly dispatched response = queueCommand(cmdObj, paramMap); @@ -384,16 +385,13 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer } } } - } - catch (InvalidParameterValueException ex){ + } catch (InvalidParameterValueException ex){ s_logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex); - } - catch (IllegalArgumentException ex){ + } catch (IllegalArgumentException ex){ s_logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex); - } - catch (PermissionDeniedException ex){ + } catch (PermissionDeniedException ex){ ArrayList idList = ex.getIdProxyList(); if (idList != null) { StringBuffer buf = new StringBuffer(); @@ -408,31 +406,21 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer s_logger.info("PermissionDenied: " + ex.getMessage()); } throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, ex.getMessage(), ex); - } - catch (AccountLimitException ex){ + } catch (AccountLimitException ex){ s_logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.ACCOUNT_RESOURCE_LIMIT_ERROR, ex.getMessage(), ex); - } - catch (InsufficientCapacityException ex){ + } catch (InsufficientCapacityException ex){ s_logger.info(ex.getMessage()); String errorMsg = ex.getMessage(); if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ // hide internal details to non-admin user for security reason errorMsg = BaseCmd.USER_ERROR_MESSAGE; - } throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, errorMsg, ex); - } - catch (ResourceAllocationException ex){ + } catch (ResourceAllocationException ex){ s_logger.info(ex.getMessage()); - String errorMsg = ex.getMessage(); - if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ - // hide internal details to non-admin user for security reason - errorMsg = BaseCmd.USER_ERROR_MESSAGE; - } - throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, errorMsg, ex); - } - catch (ResourceUnavailableException ex){ + throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage(), ex); + } catch (ResourceUnavailableException ex){ s_logger.info(ex.getMessage()); String errorMsg = ex.getMessage(); if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ @@ -440,16 +428,13 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer errorMsg = BaseCmd.USER_ERROR_MESSAGE; } throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, errorMsg, ex); - } - catch (AsyncCommandQueued ex){ + } catch (AsyncCommandQueued ex){ s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal server error, unable to execute request."); - } - catch (ServerApiException ex){ + } catch (ServerApiException ex){ s_logger.info(ex.getDescription()); throw ex; - } - catch (Exception ex){ + } catch (Exception ex){ s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex); String errorMsg = ex.getMessage(); if (CallContext.current().getCallingAccount().getType() != Account.ACCOUNT_TYPE_ADMIN){ diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index 4b49ee4c232..22047ffa901 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -63,9 +63,9 @@ public class ApiServlet extends HttpServlet { @Override public void init(ServletConfig config) throws ServletException { - SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); + SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); } - + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { processRequest(req, resp); @@ -77,8 +77,9 @@ public class ApiServlet extends HttpServlet { } private void utf8Fixup(HttpServletRequest req, Map params) { - if (req.getQueryString() == null) + if (req.getQueryString() == null) { return; + } String[] paramsInQueryString = req.getQueryString().split("&"); if (paramsInQueryString != null) { @@ -325,14 +326,14 @@ public class ApiServlet extends HttpServlet { } } catch (ServerApiException se) { String serializedResponseText = _apiServer.getSerializedApiError(se, params, responseType); - resp.setHeader("X-Description", se.getDescription()); + resp.setHeader("X-Description", se.getDescription()); writeResponse(resp, serializedResponseText, se.getErrorCode().getHttpCode(), responseType); - auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription()); + auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription()); } catch (Exception ex) { - s_logger.error("unknown exception writing api response", ex); - auditTrailSb.append(" unknown exception writing api response"); + s_logger.error("unknown exception writing api response", ex); + auditTrailSb.append(" unknown exception writing api response"); } finally { - s_accessLogger.info(auditTrailSb.toString()); + s_accessLogger.info(StringUtils.cleanString(auditTrailSb.toString())); if (s_logger.isDebugEnabled()) { s_logger.debug("===END=== " + StringUtils.cleanString(reqStr)); } diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index cef5ddf01de..33327db9038 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -2876,17 +2876,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("state", SearchCriteria.Op.SC, readySc); } - if (zoneId != null) { - SearchCriteria zoneSc = _templateJoinDao.createSearchCriteria(); - zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId); - zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION); - // handle the case where xs-tools.iso and vmware-tools.iso do not have data_center information in template_view - SearchCriteria isoPerhostSc = _templateJoinDao.createSearchCriteria(); - isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO); - isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST); - zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc); - sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc); - } if (!showDomr) { // excluding system template @@ -2894,6 +2883,19 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } + if (zoneId != null) { + SearchCriteria zoneSc = _templateJoinDao.createSearchCriteria(); + zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId); + zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION); + // handle the case where xs-tools.iso and vmware-tools.iso do not + // have data_center information in template_view + SearchCriteria isoPerhostSc = _templateJoinDao.createSearchCriteria(); + isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO); + isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST); + zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc); + sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc); + } + // don't return removed template, this should not be needed since we // changed annotation for removed field in TemplateJoinVO. // sc.addAnd("removed", SearchCriteria.Op.NULL); diff --git a/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java index 90bb8c05dae..c9dc5aad419 100644 --- a/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java +++ b/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java @@ -111,8 +111,8 @@ public class VolumeJoinDaoImpl extends GenericDaoBase implem // com.cloud.storage.VolumeHostVO volumeHostRef = // ApiDBUtils.findVolumeHostRef(volume.getId(), // volume.getDataCenterId()); - volResponse.setSize(volume.getVolumeHostSize()); - volResponse.setCreated(volume.getVolumeHostCreated()); + volResponse.setSize(volume.getVolumeStoreSize()); + volResponse.setCreated(volume.getCreatedOnStore()); if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getFormat()).toString()); diff --git a/server/src/com/cloud/api/query/vo/VolumeJoinVO.java b/server/src/com/cloud/api/query/vo/VolumeJoinVO.java index 701e195461d..c7b43ba1569 100644 --- a/server/src/com/cloud/api/query/vo/VolumeJoinVO.java +++ b/server/src/com/cloud/api/query/vo/VolumeJoinVO.java @@ -144,11 +144,11 @@ public class VolumeJoinVO extends BaseViewVO implements ControlledViewEntity { @Enumerated(value=EnumType.STRING) protected VirtualMachine.Type vmType; - @Column (name="volume_host_size") - private long volumeHostSize; + @Column(name = "volume_store_size") + private long volumeStoreSize; - @Column(name="volume_host_created") - private Date volumeHostCreated; + @Column(name = "created_on_store") + private Date createdOnStore; @Column(name="format") private Storage.ImageFormat format; @@ -625,32 +625,22 @@ public class VolumeJoinVO extends BaseViewVO implements ControlledViewEntity { this.vmType = vmType; } - - - public long getVolumeHostSize() { - return volumeHostSize; + public long getVolumeStoreSize() { + return volumeStoreSize; } - - - public void setVolumeHostSize(long volumeHostSize) { - this.volumeHostSize = volumeHostSize; + public void setVolumeStoreSize(long volumeStoreSize) { + this.volumeStoreSize = volumeStoreSize; } - - - public Date getVolumeHostCreated() { - return volumeHostCreated; + public Date getCreatedOnStore() { + return createdOnStore; } - - - public void setVolumeHostCreated(Date volumeHostCreated) { - this.volumeHostCreated = volumeHostCreated; + public void setCreatedOnStore(Date createdOnStore) { + this.createdOnStore = createdOnStore; } - - public Storage.ImageFormat getFormat() { return format; } diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index bb0237c172f..c815c771290 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -145,6 +145,7 @@ public enum Config { SnapshotPollInterval("Snapshots", SnapshotManager.class, Integer.class, "snapshot.poll.interval", "300", "The time interval in seconds when the management server polls for snapshots to be scheduled.", null), SnapshotDeltaMax("Snapshots", SnapshotManager.class, Integer.class, "snapshot.delta.max", "16", "max delta snapshots between two full snapshots.", null), BackupSnapshotAferTakingSnapshot("Snapshots", SnapshotManager.class, Boolean.class, "snapshot.backup.rightafter", "true", "backup snapshot right after snapshot is taken", null), + KVMSnapshotEnabled("Snapshots", SnapshotManager.class, Boolean.class, "KVM.snapshot.enabled", "false", "whether snapshot is enabled for KVM hosts", null), // Advanced JobExpireMinutes("Advanced", ManagementServer.class, String.class, "job.expire.minutes", "1440", "Time (in minutes) for async-jobs to be kept in system", null), @@ -436,7 +437,9 @@ public enum Config { ExecuteInSequence("Advanced", ManagementServer.class, Boolean.class, "execute.in.sequence.hypervisor.commands", "false", "If set to true, StartCommand, StopCommand, CopyCommand will be synchronized on the agent side." + " If set to false, these commands become asynchronous. Default value is false.", null), ExecuteInSequenceNetworkElementCommands("Advanced", NetworkManager.class, Boolean.class, "execute.in.sequence.network.element.commands", "false", "If set to true, DhcpEntryCommand, SavePasswordCommand, UserDataCommand, VmDataCommand will be synchronized on the agent side." + - " If set to false, these commands become asynchronous. Default value is false.", null); + " If set to false, these commands become asynchronous. Default value is false.", null), + + UCSSyncBladeInterval("Advanced", ManagementServer.class, Integer.class, "ucs.sync.blade.interval", "3600", "the interval cloudstack sync with UCS manager for available blades in case user remove blades from chassis without notifying CloudStack", null); private final String _category; private final Class _componentClass; diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 92178c9966c..9bc8efd465b 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2978,30 +2978,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (ipv4) { - String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask); + String newCidr = NetUtils.getCidrFromGatewayAndNetmask(vlanGateway, vlanNetmask); // Check if the new VLAN's subnet conflicts with the guest network // in // the specified zone (guestCidr is null for basic zone) String guestNetworkCidr = zone.getGuestNetworkCidr(); - if (guestNetworkCidr != null) { - String[] cidrPair = guestNetworkCidr.split("\\/"); - String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrPair[0], Long.parseLong(cidrPair[1])); - long guestCidrSize = Long.parseLong(cidrPair[1]); - long vlanCidrSize = NetUtils.getCidrSize(vlanNetmask); - - long cidrSizeToUse = -1; - if (vlanCidrSize < guestCidrSize) { - cidrSizeToUse = vlanCidrSize; - } else { - cidrSizeToUse = guestCidrSize; - } - - String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse); - - if (newVlanSubnet.equals(guestSubnet)) { + if ( guestNetworkCidr != null ) { + if (NetUtils.isNetworksOverlap(newCidr, guestNetworkCidr)) { throw new InvalidParameterValueException( - "The new IP range you have specified has the same subnet as the guest network in zone: " + "The new IP range you have specified has overlapped with the guest network in zone: " + zone.getName() + ". Please specify a different gateway/netmask."); } } @@ -3009,29 +2995,36 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati // Check if there are any errors with the IP range checkPublicIpRangeErrors(zoneId, vlanId, vlanGateway, vlanNetmask, startIP, endIP); - // Throw an exception if any of the following is true: - // 1. Another VLAN in the same zone has a different tag but the same - // subnet as the new VLAN. Make an exception for the - // case when both vlans are Direct. - // 2. Another VLAN in the same zone that has the same tag and subnet - // as - // the new VLAN has IPs that overlap with the IPs - // being added - // 3. Another VLAN in the same zone that has the same tag and subnet - // as - // the new VLAN has a different gateway than the - // new VLAN - // 4. If VLAN is untagged and Virtual, and there is existing - // UNTAGGED - // vlan with different subnet + // Throw an exception if this subnet overlaps with subnet on other VLAN, + // if this is ip range extension, gateway, network mask should be same and ip range should not overlap + List vlans = _vlanDao.listByZone(zone.getId()); for (VlanVO vlan : vlans) { String otherVlanGateway = vlan.getVlanGateway(); + String otherVlanNetmask = vlan.getVlanNetmask(); // Continue if it's not IPv4 - if (otherVlanGateway == null) { + if ( otherVlanGateway == null || otherVlanNetmask == null ) { continue; } - String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask()); + if ( vlan.getNetworkId() == null ) { + continue; + } + String otherCidr = NetUtils.getCidrFromGatewayAndNetmask(otherVlanGateway, otherVlanNetmask); + if( !NetUtils.isNetworksOverlap(newCidr, otherCidr)) { + continue; + } + // from here, subnet overlaps + if ( !vlanId.equals(vlan.getVlanTag()) ) { + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + + " in zone " + zone.getName() + + " has overlapped with the subnet. Please specify a different gateway/netmask."); + } + if ( vlan.getNetworkId() != networkId) { + throw new InvalidParameterValueException("This subnet is overlapped with subnet in other network " + vlan.getNetworkId() + + " in zone " + zone.getName() + + " . Please specify a different gateway/netmask."); + + } String[] otherVlanIpRange = vlan.getIpRange().split("\\-"); String otherVlanStartIP = otherVlanIpRange[0]; String otherVlanEndIP = null; @@ -3039,34 +3032,15 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati otherVlanEndIP = otherVlanIpRange[1]; } - if (forVirtualNetwork && !vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet) - && !allowIpRangeOverlap(vlan, forVirtualNetwork, networkId)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() - + " in zone " + zone.getName() - + " has the same subnet. Please specify a different gateway/netmask."); + //extend IP range + if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) { + throw new InvalidParameterValueException("The IP range has already been added with gateway " + + otherVlanGateway + " ,and netmask " + otherVlanNetmask + + ", Please specify the gateway/netmask if you want to extend ip range" ); } - - boolean vlansUntaggedAndVirtual = (vlanId.equals(Vlan.UNTAGGED) && vlanId.equals(vlan.getVlanTag()) - && forVirtualNetwork && vlan.getVlanType() == VlanType.VirtualNetwork); - - if (vlansUntaggedAndVirtual && !newVlanSubnet.equals(otherVlanSubnet)) { - throw new InvalidParameterValueException( - "The Untagged ip range with different subnet already exists in zone " + zone.getId()); - } - - if (vlanId.equals(vlan.getVlanTag()) && newVlanSubnet.equals(otherVlanSubnet)) { - if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { - throw new InvalidParameterValueException( - "The IP range with tag: " - + vlan.getVlanTag() - + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); - } - - if (!vlanGateway.equals(otherVlanGateway)) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() - + " has already been added with gateway " + otherVlanGateway - + ". Please specify a different tag."); - } + if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) { + throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + + " Please specify a different start IP/end IP."); } } } @@ -3085,15 +3059,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } if (vlanId.equals(vlan.getVlanTag())) { if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) { - throw new InvalidParameterValueException( - "The IPv6 range with tag: " - + vlan.getVlanTag() - + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); + throw new InvalidParameterValueException("The IPv6 range with tag: " + vlan.getVlanTag() + + " already has IPs that overlap with the new range. Please specify a different start IP/end IP."); } if (!vlanIp6Gateway.equals(vlan.getIp6Gateway())) { - throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() - + " has already been added with gateway " + vlan.getIp6Gateway() + throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " has already been added with gateway " + vlan.getIp6Gateway() + ". Please specify a different tag."); } } @@ -4911,14 +4882,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - private boolean allowIpRangeOverlap(VlanVO vlan, boolean forVirtualNetwork, long networkId) { - // FIXME - delete restriction for virtual network in the future - if (vlan.getVlanType() == VlanType.DirectAttached && !forVirtualNetwork) { - return true; - } else { - return false; - } - } @Override public ServiceOffering getServiceOffering(long serviceOfferingId) { diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java index 30fbb4806f2..e1720927aca 100755 --- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java +++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java @@ -65,6 +65,7 @@ import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; @@ -110,7 +111,6 @@ import com.cloud.storage.dao.VMTemplateDao; import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountManager; -import com.cloud.user.User; import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -155,7 +155,7 @@ import com.cloud.vm.dao.VMInstanceDao; // @Local(value = { ConsoleProxyManager.class, ConsoleProxyService.class }) public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxyManager, - VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { + VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class); private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds @@ -540,8 +540,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy public ConsoleProxyVO startProxy(long proxyVmId) { try { ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyVmId); - Account systemAcct = _accountMgr.getSystemAccount(); - User systemUser = _accountMgr.getSystemUser(); if (proxy.getState() == VirtualMachine.State.Running) { return proxy; } @@ -552,7 +550,8 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } if (proxy.getState() == VirtualMachine.State.Stopped) { - return _itMgr.start(proxy, null, systemUser, systemAcct); + _itMgr.advanceStart(proxy.getUuid(), null); + proxy = _consoleProxyDao.findById(proxy.getId()); } // For VMs that are in Stopping, Starting, Migrating state, let client to wait by returning null @@ -574,6 +573,12 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } catch (CloudRuntimeException e) { s_logger.warn("Runtime Exception while trying to start console proxy", e); return null; + } catch (ConcurrentOperationException e) { + s_logger.warn("Runtime Exception while trying to start console proxy", e); + return null; + } catch (OperationTimedoutException e) { + s_logger.warn("Runtime Exception while trying to start console proxy", e); + return null; } } @@ -1020,9 +1025,13 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } try { - return _itMgr.stop(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + _itMgr.stop(proxy.getUuid()); + return true; } catch (ResourceUnavailableException e) { - s_logger.warn("Stopping console proxy " + proxy.getHostName() + " failed : exception " + e.toString()); + s_logger.warn("Stopping console proxy " + proxy.getHostName() + " failed : exception ", e); + return false; + } catch (CloudRuntimeException e) { + s_logger.warn("Unable to stop proxy ", e); return false; } } @@ -1305,9 +1314,9 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - ConsoleProxyVO vm = profile.getVirtualMachine(); + ConsoleProxyVO vm = _consoleProxyDao.findById(profile.getId()); Map details = _vmDetailsDao.findDetails(vm.getId()); vm.setDetails(details); @@ -1383,11 +1392,11 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { finalizeCommandsOnStart(cmds, profile); - ConsoleProxyVO proxy = profile.getVirtualMachine(); + ConsoleProxyVO proxy = _consoleProxyDao.findById(profile.getId()); DataCenter dc = dest.getDataCenter(); List nics = profile.getNics(); for (NicProfile nic : nics) { @@ -1406,7 +1415,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { NicProfile managementNic = null; NicProfile controlNic = null; @@ -1433,7 +1442,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh"); if (answer == null || !answer.getResult()) { if (answer != null) { @@ -1449,7 +1458,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false); IPAddressVO ipaddr = _ipAddressDao.findByAssociatedVmId(profile.getVirtualMachine().getId()); if (ipaddr != null && ipaddr.getSystem()) { - ConsoleProxyVO consoleVm = profile.getVirtualMachine(); + ConsoleProxyVO consoleVm = _consoleProxyDao.findById(profile.getId()); // override CPVM guest IP with EIP, so that console url's will be prepared with EIP consoleVm.setPublicIpAddress(ipaddr.getAddress().addr()); _consoleProxyDao.update(consoleVm.getId(), consoleVm); @@ -1463,7 +1472,8 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public void finalizeExpunge(ConsoleProxyVO proxy) { + public void finalizeExpunge(VirtualMachine vm) { + ConsoleProxyVO proxy = _consoleProxyDao.findById(vm.getId()); proxy.setPublicIpAddress(null); proxy.setPublicMacAddress(null); proxy.setPublicNetmask(null); @@ -1473,12 +1483,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public ConsoleProxyVO findById(long id) { - return _consoleProxyDao.findById(id); - } - - @Override - public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { //release elastic IP here if assigned IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); if (ip != null && ip.getSystem()) { @@ -1680,7 +1685,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy } @Override - public void prepareStop(VirtualMachineProfile profile) { + public void prepareStop(VirtualMachineProfile profile) { } } diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManager.java b/server/src/com/cloud/deploy/DeploymentPlanningManager.java index 9458df2946f..7dde8158bb1 100644 --- a/server/src/com/cloud/deploy/DeploymentPlanningManager.java +++ b/server/src/com/cloud/deploy/DeploymentPlanningManager.java @@ -20,7 +20,6 @@ import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.exception.AffinityConflictException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.utils.component.Manager; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public interface DeploymentPlanningManager extends Manager { @@ -40,11 +39,11 @@ public interface DeploymentPlanningManager extends Manager { * * */ - DeployDestination planDeployment(VirtualMachineProfile vmProfile, DeploymentPlan plan, + DeployDestination planDeployment(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException, AffinityConflictException; String finalizeReservation(DeployDestination plannedDestination, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException, AffinityConflictException; void cleanupVMReservations(); diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java index 975f80b6355..5336d30fe07 100644 --- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java +++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java @@ -207,7 +207,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy } @Override - public DeployDestination planDeployment(VirtualMachineProfile vmProfile, + public DeployDestination planDeployment(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException, AffinityConflictException { @@ -449,7 +449,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy return dest; } - private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) { + private void checkForNonDedicatedResources(VirtualMachineProfile vmProfile, DataCenter dc, ExcludeList avoids) { boolean isExplicit = false; VirtualMachine vm = vmProfile.getVirtualMachine(); // check affinity group of type Explicit dedication exists @@ -534,7 +534,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy } } - private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException { + private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException { if (planner != null && planner instanceof DeploymentClusterPlanner) { return ((DeploymentClusterPlanner) planner).getResourceUsage(vmProfile, plan, avoids); } else { @@ -843,7 +843,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy // /refactoring planner methods private DeployDestination checkClustersforDestination(List clusterList, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, DataCenter dc, DeploymentPlanner.PlannerResourceUsage resourceUsageRequired, ExcludeList PlannerAvoidOutput) { if (s_logger.isTraceEnabled()) { @@ -1035,7 +1035,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy return hostCanAccessSPool; } - protected List findSuitableHosts(VirtualMachineProfile vmProfile, + protected List findSuitableHosts(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { List suitableHosts = new ArrayList(); for (HostAllocator allocator : _hostAllocators) { @@ -1052,7 +1052,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy } protected Pair>, List> findSuitablePoolsForVolumes( - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { List volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId()); Map> suitableVolumeStoragePools = new HashMap>(); @@ -1219,7 +1219,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy @DB @Override public String finalizeReservation(DeployDestination plannedDestination, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException, AffinityConflictException { VirtualMachine vm = vmProfile.getVirtualMachine(); diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index 7124de28d7b..d2e0c14cb52 100755 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -110,7 +110,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla @Override - public List orderClusters(VirtualMachineProfile vmProfile, + public List orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { VirtualMachine vm = vmProfile.getVirtualMachine(); @@ -178,7 +178,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla } - private List scanPodsForDestination(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid){ + private List scanPodsForDestination(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid){ ServiceOffering offering = vmProfile.getServiceOffering(); int requiredCpu = offering.getCpu() * offering.getSpeed(); @@ -264,7 +264,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla } private void removeClustersCrossingThreshold(List clusterListForVmAllocation, ExcludeList avoid, - VirtualMachineProfile vmProfile, DeploymentPlan plan) { + VirtualMachineProfile vmProfile, DeploymentPlan plan) { List capacityList = getCapacitiesForCheckingThreshold(); List clustersCrossingThreshold = new ArrayList(); @@ -302,7 +302,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla } private List scanClustersForDestinationInZoneOrPod(long id, boolean isZone, - VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) { + VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) { VirtualMachine vm = vmProfile.getVirtualMachine(); ServiceOffering offering = vmProfile.getServiceOffering(); @@ -362,7 +362,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla * other than the capacity based ordering which is done by default. * @return List ordered list of Cluster Ids */ - protected List reorderClusters(long id, boolean isZone, Pair, Map> clusterCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ + protected List reorderClusters(long id, boolean isZone, Pair, Map> clusterCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ List reordersClusterIds = clusterCapacityInfo.first(); return reordersClusterIds; } @@ -374,7 +374,7 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla * other than the capacity based ordering which is done by default. * @return List ordered list of Pod Ids */ - protected List reorderPods(Pair, Map> podCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ + protected List reorderPods(Pair, Map> podCapacityInfo, VirtualMachineProfile vmProfile, DeploymentPlan plan){ List podIdsByCapacity = podCapacityInfo.first(); return podIdsByCapacity; } @@ -476,14 +476,14 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla } @Override - public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, + public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude) { // TODO Auto-generated method stub return false; } @Override - public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { + public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { // check what the ServiceOffering says. If null, check the global config ServiceOffering offering = vm.getServiceOffering(); if (vm.getHypervisorType() != HypervisorType.BareMetal) { @@ -510,14 +510,14 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla @Override - public DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, + public DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { // TODO Auto-generated method stub return null; } @Override - public PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile, + public PlannerResourceUsage getResourceUsage(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { return PlannerResourceUsage.Shared; } diff --git a/server/src/com/cloud/deploy/dao/PlannerHostReservationDao.java b/server/src/com/cloud/deploy/dao/PlannerHostReservationDao.java index 69118f13896..e60254b4866 100644 --- a/server/src/com/cloud/deploy/dao/PlannerHostReservationDao.java +++ b/server/src/com/cloud/deploy/dao/PlannerHostReservationDao.java @@ -27,4 +27,6 @@ public interface PlannerHostReservationDao extends GenericDao listAllReservedHosts(); + List listAllDedicatedHosts(); + } diff --git a/server/src/com/cloud/deploy/dao/PlannerHostReservationDaoImpl.java b/server/src/com/cloud/deploy/dao/PlannerHostReservationDaoImpl.java index 41e09647d7e..06cdab22fad 100644 --- a/server/src/com/cloud/deploy/dao/PlannerHostReservationDaoImpl.java +++ b/server/src/com/cloud/deploy/dao/PlannerHostReservationDaoImpl.java @@ -20,6 +20,8 @@ import java.util.List; import javax.annotation.PostConstruct; import javax.ejb.Local; + +import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage; import com.cloud.deploy.PlannerHostReservationVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; @@ -31,6 +33,7 @@ public class PlannerHostReservationDaoImpl extends GenericDaoBase _hostIdSearch; private SearchBuilder _reservedHostSearch; + private SearchBuilder _dedicatedHostSearch;; public PlannerHostReservationDaoImpl() { @@ -45,6 +48,10 @@ public class PlannerHostReservationDaoImpl extends GenericDaoBase listAllDedicatedHosts() { + SearchCriteria sc = _dedicatedHostSearch.create(); + sc.setParameters("usage", PlannerResourceUsage.Dedicated); + return listBy(sc); + } +} \ No newline at end of file diff --git a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java index 29719105a15..0df324c8bc7 100644 --- a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java +++ b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java @@ -26,10 +26,10 @@ import com.cloud.agent.api.CheckVirtualMachineAnswer; import com.cloud.agent.api.CheckVirtualMachineCommand; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.OperationTimedoutException; -import com.cloud.host.HostVO; +import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; @Local(value=Investigator.class) @@ -42,12 +42,12 @@ public class CheckOnAgentInvestigator extends AdapterBase implements Investigato } @Override - public Status isAgentAlive(HostVO agent) { + public Status isAgentAlive(Host agent) { return null; } @Override - public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) { CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName()); try { CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer)_agentMgr.send(vm.getHostId(), cmd); diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java index 25c5a043b6c..a7e0bd9a77a 100755 --- a/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java +++ b/server/src/com/cloud/ha/HighAvailabilityManagerImpl.java @@ -32,6 +32,8 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.apache.log4j.NDC; +import org.apache.cloudstack.context.ServerContexts; + import com.cloud.agent.AgentManager; import com.cloud.alert.AlertManager; import com.cloud.cluster.ClusterManagerListener; @@ -284,7 +286,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai if (hostId == null) { try { s_logger.debug("Found a vm that is scheduled to be restarted but has no host id: " + vm); - _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + _itMgr.advanceStop(vm.getUuid(), true); } catch (ResourceUnavailableException e) { assert false : "How do we hit this when force is true?"; throw new CloudRuntimeException("Caught exception even though it should be handled.", e); @@ -294,7 +296,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } catch (ConcurrentOperationException e) { assert false : "How do we hit this when force is true?"; throw new CloudRuntimeException("Caught exception even though it should be handled.", e); - } + } return; } @@ -328,7 +330,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } try { - _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + _itMgr.advanceStop(vm.getUuid(), true); } catch (ResourceUnavailableException e) { assert false : "How do we hit this when force is true?"; throw new CloudRuntimeException("Caught exception even though it should be handled.", e); @@ -338,7 +340,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } catch (ConcurrentOperationException e) { assert false : "How do we hit this when force is true?"; throw new CloudRuntimeException("Caught exception even though it should be handled.", e); - } + } } List items = _haDao.findPreviousHA(vm.getId()); @@ -386,7 +388,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai long vmId = work.getInstanceId(); - VMInstanceVO vm = _itMgr.findByIdAndType(work.getType(), work.getInstanceId()); + VirtualMachine vm = _itMgr.findById(work.getInstanceId()); if (vm == null) { s_logger.info("Unable to find vm: " + vmId); return null; @@ -473,7 +475,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } try { - _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + _itMgr.advanceStop(vm.getUuid(), true); } catch (ResourceUnavailableException e) { assert false : "How do we hit this when force is true?"; throw new CloudRuntimeException("Caught exception even though it should be handled.", e); @@ -490,7 +492,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } else { s_logger.debug("How come that HA step is Investigating and the host is removed? Calling forced Stop on Vm anyways"); try { - _itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + _itMgr.advanceStop(vm.getUuid(), true); } catch (ResourceUnavailableException e) { assert false : "How do we hit this when force is true?"; throw new CloudRuntimeException("Caught exception even though it should be handled.", e); @@ -504,7 +506,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } } - vm = _itMgr.findByIdAndType(vm.getType(), vm.getId()); + vm = _itMgr.findById(vm.getId()); if (!_forceHA && !vm.isHaEnabled()) { if (s_logger.isDebugEnabled()) { @@ -513,7 +515,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai return null; // VM doesn't require HA } - if (!this.volumeMgr.canVmRestartOnAnotherServer(vm.getId())) { + if (!volumeMgr.canVmRestartOnAnotherServer(vm.getId())) { if (s_logger.isDebugEnabled()) { s_logger.debug("VM can not restart on another server."); } @@ -530,9 +532,10 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai if (_haTag != null) { params.put(VirtualMachineProfile.Param.HaTag, _haTag); } - VMInstanceVO started = _itMgr.advanceStart(vm, params, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); - - if (started != null) { + _itMgr.advanceStart(vm.getUuid(), params); + + VMInstanceVO started = _instanceDao.findById(vm.getId()); + if (started != null && started.getState() == VirtualMachine.State.Running) { s_logger.info("VM is now restarted: " + vmId + " on " + started.getHostId()); return null; } @@ -557,7 +560,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "Unable to restart " + vm.getHostName() + " which was running on host " + hostDesc, "The Storage is unavailable for trying to restart VM, name: " + vm.getHostName() + ", id: " + vmId + " which was running on host " + hostDesc); } - vm = _itMgr.findByIdAndType(vm.getType(), vm.getId()); + vm = _itMgr.findById(vm.getId()); work.setUpdateTime(vm.getUpdated()); work.setPreviousState(vm.getState()); return (System.currentTimeMillis() >> 10) + _restartRetryInterval; @@ -603,7 +606,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } protected Long destroyVM(HaWorkVO work) { - final VMInstanceVO vm = _itMgr.findByIdAndType(work.getType(), work.getInstanceId()); + final VirtualMachine vm = _itMgr.findById(work.getInstanceId()); s_logger.info("Destroying " + vm.toString()); try { if (vm.getState() != State.Destroyed) { @@ -612,11 +615,9 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } if (vm.getHostId() != null) { - if (_itMgr.destroy(vm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) { - s_logger.info("Successfully destroy " + vm); - return null; - } - s_logger.debug("Stop for " + vm + " was unsuccessful."); + _itMgr.destroy(vm.getUuid()); + s_logger.info("Successfully destroy " + vm); + return null; } else { if (s_logger.isDebugEnabled()) { s_logger.debug(vm + " has already been stopped"); @@ -636,7 +637,7 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai } protected Long stopVM(final HaWorkVO work) throws ConcurrentOperationException { - VMInstanceVO vm = _itMgr.findByIdAndType(work.getType(), work.getInstanceId()); + VirtualMachine vm = _itMgr.findById(work.getInstanceId()); if (vm == null) { s_logger.info("No longer can find VM " + work.getInstanceId() + ". Throwing away " + work); work.setStep(Step.Done); @@ -645,28 +646,25 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai s_logger.info("Stopping " + vm); try { if (work.getWorkType() == WorkType.Stop) { - if (_itMgr.advanceStop(vm, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) { - s_logger.info("Successfully stopped " + vm); - return null; - } + _itMgr.advanceStop(vm.getUuid(), false); + s_logger.info("Successfully stopped " + vm); + return null; } else if (work.getWorkType() == WorkType.CheckStop) { if ((vm.getState() != work.getPreviousState()) || vm.getUpdated() != work.getUpdateTime() || vm.getHostId() == null || vm.getHostId().longValue() != work.getHostId()) { s_logger.info(vm + " is different now. Scheduled Host: " + work.getHostId() + " Current Host: " + (vm.getHostId() != null ? vm.getHostId() : "none") + " State: " + vm.getState()); return null; } - if (_itMgr.advanceStop(vm, false, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) { - s_logger.info("Stop for " + vm + " was successful"); - return null; - } + _itMgr.advanceStop(vm.getUuid(), false); + s_logger.info("Stop for " + vm + " was successful"); + return null; } else if (work.getWorkType() == WorkType.ForceStop) { if ((vm.getState() != work.getPreviousState()) || vm.getUpdated() != work.getUpdateTime() || vm.getHostId() == null || vm.getHostId().longValue() != work.getHostId()) { s_logger.info(vm + " is different now. Scheduled Host: " + work.getHostId() + " Current Host: " + (vm.getHostId() != null ? vm.getHostId() : "none") + " State: " + vm.getState()); return null; } - if (_itMgr.advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount())) { - s_logger.info("Stop for " + vm + " was successful"); - return null; - } + _itMgr.advanceStop(vm.getUuid(), true); + s_logger.info("Stop for " + vm + " was successful"); + return null; } else { assert false : "Who decided there's other steps but didn't modify the guy who does the work?"; } @@ -801,66 +799,71 @@ public class HighAvailabilityManagerImpl extends ManagerBase implements HighAvai @Override public void run() { - s_logger.info("Starting work"); - while (!_stopped) { - HaWorkVO work = null; - try { - s_logger.trace("Checking the database"); - work = _haDao.take(_serverId); - if (work == null) { + ServerContexts.registerSystemContext(); + try { + s_logger.info("Starting work"); + while (!_stopped) { + HaWorkVO work = null; try { - synchronized (this) { - wait(_timeToSleep); + s_logger.trace("Checking the database"); + work = _haDao.take(_serverId); + if (work == null) { + try { + synchronized (this) { + wait(_timeToSleep); + } + continue; + } catch (final InterruptedException e) { + s_logger.info("Interrupted"); + continue; } - continue; - } catch (final InterruptedException e) { - s_logger.info("Interrupted"); - continue; - } - } - - NDC.push("work-" + work.getId()); - s_logger.info("Processing " + work); - - try { - final WorkType wt = work.getWorkType(); - Long nextTime = null; - if (wt == WorkType.Migration) { - nextTime = migrate(work); - } else if (wt == WorkType.HA) { - nextTime = restart(work); - } else if (wt == WorkType.Stop || wt == WorkType.CheckStop || wt == WorkType.ForceStop) { - nextTime = stopVM(work); - } else if (wt == WorkType.Destroy) { - nextTime = destroyVM(work); - } else { - assert false : "How did we get here with " + wt.toString(); - continue; } - if (nextTime == null) { - s_logger.info("Completed " + work); - work.setStep(Step.Done); - } else { - s_logger.info("Rescheduling " + work + " to try again at " + new Date(nextTime << 10)); - work.setTimeToTry(nextTime); - work.setServerId(null); - work.setDateTaken(null); + NDC.push("work-" + work.getId()); + s_logger.info("Processing " + work); + + try { + final WorkType wt = work.getWorkType(); + Long nextTime = null; + if (wt == WorkType.Migration) { + nextTime = migrate(work); + } else if (wt == WorkType.HA) { + nextTime = restart(work); + } else if (wt == WorkType.Stop || wt == WorkType.CheckStop || wt == WorkType.ForceStop) { + nextTime = stopVM(work); + } else if (wt == WorkType.Destroy) { + nextTime = destroyVM(work); + } else { + assert false : "How did we get here with " + wt.toString(); + continue; + } + + if (nextTime == null) { + s_logger.info("Completed " + work); + work.setStep(Step.Done); + } else { + s_logger.info("Rescheduling " + work + " to try again at " + new Date(nextTime << 10)); + work.setTimeToTry(nextTime); + work.setServerId(null); + work.setDateTaken(null); + } + } catch (Exception e) { + s_logger.error("Terminating " + work, e); + work.setStep(Step.Error); + } + _haDao.update(work.getId(), work); + } catch (final Throwable th) { + s_logger.error("Caught this throwable, ", th); + } finally { + if (work != null) { + NDC.pop(); + } } - } catch (Exception e) { - s_logger.error("Terminating " + work, e); - work.setStep(Step.Error); } - _haDao.update(work.getId(), work); - } catch (final Throwable th) { - s_logger.error("Caught this throwable, ", th); - } finally { - if (work != null) { - NDC.pop(); - } - } + s_logger.info("Time to go home!"); + } finally { + ServerContexts.unregisterSystemContext(); } - s_logger.info("Time to go home!"); } public synchronized void wakup() { diff --git a/server/src/com/cloud/ha/KVMFencer.java b/server/src/com/cloud/ha/KVMFencer.java index 9fcacd72321..517209e8dad 100755 --- a/server/src/com/cloud/ha/KVMFencer.java +++ b/server/src/com/cloud/ha/KVMFencer.java @@ -17,7 +17,6 @@ package com.cloud.ha; import java.util.List; - import java.util.Map; import javax.ejb.Local; @@ -31,13 +30,14 @@ import com.cloud.agent.api.FenceAnswer; import com.cloud.agent.api.FenceCommand; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.OperationTimedoutException; +import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceManager; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; @Local(value=FenceBuilder.class) public class KVMFencer extends AdapterBase implements FenceBuilder { @@ -70,7 +70,7 @@ public class KVMFencer extends AdapterBase implements FenceBuilder { } @Override - public Boolean fenceOff(VMInstanceVO vm, HostVO host) { + public Boolean fenceOff(VirtualMachine vm, Host host) { if (host.getHypervisorType() != HypervisorType.KVM) { s_logger.debug("Don't know how to fence non kvm hosts " + host.getHypervisorType()); return null; diff --git a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java index 17f0355ed96..2b6d261261c 100644 --- a/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java +++ b/server/src/com/cloud/ha/ManagementIPSystemVMInvestigator.java @@ -25,13 +25,13 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; +import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.network.NetworkModel; import com.cloud.network.Networks.TrafficType; import com.cloud.vm.Nic; -import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; @Local(value={Investigator.class}) @@ -39,13 +39,13 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { private static final Logger s_logger = Logger.getLogger(ManagementIPSystemVMInvestigator.class); private String _name = null; - @Inject private HostDao _hostDao = null; - @Inject private NetworkModel _networkMgr = null; + @Inject private final HostDao _hostDao = null; + @Inject private final NetworkModel _networkMgr = null; @Override - public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { - if (!VirtualMachine.Type.isSystemVM(vm.getType())) { + public Boolean isVmAlive(VirtualMachine vm, Host host) { + if (!vm.getType().isUsedBySystem()) { s_logger.debug("Not a System Vm, unable to determine state of " + vm + " returning null"); } @@ -110,7 +110,7 @@ public class ManagementIPSystemVMInvestigator extends AbstractInvestigatorImpl { } @Override - public Status isAgentAlive(HostVO agent) { + public Status isAgentAlive(Host agent) { return null; } diff --git a/server/src/com/cloud/ha/RecreatableFencer.java b/server/src/com/cloud/ha/RecreatableFencer.java index 50aa1b75762..398bb037cd5 100644 --- a/server/src/com/cloud/ha/RecreatableFencer.java +++ b/server/src/com/cloud/ha/RecreatableFencer.java @@ -21,15 +21,15 @@ import java.util.List; import javax.ejb.Local; import javax.inject.Inject; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; -import com.cloud.host.HostVO; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; + +import com.cloud.host.Host; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.VolumeDao; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; @Component @@ -44,7 +44,7 @@ public class RecreatableFencer extends AdapterBase implements FenceBuilder { } @Override - public Boolean fenceOff(VMInstanceVO vm, HostVO host) { + public Boolean fenceOff(VirtualMachine vm, Host host) { VirtualMachine.Type type = vm.getType(); if (type != VirtualMachine.Type.ConsoleProxy && type != VirtualMachine.Type.DomainRouter && type != VirtualMachine.Type.SecondaryStorageVm) { if (s_logger.isDebugEnabled()) { diff --git a/server/src/com/cloud/ha/UserVmDomRInvestigator.java b/server/src/com/cloud/ha/UserVmDomRInvestigator.java index 8b48c09dfa1..195deff5ab0 100644 --- a/server/src/com/cloud/ha/UserVmDomRInvestigator.java +++ b/server/src/com/cloud/ha/UserVmDomRInvestigator.java @@ -29,7 +29,7 @@ import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.PingTestCommand; -import com.cloud.host.HostVO; +import com.cloud.host.Host; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.NetworkModel; @@ -38,7 +38,6 @@ import com.cloud.network.router.VirtualRouter; import com.cloud.network.router.VpcVirtualNetworkApplianceManager; import com.cloud.vm.Nic; import com.cloud.vm.UserVmVO; -import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.dao.UserVmDao; @@ -53,7 +52,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { @Inject private final VpcVirtualNetworkApplianceManager _vnaMgr = null; @Override - public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) { if (vm.getType() != VirtualMachine.Type.User) { if (s_logger.isDebugEnabled()) { s_logger.debug("Not a User Vm, unable to determine state of " + vm + " returning null"); @@ -104,7 +103,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { } @Override - public Status isAgentAlive(HostVO agent) { + public Status isAgentAlive(Host agent) { if (s_logger.isDebugEnabled()) { s_logger.debug("checking if agent (" + agent.getId() + ") is alive"); } @@ -166,7 +165,7 @@ public class UserVmDomRInvestigator extends AbstractInvestigatorImpl { return true; } - private Boolean testUserVM(VMInstanceVO vm, Nic nic, VirtualRouter router) { + private Boolean testUserVM(VirtualMachine vm, Nic nic, VirtualRouter router) { String privateIp = nic.getIp4Address(); String routerPrivateIp = router.getPrivateIpAddress(); diff --git a/server/src/com/cloud/ha/XenServerInvestigator.java b/server/src/com/cloud/ha/XenServerInvestigator.java index 6cbd22ff2da..2b96007b91b 100755 --- a/server/src/com/cloud/ha/XenServerInvestigator.java +++ b/server/src/com/cloud/ha/XenServerInvestigator.java @@ -23,17 +23,18 @@ import javax.inject.Inject; import org.apache.log4j.Logger; +import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckOnHostAnswer; import com.cloud.agent.api.CheckOnHostCommand; -import com.cloud.agent.AgentManager; +import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceManager; import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; @Local(value=Investigator.class) public class XenServerInvestigator extends AdapterBase implements Investigator { @@ -46,7 +47,7 @@ public class XenServerInvestigator extends AdapterBase implements Investigator { } @Override - public Status isAgentAlive(HostVO agent) { + public Status isAgentAlive(Host agent) { if (agent.getHypervisorType() != HypervisorType.XenServer) { return null; } @@ -72,7 +73,7 @@ public class XenServerInvestigator extends AdapterBase implements Investigator { } @Override - public Boolean isVmAlive(VMInstanceVO vm, HostVO host) { + public Boolean isVmAlive(VirtualMachine vm, Host host) { Status status = isAgentAlive(host); if (status == null) { return null; diff --git a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java index 2ffd6821d3e..34584ab7a81 100644 --- a/server/src/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/com/cloud/hypervisor/HypervisorGuruBase.java @@ -85,7 +85,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis } - protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { + protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { ServiceOffering offering = vmProfile.getServiceOffering(); VirtualMachine vm = vmProfile.getVirtualMachine(); diff --git a/server/src/com/cloud/hypervisor/KVMGuru.java b/server/src/com/cloud/hypervisor/KVMGuru.java index 662ee3e836b..58e46e12979 100644 --- a/server/src/com/cloud/hypervisor/KVMGuru.java +++ b/server/src/com/cloud/hypervisor/KVMGuru.java @@ -23,7 +23,6 @@ import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.GuestOSVO; import com.cloud.storage.dao.GuestOSDao; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @Local(value=HypervisorGuru.class) @@ -40,8 +39,7 @@ public class KVMGuru extends HypervisorGuruBase implements HypervisorGuru { } @Override - public VirtualMachineTO implement( - VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); // Determine the VM's OS description diff --git a/server/src/com/cloud/hypervisor/LXCGuru.java b/server/src/com/cloud/hypervisor/LXCGuru.java index 7a530b5a203..dd61b20a0a7 100644 --- a/server/src/com/cloud/hypervisor/LXCGuru.java +++ b/server/src/com/cloud/hypervisor/LXCGuru.java @@ -23,7 +23,6 @@ import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.GuestOSVO; import com.cloud.storage.dao.GuestOSDao; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @Local(value=HypervisorGuru.class) @@ -40,8 +39,7 @@ public class LXCGuru extends HypervisorGuruBase implements HypervisorGuru { } @Override - public VirtualMachineTO implement( - VirtualMachineProfile vm) { + public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); // Determine the VM's OS description diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 8dc7743e706..f6dbb198945 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -5,7 +5,7 @@ // 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, @@ -55,7 +55,6 @@ import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; import com.cloud.vm.ReservationContext; -import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; @@ -82,7 +81,7 @@ public interface NetworkManager { * @throws InsufficientAddressCapacityException */ - PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, + PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException; @@ -103,17 +102,17 @@ public interface NetworkManager { List setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException; - void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException; + void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException; - void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, + void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; - void release(VirtualMachineProfile vmProfile, boolean forced) throws + void release(VirtualMachineProfile vmProfile, boolean forced) throws ConcurrentOperationException, ResourceUnavailableException; - void cleanupNics(VirtualMachineProfile vm); + void cleanupNics(VirtualMachineProfile vm); - void expungeNics(VirtualMachineProfile vm); + void expungeNics(VirtualMachineProfile vm); List getNicProfiles(VirtualMachine vm); @@ -129,27 +128,27 @@ public interface NetworkManager { * @param vm * @param dest */ - void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest); + void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest); /** * commit vm nic change for migration * - * This method will be called in migration transaction after the successful + * This method will be called in migration transaction after the successful * vm migration. * @param src * @param dst */ - void commitNicForMigration(VirtualMachineProfile src, VirtualMachineProfile dst); + void commitNicForMigration(VirtualMachineProfile src, VirtualMachineProfile dst); /** * rollback vm nic change for migration * - * This method will be called in migaration transaction after vm migration + * This method will be called in migaration transaction after vm migration * failure. * @param src * @param dst */ - void rollbackNicForMigration(VirtualMachineProfile src, VirtualMachineProfile dst); + void rollbackNicForMigration(VirtualMachineProfile src, VirtualMachineProfile dst); boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements); @@ -193,8 +192,7 @@ public interface NetworkManager { boolean applyStaticNats(List staticNats, boolean continueOnError, boolean forRevoke) throws ResourceUnavailableException; - boolean reallocate(VirtualMachineProfile vm, - DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException; + boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException; IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) @@ -203,7 +201,7 @@ public interface NetworkManager { boolean handleSystemIpRelease(IpAddress ip); void allocateDirectIp(NicProfile nic, DataCenter dc, - VirtualMachineProfile vm, + VirtualMachineProfile vm, Network network, String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException; @@ -212,8 +210,8 @@ public interface NetworkManager { * @param owner * @param guestNetwork * @return - * @throws ConcurrentOperationException - * @throws InsufficientAddressCapacityException + * @throws ConcurrentOperationException + * @throws InsufficientAddressCapacityException */ PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) throws InsufficientAddressCapacityException, ConcurrentOperationException; @@ -229,8 +227,8 @@ public interface NetworkManager { * @throws InsufficientAddressCapacityException * @throws ConcurrentOperationException */ - Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, - VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId, + VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException; @@ -247,7 +245,7 @@ public interface NetworkManager { * @throws InsufficientCapacityException * @throws ResourceUnavailableException */ - NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, + NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; @@ -256,7 +254,7 @@ public interface NetworkManager { * @param vm * @param nic TODO */ - void removeNic(VirtualMachineProfile vm, Nic nic); + void removeNic(VirtualMachineProfile vm, Nic nic); /** @@ -264,7 +262,7 @@ public interface NetworkManager { * @param networkId * @param releaseOnFailure TODO */ - IPAddressVO associateIPToGuestNetwork(long ipAddrId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException, + IPAddressVO associateIPToGuestNetwork(long ipAddrId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException; IpAddress allocatePortableIp(Account ipOwner, Account caller, long dcId, Long networkId, Long vpcID) @@ -297,7 +295,7 @@ public interface NetworkManager { * @throws ConcurrentOperationException * @throws ResourceUnavailableException */ - void releaseNic(VirtualMachineProfile vmProfile, Nic nic) + void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException; @@ -314,7 +312,8 @@ public interface NetworkManager { * @throws InsufficientCapacityException * @throws ResourceUnavailableException */ - NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, + NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) + throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException; diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 196f7de0ba0..30c4242c8e9 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1429,6 +1429,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null); offering.setState(NetworkOffering.State.Enabled); offering.setInternalLb(true); + offering.setPublicLb(false); _networkOfferingDao.update(offering.getId(), offering); } @@ -1614,7 +1615,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override @DB - public void allocate(VirtualMachineProfile vm, List> networks) + public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException { Transaction txn = Transaction.currentTxn(); txn.start(); @@ -1689,7 +1690,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @DB @Override public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, - int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException{ NetworkVO ntwkVO = _networksDao.findById(network.getId()); @@ -1996,7 +1997,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } protected boolean prepareElement(NetworkElement element, NetworkVO network, - NicProfile profile, VirtualMachineProfile vmProfile, + NicProfile profile, VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { element.prepare(network, profile, vmProfile, dest, context); @@ -2043,7 +2044,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } @Override - public void prepare(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, + public void prepare(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { List nics = _nicDao.listByVmId(vmProfile.getId()); @@ -2071,7 +2072,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } @Override - public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination + public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { @@ -2135,7 +2136,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } @Override - public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest) { + public void prepareNicForMigration(VirtualMachineProfile vm, DeployDestination dest) { List nics = _nicDao.listByVmId(vm.getId()); ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null); for (NicVO nic : nics) { @@ -2162,7 +2163,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } } - private NicProfile findNicProfileById(VirtualMachineProfile vm, long id){ + private NicProfile findNicProfileById(VirtualMachineProfile vm, long id){ for(NicProfile nic: vm.getNics()){ if(nic.getId() == id){ return nic; @@ -2173,8 +2174,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override public void commitNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { + VirtualMachineProfile src, + VirtualMachineProfile dst) { for(NicProfile nicSrc: src.getNics()){ NetworkVO network = _networksDao.findById(nicSrc.getNetworkId()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); @@ -2199,8 +2200,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override public void rollbackNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { + VirtualMachineProfile src, + VirtualMachineProfile dst) { for(NicProfile nicDst: dst.getNics()){ NetworkVO network = _networksDao.findById(nicDst.getNetworkId()); NetworkGuru guru = AdapterBase.getAdapterByName(_networkGurus, network.getGuruName()); @@ -2221,7 +2222,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override @DB - public void release(VirtualMachineProfile vmProfile, boolean forced) throws + public void release(VirtualMachineProfile vmProfile, boolean forced) throws ConcurrentOperationException, ResourceUnavailableException { List nics = _nicDao.listByVmId(vmProfile.getId()); for (NicVO nic : nics) { @@ -2232,14 +2233,14 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override @DB - public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { NicVO nicVO = _nicDao.findById(nic.getId()); releaseNic(vmProfile, nicVO); } @DB - protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nicVO) + protected void releaseNic(VirtualMachineProfile vmProfile, NicVO nicVO) throws ConcurrentOperationException, ResourceUnavailableException { //lock the nic Transaction txn = Transaction.currentTxn(); @@ -2291,7 +2292,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } @Override - public void cleanupNics(VirtualMachineProfile vm) { + public void cleanupNics(VirtualMachineProfile vm) { if (s_logger.isDebugEnabled()) { s_logger.debug("Cleaning network for vm: " + vm.getId()); } @@ -2304,12 +2305,12 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override - public void removeNic(VirtualMachineProfile vm, Nic nic) { + public void removeNic(VirtualMachineProfile vm, Nic nic) { removeNic(vm, _nicDao.findById(nic.getId())); } - protected void removeNic(VirtualMachineProfile vm, NicVO nic) { + protected void removeNic(VirtualMachineProfile vm, NicVO nic) { nic.setState(Nic.State.Deallocating); _nicDao.update(nic.getId(), nic); NetworkVO network = _networksDao.findById(nic.getNetworkId()); @@ -2346,7 +2347,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } @Override - public void expungeNics(VirtualMachineProfile vm) { + public void expungeNics(VirtualMachineProfile vm) { List nics = _nicDao.listByVmIdIncludingRemoved(vm.getId()); for (NicVO nic : nics) { _nicDao.expunge(nic.getId()); @@ -3703,7 +3704,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @DB @Override - public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException { + public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException { VMInstanceVO vmInstance = _vmDao.findById(vm.getId()); DataCenterVO dc = _dcDao.findById(vmInstance.getDataCenterId()); if (dc.getNetworkType() == NetworkType.Basic) { @@ -4197,7 +4198,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L @Override @DB - public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network, + public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network, String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { //This method allocates direct ip for the Shared network in Advance zones @@ -4299,7 +4300,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } @Override - public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) + public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, VirtualMachineProfile vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index f1f71ca4078..23bed01d87a 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -1233,13 +1233,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { } } - // Vlan is created in 2 cases - works in Advance zone only: + // Vlan is created in 1 cases - works in Advance zone only: // 1) GuestType is Shared - // 2) GuestType is Isolated, but SourceNat service is disabled boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced - && ((ntwkOff.getGuestType() == Network.GuestType.Shared) - || (ntwkOff.getGuestType() == GuestType.Isolated && - !areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)))); + && (ntwkOff.getGuestType() == Network.GuestType.Shared)); if (!createVlan) { // Only support advance shared network in IPv6, which means createVlan is a must diff --git a/server/src/com/cloud/network/element/CloudZonesNetworkElement.java b/server/src/com/cloud/network/element/CloudZonesNetworkElement.java index bdd8e61bbc2..5c7f333a687 100644 --- a/server/src/com/cloud/network/element/CloudZonesNetworkElement.java +++ b/server/src/com/cloud/network/element/CloudZonesNetworkElement.java @@ -50,7 +50,6 @@ import com.cloud.network.PhysicalNetworkServiceProvider; import com.cloud.network.dao.NetworkDao; import com.cloud.offering.NetworkOffering; import com.cloud.service.dao.ServiceOfferingDao; -import com.cloud.uservm.UserVm; import com.cloud.utils.PasswordGenerator; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.NicProfile; @@ -112,13 +111,13 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { return true; } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { return true; } @@ -200,7 +199,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem } @Override - public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(dest, network.getTrafficType())) { @@ -208,16 +207,16 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem return false; } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; - _userVmDao.loadDetails((UserVmVO) uservm.getVirtualMachine()); - String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword); - String userData = uservm.getVirtualMachine().getUserData(); - String sshPublicKey = uservm.getVirtualMachine().getDetail("SSH.PublicKey"); + UserVmVO uservm = _userVmDao.findById(vm.getId()); + _userVmDao.loadDetails(uservm); + String password = (String)vm.getParameter(VirtualMachineProfile.Param.VmPassword); + String userData = uservm.getUserData(); + String sshPublicKey = uservm.getDetail("SSH.PublicKey"); Commands cmds = new Commands(OnError.Continue); if (password != null && nic.isDefaultNic()) { final String encodedPassword = PasswordGenerator.rot13(password); - SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getVirtualMachine().getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd()); + SavePasswordCommand cmd = new SavePasswordCommand(encodedPassword, nic.getIp4Address(), uservm.getHostName(), _networkMgr.getExecuteInSeqNtwkElmtCmd()); cmds.addCommand("password", cmd); } String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(uservm.getServiceOfferingId()).getDisplayText(); @@ -225,7 +224,7 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem cmds.addCommand( "vmdata", - generateVmDataCommand(nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), uservm.getVirtualMachine().getHostName(), + generateVmDataCommand(nic.getIp4Address(), userData, serviceOffering, zoneName, nic.getIp4Address(), uservm.getHostName(), uservm.getInstanceName(), uservm.getId(), uservm.getUuid(), sshPublicKey)); try { _agentManager.send(dest.getHost().getId(), cmds); @@ -235,29 +234,29 @@ public class CloudZonesNetworkElement extends AdapterBase implements NetworkElem } Answer dataAnswer = cmds.getAnswer("vmdata"); if (dataAnswer != null && dataAnswer.getResult()) { - s_logger.info("Sent vm data successfully to vm " + uservm.getVirtualMachine().getInstanceName()); + s_logger.info("Sent vm data successfully to vm " + uservm.getInstanceName()); return true; } - s_logger.info("Failed to send vm data to vm " + uservm.getVirtualMachine().getInstanceName()); + s_logger.info("Failed to send vm data to vm " + uservm.getInstanceName()); return false; } return false; } @Override - public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { + public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @Override - public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException { + public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @Override - public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { + public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } diff --git a/server/src/com/cloud/network/element/SecurityGroupElement.java b/server/src/com/cloud/network/element/SecurityGroupElement.java index 0659db781e3..4a740c0c186 100644 --- a/server/src/com/cloud/network/element/SecurityGroupElement.java +++ b/server/src/com/cloud/network/element/SecurityGroupElement.java @@ -68,13 +68,13 @@ public class SecurityGroupElement extends AdapterBase implements NetworkElement } @Override @DB - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { return true; } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index d26c1e111cd..15b7f13ee62 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -212,7 +212,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (vm.getType() != VirtualMachine.Type.User || vm.getHypervisorType() == HypervisorType.BareMetal) { @@ -232,7 +232,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; List routers = _routerMgr.deployVirtualRouterInGuestNetwork(network, dest, _accountMgr.getAccount(network.getAccountId()), uservm.getParameters(), offering.getRedundantRouter()); @@ -685,7 +685,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) + public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { if (!canHandle(network, null)) { return false; @@ -697,13 +697,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; return _routerMgr.savePasswordToRouter(network, nic, uservm, routers); } @Override - public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) + public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile vm, String SSHPublicKey) throws ResourceUnavailableException { if (!canHandle(network, null)) { return false; @@ -715,13 +715,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; return _routerMgr.saveSSHPublicKeyToRouter(network, nic, uservm, routers, SSHPublicKey); } @Override - public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) + public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfile vm) throws ResourceUnavailableException { if (!canHandle(network, null)) { return false; @@ -733,7 +733,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; return _routerMgr.saveUserDataToRouter(network, nic, uservm, routers); } @@ -848,21 +848,21 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { return true; } @Override - public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.Dhcp)) { if (vm.getType() != VirtualMachine.Type.User) { return false; } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; List routers = getRouters(network, dest); @@ -893,7 +893,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.Dhcp)) { @@ -902,7 +902,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; List routers = getRouters(network, dest); @@ -916,7 +916,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @Override - public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { if (canHandle(network, Service.UserData)) { @@ -930,7 +930,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } @SuppressWarnings("unchecked") - VirtualMachineProfile uservm = (VirtualMachineProfile) vm; + VirtualMachineProfile uservm = (VirtualMachineProfile) vm; List routers = getRouters(network, dest); @@ -1049,7 +1049,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @Override public boolean prepareMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) { return true; @@ -1068,7 +1068,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @Override public void rollbackMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) { return; @@ -1086,7 +1086,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @Override public void commitMigration(NicProfile nic, Network network, - VirtualMachineProfile vm, + VirtualMachineProfile vm, ReservationContext src, ReservationContext dst) { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) { return; diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 966710c36c9..979d8fe2d3d 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -185,7 +185,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, + public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { diff --git a/server/src/com/cloud/network/guru/ControlNetworkGuru.java b/server/src/com/cloud/network/guru/ControlNetworkGuru.java index e7c5cba132d..6060dac4b8f 100755 --- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java @@ -106,7 +106,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if(vm.getHypervisorType() == HypervisorType.VMware && vm.getType() != VirtualMachine.Type.DomainRouter) { @@ -124,11 +124,11 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { } @Override - public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, + public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { assert nic.getTrafficType() == TrafficType.Control; @@ -163,7 +163,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { assert nic.getTrafficType() == TrafficType.Control; if (vm.getHypervisorType() == HypervisorType.VMware && vm.getType() == VirtualMachine.Type.DomainRouter) { diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java index b4577ac096a..5d0e7b1d9cf 100755 --- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java @@ -188,7 +188,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(network.getDataCenterId()); @@ -208,7 +208,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (nic.getIp4Address() == null && nic.getIp6Address() == null) { allocateDirectIp(nic, network, vm, dest.getDataCenter(), null, null); @@ -217,7 +217,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { } @DB - protected void allocateDirectIp(NicProfile nic, Network network, VirtualMachineProfile vm, DataCenter dc, String requestedIp4Addr, String requestedIp6Addr) + protected void allocateDirectIp(NicProfile nic, Network network, VirtualMachineProfile vm, DataCenter dc, String requestedIp4Addr, String requestedIp6Addr) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { @@ -236,7 +236,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { return true; } @@ -246,7 +246,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { } @Override @DB - public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { if (s_logger.isDebugEnabled()) { s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address()); } diff --git a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java index f21e352ff76..110096b7147 100755 --- a/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectPodBasedNetworkGuru.java @@ -88,7 +88,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenterVO dc = _dcDao.findById(network.getDataCenterId()); @@ -119,7 +119,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { } @Override @DB - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { String oldIp = nic.getIp4Address(); @@ -159,7 +159,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru { } @DB - protected void getIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, + protected void getIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(pod.getDataCenterId()); if (nic.getIp4Address() == null) { diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index 36ea6a5b359..9355d7795e6 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -198,7 +198,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } @Override - public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if (_networkModel.networkIsConfiguredForExternalNetworking(config.getDataCenterId(), config.getId()) && nic != null && nic.getRequestedIpv4() != null) { @@ -224,7 +224,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } @Override @DB - public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { super.deallocate(config, nic, vm); if (Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()))) { @@ -241,7 +241,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } @Override - public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? "; boolean _isEnabled = Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key())); @@ -278,7 +278,7 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { if (Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()))) { return true; diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index 9adffa222e0..f2eeb1252f7 100755 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -216,7 +216,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur } @Override @DB - public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { if (network.getSpecifyIpRanges()) { if (s_logger.isDebugEnabled()) { s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address()); @@ -316,7 +316,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { @@ -393,7 +393,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? "; @@ -403,7 +403,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { nic.setBroadcastUri(null); nic.setIsolationUri(null); return true; diff --git a/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java b/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java index 5a24fe56305..38624652c1b 100755 --- a/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java +++ b/server/src/com/cloud/network/guru/PodBasedNetworkGuru.java @@ -90,11 +90,11 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network config, NicProfile nic, VirtualMachineProfile vm) { } @Override - public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, + public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { TrafficType trafficType = config.getTrafficType(); assert trafficType == TrafficType.Management || trafficType == TrafficType.Storage: "Well, I can't take care of this config now can I? " + config; @@ -112,7 +112,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, + public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { Pod pod = dest.getPod(); @@ -144,7 +144,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { _dcDao.releasePrivateIpAddress(nic.getId(), nic.getReservationId()); nic.deallocate(); diff --git a/server/src/com/cloud/network/guru/PrivateNetworkGuru.java b/server/src/com/cloud/network/guru/PrivateNetworkGuru.java index 2e266e7b780..6521cf4e1dd 100644 --- a/server/src/com/cloud/network/guru/PrivateNetworkGuru.java +++ b/server/src/com/cloud/network/guru/PrivateNetworkGuru.java @@ -132,7 +132,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { if (s_logger.isDebugEnabled()) { s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address()); } @@ -153,7 +153,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { DataCenter dc = _configMgr.getZone(network.getDataCenterId()); NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); @@ -212,7 +212,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if (nic.getIp4Address() == null) { @@ -222,7 +222,7 @@ public class PrivateNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { return true; } diff --git a/server/src/com/cloud/network/guru/PublicNetworkGuru.java b/server/src/com/cloud/network/guru/PublicNetworkGuru.java index a83cdb37c69..8beb42e5831 100755 --- a/server/src/com/cloud/network/guru/PublicNetworkGuru.java +++ b/server/src/com/cloud/network/guru/PublicNetworkGuru.java @@ -107,7 +107,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { super(); } - protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, + protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (nic.getIp4Address() == null) { PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.VirtualNetwork, null, null, false); @@ -136,7 +136,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { @@ -164,7 +164,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { if (nic.getIp4Address() == null) { getIp(nic, dest.getDataCenter(), vm, network); @@ -172,7 +172,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { return true; } @@ -183,7 +183,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru { } @Override @DB - public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { if (s_logger.isDebugEnabled()) { s_logger.debug("public network deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address()); } diff --git a/server/src/com/cloud/network/guru/StorageNetworkGuru.java b/server/src/com/cloud/network/guru/StorageNetworkGuru.java index 1d01184e0c5..86dd5f6b996 100755 --- a/server/src/com/cloud/network/guru/StorageNetworkGuru.java +++ b/server/src/com/cloud/network/guru/StorageNetworkGuru.java @@ -103,7 +103,7 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) + public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { assert network.getTrafficType() == TrafficType.Storage : "Well, I can't take care of this config now can I? " + network; if (!_sNwMgr.isStorageIpRangeAvailable(network.getDataCenterId())) { @@ -114,7 +114,7 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) + public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { if (!_sNwMgr.isStorageIpRangeAvailable(dest.getDataCenter().getId())) { super.reserve(nic, network, vm, dest, context); @@ -146,7 +146,7 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { + public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) { Network nw = _nwDao.findById(nic.getNetworkId()); if (!_sNwMgr.isStorageIpRangeAvailable(nw.getDataCenterId())) { return super.release(nic, vm, reservationId); @@ -159,7 +159,7 @@ public class StorageNetworkGuru extends PodBasedNetworkGuru implements NetworkGu } @Override - public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { + public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) { // TODO Auto-generated method stub } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java index 72fddf4f87d..dbbc2d543ed 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManager.java @@ -61,13 +61,13 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA * @param routers TODO * */ - boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; - boolean saveSSHPublicKeyToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + boolean saveSSHPublicKeyToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers, String SSHPublicKey) throws ResourceUnavailableException; - boolean saveUserDataToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + boolean saveUserDataToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException; List deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, @@ -99,16 +99,16 @@ public interface VirtualNetworkApplianceManager extends Manager, VirtualNetworkA boolean applyStaticNats(Network network, final List rules, List routers) throws ResourceUnavailableException; - boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; - boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, + boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException; boolean applyLoadBalancingRules(Network network, List rules, List routers) throws ResourceUnavailableException; - boolean configDhcpForSubnet(Network network, NicProfile nic, VirtualMachineProfile uservm, DeployDestination dest, List routers) throws ResourceUnavailableException ; + boolean configDhcpForSubnet(Network network, NicProfile nic, VirtualMachineProfile uservm, DeployDestination dest, List routers) throws ResourceUnavailableException ; boolean removeDhcpSupportForSubnet(Network network, List routers) throws ResourceUnavailableException; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index dda2df8fa87..4859f0de038 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -261,7 +261,7 @@ import com.cloud.vm.dao.VMInstanceDao; @Component @Local(value = { VirtualNetworkApplianceManager.class, VirtualNetworkApplianceService.class }) public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements VirtualNetworkApplianceManager, VirtualNetworkApplianceService, - VirtualMachineGuru, Listener { + VirtualMachineGuru, Listener { private static final Logger s_logger = Logger.getLogger(VirtualNetworkApplianceManagerImpl.class); @Inject @@ -485,10 +485,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean savePasswordToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException { + public boolean savePasswordToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException { _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); - final VirtualMachineProfile updatedProfile = profile; + final VirtualMachineProfile updatedProfile = profile; return applyRules(network, routers, "save password entry", false, null, false, new RuleApplier() { @Override @@ -503,10 +503,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean saveSSHPublicKeyToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List routers, final String SSHPublicKey) throws ResourceUnavailableException { - _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); + public boolean saveSSHPublicKeyToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List routers, final String SSHPublicKey) throws ResourceUnavailableException { + final UserVmVO vm = _userVmDao.findById(profile.getVirtualMachine().getId()); + _userVmDao.loadDetails(vm); - final VirtualMachineProfile updatedProfile = profile; + final VirtualMachineProfile updatedProfile = profile; return applyRules(network, routers, "save SSHkey entry", false, null, false, new RuleApplier() { @Override @@ -518,17 +519,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V if(template != null && template.getEnablePassword()) { createPasswordCommand(router, updatedProfile, nicVo, cmds); } - createVmDataCommand(router, updatedProfile.getVirtualMachine(), nicVo, SSHPublicKey, cmds); + createVmDataCommand(router, vm, nicVo, SSHPublicKey, cmds); return sendCommandsToRouter(router, cmds); } }); } @Override - public boolean saveUserDataToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException { - _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); - - final VirtualMachineProfile updatedProfile = profile; + public boolean saveUserDataToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException { + final UserVmVO vm = _userVmDao.findById(profile.getVirtualMachine().getId()); + _userVmDao.loadDetails(vm); return applyRules(network, routers, "save userdata entry", false, null, false, new RuleApplier() { @Override @@ -536,7 +536,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V // for basic zone, send vm data/password information only to the router in the same pod Commands cmds = new Commands(OnError.Stop); NicVO nicVo = _nicDao.findById(nic.getId()); - createVmDataCommand(router, updatedProfile.getVirtualMachine(), nicVo, null, cmds); + createVmDataCommand(router, vm, nicVo, null, cmds); return sendCommandsToRouter(router, cmds); } }); @@ -1320,7 +1320,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } } } - + protected class CheckRouterTask implements Runnable { public CheckRouterTask() { @@ -1589,12 +1589,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { - if(s_logger.isTraceEnabled()) { - s_logger.trace("deployRouter(" + owner.getAccountName() + ", " + dest.getHost() + ", " + plan.toString() + ", " + params.toString() - + ", " + isRedundant + ", " + vrProvider.getUuid() + ", " + svcOffId + ", " + vpcId - + ", list_of_" + networks.size() + "networks, " + startRouter + ", " + supportedHypervisors + ")"); - } - ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); // Router is the network element, we don't know the hypervisor type yet. @@ -1872,11 +1866,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - - if(s_logger.isTraceEnabled()) { - s_logger.trace("startVirtualRouter(" + router.getHostName() + ", " + user.getUsername() + ", " + caller.getAccountName() + ", " + params.toString() + ")"); - } - + if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) { return this.start(router, user, caller, params, null); } @@ -1989,7 +1979,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { boolean dnsProvided = true; @@ -1999,7 +1989,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V _dcDao.loadDetails(dc); //1) Set router details - DomainRouterVO router = profile.getVirtualMachine(); + DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId()); Map details = _vmDetailsDao.findDetails(router.getId()); router.setDetails(details); @@ -2272,9 +2262,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { - DomainRouterVO router = profile.getVirtualMachine(); + DomainRouterVO router = _routerDao.findById(profile.getId()); List nics = profile.getNics(); for (NicProfile nic : nics) { @@ -2294,8 +2284,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - DomainRouterVO router = profile.getVirtualMachine(); + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + DomainRouterVO router = _routerDao.findById(profile.getId()); NicProfile controlNic = getControlNic(profile); if (controlNic == null) { @@ -2334,8 +2324,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return true; } - protected NicProfile getControlNic(VirtualMachineProfile profile) { - DomainRouterVO router = profile.getVirtualMachine(); + protected NicProfile getControlNic(VirtualMachineProfile profile) { + DomainRouterVO router = _routerDao.findById(profile.getId()); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); NicProfile controlNic = null; if (profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) { @@ -2356,7 +2346,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return controlNic; } - protected void finalizeSshAndVersionAndNetworkUsageOnStart(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, NicProfile controlNic) { + protected void finalizeSshAndVersionAndNetworkUsageOnStart(Commands cmds, VirtualMachineProfile profile, DomainRouterVO router, NicProfile controlNic) { + DomainRouterVO vr = _routerDao.findById(profile.getId()); cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922)); // Update router template/scripts version @@ -2366,7 +2357,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V cmds.addCommand("getDomRVersion", command); // Network usage command to create iptables rules - boolean forVpc = profile.getVirtualMachine().getVpcId() != null; + boolean forVpc = vr.getVpcId() != null; if (!forVpc) cmds.addCommand("networkUsage", new NetworkUsageCommand(controlNic.getIp4Address(), router.getHostName(), "create", forVpc)); } @@ -2510,7 +2501,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V createIpAlias(router, activeIpAliasTOs, guestNetworkId, cmds); configDnsMasq(router, _networkDao.findById(guestNetworkId), cmds); } - } } } @@ -2572,9 +2562,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { - DomainRouterVO router = profile.getVirtualMachine(); + DomainRouterVO router = _routerDao.findById(profile.getId()); boolean result = true; @@ -2631,9 +2621,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { if (answer != null) { - VMInstanceVO vm = profile.getVirtualMachine(); + VirtualMachine vm = profile.getVirtualMachine(); DomainRouterVO domR = _routerDao.findById(vm.getId()); processStopOrRebootAnswer(domR, answer); List routerNics = _nicDao.listByVmId(profile.getId()); @@ -2649,7 +2639,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public void finalizeExpunge(DomainRouterVO vm) { + public void finalizeExpunge(VirtualMachine vm) { } @@ -2746,43 +2736,37 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Starting router " + router); - if (_itMgr.start(router, params, user, caller, planToDeploy) != null) { - if (router.isStopPending()) { - s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); - router.setStopPending(false); - router = _routerDao.persist(router); - } - // We don't want the failure of VPN Connection affect the status of router, so we try to make connection - // only after router start successfully - Long vpcId = router.getVpcId(); - if (vpcId != null) { - _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); - } - return _routerDao.findById(router.getId()); - } else { - return null; + _itMgr.start(router.getUuid(), params, planToDeploy); + if (router.isStopPending()) { + s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!"); + router.setStopPending(false); + router = _routerDao.persist(router); } + // We don't want the failure of VPN Connection affect the status of router, so we try to make connection + // only after router start successfully + Long vpcId = router.getVpcId(); + if (vpcId != null) { + _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId); + } + return _routerDao.findById(router.getId()); } @Override public DomainRouterVO stop(VirtualRouter router, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException { s_logger.debug("Stopping router " + router); try { - if (_itMgr.advanceStop((DomainRouterVO) router, forced, user, caller)) { - return _routerDao.findById(router.getId()); - } else { - return null; - } + _itMgr.advanceStop(router.getUuid(), forced); + return _routerDao.findById(router.getId()); } catch (OperationTimedoutException e) { throw new CloudRuntimeException("Unable to stop " + router, e); } } @Override - public boolean configDhcpForSubnet(Network network, final NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, List routers) throws ResourceUnavailableException { - _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); + public boolean configDhcpForSubnet(Network network, final NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, List routers) throws ResourceUnavailableException { + UserVmVO vm = _userVmDao.findById(profile.getId()); + _userVmDao.loadDetails(vm); - final VirtualMachineProfile updatedProfile = profile; final boolean isZoneBasic = (dest.getDataCenter().getNetworkType() == NetworkType.Basic); final Long podId = isZoneBasic ? dest.getPod().getId() : null; @@ -2794,7 +2778,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V router.getState(), DataCenter.class, network.getDataCenterId()); } //check if this is not the primary subnet. - UserVm vm = updatedProfile.getVirtualMachine(); NicVO domr_guest_nic = _nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(), _nicDao.getIpAddress(nic.getNetworkId(), router.getId()), VirtualMachine.Type.DomainRouter); //check if the router ip address and the vm ip address belong to same subnet. //if they do not belong to same netwoek check for the alias ips. if not create one. @@ -2909,15 +2892,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @Override - public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile profile, + public boolean applyDhcpEntry(Network network, final NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, List routers) throws ResourceUnavailableException { if(s_logger.isTraceEnabled()) { s_logger.trace("applyDhcpEntry(" + network.getCidr() + ", " + nic.getMacAddress() + ", " + profile.getUuid() + ", " + dest.getHost() + ", " + routers + ")"); } - _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); + final UserVmVO vm = _userVmDao.findById(profile.getId()); + _userVmDao.loadDetails(vm); - final VirtualMachineProfile updatedProfile = profile; + final VirtualMachineProfile updatedProfile = profile; final boolean isZoneBasic = (dest.getDataCenter().getNetworkType() == NetworkType.Basic); final Long podId = isZoneBasic ? dest.getPod().getId() : null; @@ -2935,7 +2919,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V Commands cmds = new Commands(OnError.Stop); if (!(isZoneBasic && router.getPodIdToDeployIn().longValue() != podId.longValue() && _dnsBasicZoneUpdates.equalsIgnoreCase("pod"))) { NicVO nicVo = _nicDao.findById(nic.getId()); - createDhcpEntryCommand(router, updatedProfile.getVirtualMachine(), nicVo, cmds); + createDhcpEntryCommand(router, vm, nicVo, cmds); return sendCommandsToRouter(router, cmds); } return true; @@ -2987,11 +2971,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } @Override - public boolean applyUserData(Network network, final NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, List routers) + public boolean applyUserData(Network network, final NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, List routers) throws ResourceUnavailableException { - _userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); + final UserVmVO vm = _userVmDao.findById(profile.getId()); + _userVmDao.loadDetails(vm); - final VirtualMachineProfile updatedProfile = profile; + final VirtualMachineProfile updatedProfile = profile; final boolean isZoneBasic = (dest.getDataCenter().getNetworkType() == NetworkType.Basic); final Long podId = isZoneBasic ? dest.getPod().getId() : null; @@ -3010,7 +2995,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V if (!(isZoneBasic && router.getPodIdToDeployIn().longValue() != podId.longValue())) { NicVO nicVo = _nicDao.findById(nic.getId()); createPasswordCommand(router, updatedProfile, nicVo, cmds); - createVmDataCommand(router, updatedProfile.getVirtualMachine(), nicVo, updatedProfile.getVirtualMachine().getDetail("SSH.PublicKey"), cmds); + createVmDataCommand(router, vm, nicVo, vm.getDetail("SSH.PublicKey"), cmds); return sendCommandsToRouter(router, cmds); } return true; @@ -3077,11 +3062,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V return result; } - @Override - public DomainRouterVO findById(long id) { - return _routerDao.findById(id); - } - @Override @ActionEvent(eventType = EventTypes.EVENT_ROUTER_START, eventDescription = "starting router Vm", async = true) public VirtualRouter startRouter(long id) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException{ return startRouter(id, true); @@ -3369,7 +3349,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V cmds.addCommand("startVpn", startVpnCmd); } - private void createPasswordCommand(VirtualRouter router, VirtualMachineProfile profile, NicVO nic, Commands cmds) { + private void createPasswordCommand(VirtualRouter router, VirtualMachineProfile profile, NicVO nic, Commands cmds) { String password = (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword); DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); @@ -3448,9 +3428,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V } private void configDnsMasq(VirtualRouter router, Network network, Commands cmds) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("configDnsMasq(" + router.getHostName() + ", " + network.getNetworkDomain() + ", " + cmds + ")"); - } DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); List ipAliasVOList = _nicIpAliasDao.listByNetworkIdAndState(network.getId(), NicIpAlias.state.active); List ipList = new ArrayList(); @@ -3482,7 +3459,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V dnsMasqConfigCmd.setDomainSuffix(domain_suffix); dnsMasqConfigCmd.setIfDnsProvided(dnsProvided); cmds.addCommand("dnsMasqConfig" ,dnsMasqConfigCmd); - //To change body of created methods use File | Settings | File Templates. } @@ -3981,11 +3957,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V @Override - public void prepareStop(VirtualMachineProfile profile){ + public void prepareStop(VirtualMachineProfile profile){ //Collect network usage before stopping Vm - VMInstanceVO vm = profile.getVirtualMachine(); - DomainRouterVO router = _routerDao.findById(vm.getId()); + DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId()); if(router == null){ return; } diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 3ca4331eedf..6fafa3e40fc 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -27,7 +27,6 @@ import java.util.TreeSet; import javax.ejb.Local; import javax.inject.Inject; -import com.cloud.configuration.ZoneConfig; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -38,14 +37,12 @@ import com.cloud.agent.api.PlugNicCommand; import com.cloud.agent.api.SetupGuestNetworkAnswer; import com.cloud.agent.api.SetupGuestNetworkCommand; import com.cloud.agent.api.StopAnswer; -import com.cloud.agent.api.routing.DnsMasqConfigCommand; import com.cloud.agent.api.routing.IpAssocVpcCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.SetNetworkACLCommand; import com.cloud.agent.api.routing.SetSourceNatCommand; import com.cloud.agent.api.routing.SetStaticRouteCommand; import com.cloud.agent.api.routing.Site2SiteVpnCfgCommand; -import com.cloud.agent.api.to.DhcpTO; import com.cloud.agent.api.to.IpAddressTO; import com.cloud.agent.api.to.NetworkACLTO; import com.cloud.agent.api.to.NicTO; @@ -167,9 +164,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian public List deployVirtualRouterInVpc(Vpc vpc, DeployDestination dest, Account owner, Map params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - if(s_logger.isTraceEnabled()) { - s_logger.trace("deployVirtualRouterInVpc(" + vpc.getName() +", "+dest.getHost()+", "+owner.getAccountName()+", "+params.toString()+")"); - } List routers = findOrDeployVirtualRouterInVpc(vpc, dest, owner, params); @@ -247,9 +241,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian @Override public boolean addVpcRouterToGuestNetwork(VirtualRouter router, Network network, boolean isRedundant) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - if (s_logger.isTraceEnabled()) { - s_logger.trace("addVpcRouterToGuestNetwork(" + router.getUuid() + ", " + network.getCidr() + ", " + isRedundant + ")"); - } + if (network.getTrafficType() != TrafficType.Guest) { s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); return false; @@ -321,10 +313,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian Long vpcId, PublicIp sourceNatIp) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { - if(s_logger.isTraceEnabled()) { - s_logger.trace("deployVpcRouter(" + owner.getAccountName() + ", " + dest.getHost() + ", " + plan.toString() + ", " + params.toString() - + ", " + isRedundant + ", " + vrProvider.getUuid() + ", " + svcOffId + ", " + vpcId + ", " + sourceNatIp + ")"); - } + List> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair(true, sourceNatIp), vpcId); DomainRouterVO router = @@ -607,10 +596,11 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + DomainRouterVO vr = _routerDao.findById(profile.getId()); - if (profile.getVirtualMachine().getVpcId() != null) { + if (vr.getVpcId() != null) { String defaultDns1 = null; String defaultDns2 = null; //remove public and guest nics as we will plug them later @@ -631,7 +621,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian //add vpc cidr/dns/networkdomain to the boot load args StringBuilder buf = profile.getBootArgsBuilder(); - Vpc vpc = _vpcMgr.getVpc(profile.getVirtualMachine().getVpcId()); + Vpc vpc = _vpcMgr.getVpc(vr.getVpcId()); buf.append(" vpccidr=" + vpc.getCidr() + " domain=" + vpc.getNetworkDomain()); buf.append(" dns1=").append(defaultDns1); @@ -703,17 +693,14 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } @Override - public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { - DomainRouterVO router = profile.getVirtualMachine(); - if(s_logger.isTraceEnabled()) { - s_logger.trace("finalizeCommandsOnStart(" + cmds + ", " + profile.getHostName() + ")"); - } + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + DomainRouterVO router = _routerDao.findById(profile.getId()); boolean isVpc = (router.getVpcId() != null); if (!isVpc) { return super.finalizeCommandsOnStart(cmds, profile); } - + //1) FORM SSH CHECK COMMAND NicProfile controlNic = getControlNic(profile); if (controlNic == null) { @@ -722,7 +709,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, router, controlNic); - + //2) FORM PLUG NIC COMMANDS List> guestNics = new ArrayList>(); List> publicNics = new ArrayList>(); @@ -875,49 +862,15 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian //Add network usage commands cmds.addCommands(usageCmds); - configDnsMasq(router, cmds); - + return true; } - protected void configDnsMasq(VirtualRouter router, Commands cmds) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("configDnsMasq(" + router.getHostName() + ", " + cmds + ")"); - } - VpcVO vpc = _vpcDao.findById(router.getVpcId()); - DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); - List ipList = new ArrayList(); - - String cidr = vpc.getCidr(); - String[] cidrPair = cidr.split("\\/"); - String cidrAddress = cidrPair[0]; - long cidrSize = Long.parseLong(cidrPair[1]); - String startIpOfSubnet = NetUtils.getIpRangeStartIpFromCidr(cidrAddress, cidrSize); - DhcpTO DhcpTO = new DhcpTO(router.getPrivateIpAddress(), router.getPublicIpAddress(), NetUtils.getCidrNetmask(cidrSize), startIpOfSubnet); - ipList.add(DhcpTO); - - NicVO nic = _nicDao.findByIp4AddressAndVmId(_routerDao.findById(router.getId()).getPrivateIpAddress(), router.getId()); - DataCenterVO dcvo = _dcDao.findById(router.getDataCenterId()); - boolean dnsProvided = _networkModel.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter); - String domain_suffix = dcvo.getDetail(ZoneConfig.DnsSearchOrder.getName()); - DnsMasqConfigCommand dnsMasqConfigCmd = new DnsMasqConfigCommand(vpc.getNetworkDomain(),ipList, dcVo.getDns1(), dcVo.getDns2(), dcVo.getInternalDns1(), dcVo.getInternalDns2()); - dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId())); - dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); - dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getPublicIpAddress()); - dnsMasqConfigCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); - dnsMasqConfigCmd.setDomainSuffix(domain_suffix); - dnsMasqConfigCmd.setIfDnsProvided(dnsProvided); - - cmds.addCommand("dnsMasqConfig" ,dnsMasqConfigCmd); - } - - @Override protected void finalizeNetworkRulesForNetwork(Commands cmds, DomainRouterVO router, Provider provider, Long guestNetworkId) { - if(s_logger.isTraceEnabled()) { - s_logger.trace("finalizing network config for "+ router.getHostName()); - } + super.finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId); + if (router.getVpcId() != null) { if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.NetworkACL, Provider.VPCVirtualRouter)) { List networkACLs = _networkACLMgr.listNetworkACLItems(guestNetworkId); @@ -927,10 +880,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian createNetworkACLsCommands(networkACLs, router, cmds, guestNetworkId, false); } } - - if(s_logger.isDebugEnabled()) { - s_logger.debug("setup the vpc domain on router " + router.getHostName()); - } } } @@ -975,10 +924,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian */ protected boolean setupVpcPrivateNetwork(VirtualRouter router, boolean add, NicProfile privateNic) throws ResourceUnavailableException { - if(s_logger.isTraceEnabled()) { - s_logger.trace("deployVpcRouter(" + router.getHostName() + ", " + add + ", " + privateNic.getMacAddress() + ")"); - } - + if (router.getState() == State.Running) { PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIp4Address()); Network network = _networkDao.findById(privateNic.getNetworkId()); @@ -990,7 +936,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian privateIps.add(ip); Commands cmds = new Commands(OnError.Stop); createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add); - + if (sendCommandsToRouter(router, cmds)) { s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc network " + network); return true; @@ -1371,10 +1317,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian } @Override - public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { super.finalizeStop(profile, answer); //Mark VPN connections as Disconnected - DomainRouterVO router = profile.getVirtualMachine(); + DomainRouterVO router = _routerDao.findById(profile.getId()); Long vpcId = router.getVpcId(); if (vpcId != null) { _s2sVpnMgr.markDisconnectVpnConnByVpc(vpcId); diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 830aaa14a28..342b9fd03dc 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -2043,8 +2043,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, s_logger.debug("Deleting Host: " + host.getId() + " Guid:" + host.getGuid()); } - User caller = _accountMgr.getActiveUser(CallContext.current().getCallingUserId()); - if (forceDestroyStorage) { // put local storage into mainenance mode, will set all the VMs on // this local storage into stopped state @@ -2067,11 +2065,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, List vmsOnLocalStorage = _storageMgr.listByStoragePool(storagePool.getId()); for (VMInstanceVO vm : vmsOnLocalStorage) { try { - if (!_vmMgr.destroy(vm, caller, _accountMgr.getAccount(vm.getAccountId()))) { - String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host.getId(); - s_logger.warn(errorMsg); - throw new UnableDeleteHostException(errorMsg); - } + _vmMgr.destroy(vm.getUuid()); } catch (Exception e) { String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host.getId(); s_logger.debug(errorMsg, e); @@ -2090,11 +2084,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager, if (!vm.isHaEnabled() || vm.getState() == State.Stopping) { s_logger.debug("Stopping vm: " + vm + " as a part of deleteHost id=" + host.getId()); try { - if (!_vmMgr.advanceStop(vm, true, caller, _accountMgr.getAccount(vm.getAccountId()))) { - String errorMsg = "There was an error stopping the vm: " + vm + " as a part of hostDelete id=" + host.getId(); - s_logger.warn(errorMsg); - throw new UnableDeleteHostException(errorMsg); - } + _vmMgr.advanceStop(vm.getUuid(), false); } catch (Exception e) { String errorMsg = "There was an error stopping the vm: " + vm + " as a part of hostDelete id=" + host.getId(); s_logger.debug(errorMsg, e); diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 9a9b1456d1d..febb6d2fe7e 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -1299,8 +1299,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio @DB public void updateResourceCount() { ResourceType[] resourceTypes = Resource.ResourceType.values(); - List accounts = _accountDao.listAllIncludingRemoved(); - List domains = _domainDao.listAllIncludingRemoved(); + List accounts = _accountDao.listAll(); + List domains = _domainDao.listAll(); List domainResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Domain); List accountResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Account); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 8d979c7d1c2..7ac12547090 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -39,23 +39,15 @@ import javax.crypto.spec.SecretKeySpec; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.exception.*; -import com.cloud.vm.*; - -import org.apache.cloudstack.acl.ControlledEntity; -import org.apache.cloudstack.acl.SecurityChecker.AccessType; -import org.apache.cloudstack.api.ApiConstants; - -import com.cloud.event.ActionEventUtils; - -import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd; -import org.apache.cloudstack.api.command.admin.region.*; - import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; +import org.apache.cloudstack.acl.ControlledEntity; +import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroupProcessor; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd; import org.apache.cloudstack.api.command.admin.account.CreateAccountCmd; import org.apache.cloudstack.api.command.admin.account.DeleteAccountCmd; import org.apache.cloudstack.api.command.admin.account.DisableAccountCmd; @@ -69,6 +61,7 @@ import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd; import org.apache.cloudstack.api.command.admin.cluster.UpdateClusterCmd; import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd; +import org.apache.cloudstack.api.command.admin.config.ListDeploymentPlannersCmd; import org.apache.cloudstack.api.command.admin.config.ListHypervisorCapabilitiesCmd; import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd; import org.apache.cloudstack.api.command.admin.config.UpdateHypervisorCapabilitiesCmd; @@ -129,6 +122,12 @@ import org.apache.cloudstack.api.command.admin.pod.CreatePodCmd; import org.apache.cloudstack.api.command.admin.pod.DeletePodCmd; import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd; import org.apache.cloudstack.api.command.admin.pod.UpdatePodCmd; +import org.apache.cloudstack.api.command.admin.region.AddRegionCmd; +import org.apache.cloudstack.api.command.admin.region.CreatePortableIpRangeCmd; +import org.apache.cloudstack.api.command.admin.region.DeletePortableIpRangeCmd; +import org.apache.cloudstack.api.command.admin.region.ListPortableIpRangesCmd; +import org.apache.cloudstack.api.command.admin.region.RemoveRegionCmd; +import org.apache.cloudstack.api.command.admin.region.UpdateRegionCmd; import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd; import org.apache.cloudstack.api.command.admin.resource.CleanVMReservationsCmd; import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd; @@ -159,7 +158,14 @@ import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd; import org.apache.cloudstack.api.command.admin.storage.ListStorageProvidersCmd; import org.apache.cloudstack.api.command.admin.storage.PreparePrimaryStorageForMaintenanceCmd; import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd; -import org.apache.cloudstack.api.command.admin.systemvm.*; +import org.apache.cloudstack.api.command.admin.systemvm.DestroySystemVmCmd; +import org.apache.cloudstack.api.command.admin.systemvm.ListSystemVMsCmd; +import org.apache.cloudstack.api.command.admin.systemvm.MigrateSystemVMCmd; +import org.apache.cloudstack.api.command.admin.systemvm.RebootSystemVmCmd; +import org.apache.cloudstack.api.command.admin.systemvm.ScaleSystemVMCmd; +import org.apache.cloudstack.api.command.admin.systemvm.StartSystemVMCmd; +import org.apache.cloudstack.api.command.admin.systemvm.StopSystemVmCmd; +import org.apache.cloudstack.api.command.admin.systemvm.UpgradeSystemVMCmd; import org.apache.cloudstack.api.command.admin.template.PrepareTemplateCmd; import org.apache.cloudstack.api.command.admin.usage.AddTrafficMonitorCmd; import org.apache.cloudstack.api.command.admin.usage.AddTrafficTypeCmd; @@ -309,8 +315,8 @@ import org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadB import org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd; import org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd; import org.apache.cloudstack.api.command.user.region.ha.gslb.ListGlobalLoadBalancerRuleCmd; -import org.apache.cloudstack.api.command.user.region.ha.gslb.UpdateGlobalLoadBalancerRuleCmd; import org.apache.cloudstack.api.command.user.region.ha.gslb.RemoveFromGlobalLoadBalancerRuleCmd; +import org.apache.cloudstack.api.command.user.region.ha.gslb.UpdateGlobalLoadBalancerRuleCmd; import org.apache.cloudstack.api.command.user.resource.GetCloudIdentifierCmd; import org.apache.cloudstack.api.command.user.resource.ListHypervisorsCmd; import org.apache.cloudstack.api.command.user.resource.ListResourceLimitsCmd; @@ -372,7 +378,19 @@ import org.apache.cloudstack.api.command.user.vmsnapshot.CreateVMSnapshotCmd; import org.apache.cloudstack.api.command.user.vmsnapshot.DeleteVMSnapshotCmd; import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd; import org.apache.cloudstack.api.command.user.vmsnapshot.RevertToVMSnapshotCmd; -import org.apache.cloudstack.api.command.user.volume.*; +import org.apache.cloudstack.api.command.user.volume.AddResourceDetailCmd; +import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.DeleteVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.ListResourceDetailsCmd; +import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; +import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.RemoveResourceDetailCmd; +import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.UpdateVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd; import org.apache.cloudstack.api.command.user.vpc.CreateStaticRouteCmd; import org.apache.cloudstack.api.command.user.vpc.CreateVPCCmd; import org.apache.cloudstack.api.command.user.vpc.DeleteStaticRouteCmd; @@ -401,6 +419,7 @@ import org.apache.cloudstack.api.command.user.vpn.RemoveVpnUserCmd; import org.apache.cloudstack.api.command.user.vpn.ResetVpnConnectionCmd; import org.apache.cloudstack.api.command.user.vpn.UpdateVpnCustomerGatewayCmd; import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; @@ -451,9 +470,17 @@ import com.cloud.deploy.DeploymentPlanningManager; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.ActionEvent; +import com.cloud.event.ActionEventUtils; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.DetailVO; import com.cloud.host.Host; @@ -491,9 +518,9 @@ import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.GuestOSVO; import com.cloud.storage.GuestOsCategory; import com.cloud.storage.Storage.ImageFormat; +import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; -import com.cloud.storage.Storage.TemplateType; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; import com.cloud.storage.VolumeManager; @@ -542,7 +569,18 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.NetUtils; import com.cloud.utils.ssh.SSHKeysHelper; +import com.cloud.vm.ConsoleProxyVO; +import com.cloud.vm.DiskProfile; +import com.cloud.vm.InstanceGroupVO; +import com.cloud.vm.SecondaryStorageVmVO; +import com.cloud.vm.UserVmManager; +import com.cloud.vm.UserVmVO; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachineManager; +import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.VirtualMachineProfileImpl; import com.cloud.vm.dao.ConsoleProxyDao; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.InstanceGroupDao; @@ -553,12 +591,6 @@ import com.cloud.vm.dao.VMInstanceDao; import edu.emory.mathcs.backport.java.util.Arrays; import edu.emory.mathcs.backport.java.util.Collections; -import org.apache.cloudstack.api.command.admin.region.AddRegionCmd; -import org.apache.cloudstack.api.command.admin.region.RemoveRegionCmd; -import org.apache.cloudstack.api.command.admin.region.UpdateRegionCmd; -import org.apache.cloudstack.api.command.admin.config.ListDeploymentPlannersCmd; -import org.apache.cloudstack.context.CallContext; - public class ManagementServerImpl extends ManagerBase implements ManagementServer { public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName()); @@ -725,7 +757,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe return _affinityProcessors; } public void setAffinityGroupProcessors(List affinityProcessors) { - this._affinityProcessors = affinityProcessors; + _affinityProcessors = affinityProcessors; } public ManagementServerImpl() { @@ -1060,7 +1092,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe } // Check if the vm is using any disks on local storage. - VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); List volumes = _volumeDao.findCreatedByInstance(vmProfile.getId()); boolean usesLocal = false; for (VolumeVO volume : volumes) { @@ -1156,7 +1188,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe suitableHosts, requiresStorageMotion); } - private Map> findSuitablePoolsForVolumes(VirtualMachineProfile vmProfile, + private Map> findSuitablePoolsForVolumes(VirtualMachineProfile vmProfile, Host host) { List volumes = _volumeDao.findCreatedByInstance(vmProfile.getId()); Map> suitableVolumeStoragePools = new HashMap>(); @@ -1272,7 +1304,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe storagePools.remove(srcVolumePool); for (StoragePoolVO pool : storagePools) { if (pool.isShared()) { - allPools.add((StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId())); + allPools.add((StoragePool)dataStoreMgr.getPrimaryDataStore(pool.getId())); } } @@ -1284,7 +1316,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe // Volume stays in the same cluster after migration. DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), srcVolumePool.getPodId(), srcVolumePool.getClusterId(), null, null, null); - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType()); @@ -2060,12 +2092,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe private ConsoleProxyVO stopConsoleProxy(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { - User caller = _userDao.findById(CallContext.current().getCallingUserId()); - - if (_itMgr.advanceStop(systemVm, isForced, caller, CallContext.current().getCallingAccount())) { - return _consoleProxyDao.findById(systemVm.getId()); - } - return null; + _itMgr.advanceStop(systemVm.getUuid(), isForced); + return _consoleProxyDao.findById(systemVm.getId()); } @ActionEvent(eventType = EventTypes.EVENT_PROXY_REBOOT, eventDescription = "rebooting console proxy Vm", async = true) @@ -2949,12 +2977,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe private SecondaryStorageVmVO stopSecondaryStorageVm(VMInstanceVO systemVm, boolean isForced) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { - User caller = _userDao.findById(CallContext.current().getCallingUserId()); - - if (_itMgr.advanceStop(systemVm, isForced, caller, CallContext.current().getCallingAccount())) { - return _secStorageVmDao.findById(systemVm.getId()); - } - return null; + _itMgr.advanceStop(systemVm.getUuid(), isForced); + return _secStorageVmDao.findById(systemVm.getId()); } @ActionEvent(eventType = EventTypes.EVENT_SSVM_REBOOT, eventDescription = "rebooting secondary storage Vm", async = true) diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java index 097986bda62..fe2052e7908 100644 --- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java +++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java @@ -35,12 +35,16 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.cloudstack.api.IdentityService; import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.springframework.web.context.support.SpringBeanAutowiringSupport; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import org.apache.cloudstack.api.IdentityService; + import com.cloud.exception.PermissionDeniedException; import com.cloud.host.HostVO; import com.cloud.server.ManagementServer; @@ -51,12 +55,10 @@ import com.cloud.user.User; import com.cloud.uservm.UserVm; import com.cloud.utils.Pair; import com.cloud.utils.Ternary; +import com.cloud.utils.db.EntityManager; import com.cloud.utils.db.Transaction; -import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineManager; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; /** * Thumbnail access : /console?cmd=thumbnail&vm=xxx&w=xxx&h=xxx @@ -74,10 +76,12 @@ public class ConsoleProxyServlet extends HttpServlet { @Inject VirtualMachineManager _vmMgr; @Inject ManagementServer _ms; @Inject IdentityService _identityService; + @Inject + EntityManager _entityMgr; static ManagementServer s_ms; - private Gson _gson = new GsonBuilder().create(); + private final Gson _gson = new GsonBuilder().create(); public ConsoleProxyServlet() { } @@ -179,7 +183,7 @@ public class ConsoleProxyServlet extends HttpServlet { } private void handleThumbnailRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) { - VMInstanceVO vm = _vmMgr.findById(vmId); + VirtualMachine vm = _vmMgr.findById(vmId); if(vm == null) { s_logger.warn("VM " + vmId + " does not exist, sending blank response for thumbnail request"); sendResponse(resp, ""); @@ -230,7 +234,7 @@ public class ConsoleProxyServlet extends HttpServlet { } private void handleAccessRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) { - VMInstanceVO vm = _vmMgr.findById(vmId); + VirtualMachine vm = _vmMgr.findById(vmId); if(vm == null) { s_logger.warn("VM " + vmId + " does not exist, sending blank response for console access request"); sendResponse(resp, ""); @@ -258,7 +262,7 @@ public class ConsoleProxyServlet extends HttpServlet { String vmName = vm.getHostName(); if(vm.getType() == VirtualMachine.Type.User) { - UserVm userVm = (UserVm)_vmMgr.findByIdAndType(VirtualMachine.Type.User, vmId); + UserVm userVm = _entityMgr.findById(UserVm.class, vmId); String displayName = userVm.getDisplayName(); if(displayName != null && !displayName.isEmpty() && !displayName.equals(vmName)) { vmName += "(" + displayName + ")"; @@ -276,7 +280,7 @@ public class ConsoleProxyServlet extends HttpServlet { // TODO authentication channel between console proxy VM and management server needs to be secured, // the data is now being sent through private network, but this is apparently not enough - VMInstanceVO vm = _vmMgr.findById(vmId); + VirtualMachine vm = _vmMgr.findById(vmId); if(vm == null) { s_logger.warn("VM " + vmId + " does not exist, sending failed response for authentication request from console proxy"); sendResponse(resp, "failed"); @@ -339,7 +343,7 @@ public class ConsoleProxyServlet extends HttpServlet { return _gson.toJson(keyIvPair); } - private String composeThumbnailUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo, int w, int h) { + private String composeThumbnailUrl(String rootUrl, VirtualMachine vm, HostVO hostVo, int w, int h) { StringBuffer sb = new StringBuffer(rootUrl); String host = hostVo.getPrivateIpAddress(); @@ -374,7 +378,7 @@ public class ConsoleProxyServlet extends HttpServlet { return sb.toString(); } - private String composeConsoleAccessUrl(String rootUrl, VMInstanceVO vm, HostVO hostVo) { + private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO hostVo) { StringBuffer sb = new StringBuffer(rootUrl); String host = hostVo.getPrivateIpAddress(); @@ -454,7 +458,7 @@ public class ConsoleProxyServlet extends HttpServlet { private boolean checkSessionPermision(HttpServletRequest req, long vmId, Account accountObj) { - VMInstanceVO vm = _vmMgr.findById(vmId); + VirtualMachine vm = _vmMgr.findById(vmId); if(vm == null) { s_logger.debug("Console/thumbnail access denied. VM " + vmId + " does not exist in system any more"); return false; diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 8a5085ef1f3..cd966cdd565 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -403,7 +403,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C public StoragePool findStoragePool(DiskProfile dskCh, final DataCenterVO dc, Pod pod, Long clusterId, Long hostId, VMInstanceVO vm, final Set avoid) { - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); for (StoragePoolAllocator allocator : _storagePoolAllocators) { ExcludeList avoidList = new ExcludeList(); diff --git a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java index 5c971837ab1..f0f6eaf8073 100644 --- a/server/src/com/cloud/storage/StoragePoolAutomationImpl.java +++ b/server/src/com/cloud/storage/StoragePoolAutomationImpl.java @@ -23,22 +23,22 @@ import java.util.List; import javax.inject.Inject; -import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.engine.subsystem.api.storage.*; -import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; -import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; - import org.apache.log4j.Logger; import org.springframework.stereotype.Component; +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; + import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ModifyStoragePoolCommand; import com.cloud.alert.AlertManager; -import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; -import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceManager; import com.cloud.server.ManagementServer; import com.cloud.storage.dao.StoragePoolHostDao; @@ -48,7 +48,6 @@ import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.user.dao.UserDao; import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.utils.exception.ExecutionException; import com.cloud.vm.ConsoleProxyVO; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.SecondaryStorageVmVO; @@ -100,18 +99,19 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { VMInstanceDao vmDao; @Inject ManagementServer server; - @Inject DataStoreProviderManager providerMgr; + @Inject + DataStoreProviderManager providerMgr; @Override public boolean maintain(DataStore store) { Long userId = CallContext.current().getCallingUserId(); User user = _userDao.findById(userId); Account account = CallContext.current().getCallingAccount(); - StoragePoolVO pool = this.primaryDataStoreDao.findById(store.getId()); + StoragePoolVO pool = primaryDataStoreDao.findById(store.getId()); try { List spes = null; // Handling Zone and Cluster wide storage scopes. - // if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS + // if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS if (pool.getScope() == ScopeType.ZONE) { spes = primaryDataStoreDao.listBy( pool.getDataCenterId(), null, @@ -128,14 +128,14 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { + " is already in PrepareForMaintenance mode "); } } - StoragePool storagePool = (StoragePool) store; + StoragePool storagePool = (StoragePool)store; //Handeling the Zone wide and cluster wide primay storage List hosts = new ArrayList(); // if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand //TODO: if it's zone wide, this code will list a lot of hosts in the zone, which may cause performance/OOM issue. if (pool.getScope().equals(ScopeType.ZONE)) { - hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor() , pool.getDataCenterId()); + hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId()); } else { hosts = _resourceMgr.listHostsInClusterByStatus( pool.getClusterId(), Status.Up); @@ -159,7 +159,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { if (s_logger.isDebugEnabled()) { s_logger.debug("ModifyStoragePool false failed due to " + ((answer == null) ? "answer null" : answer - .getDetails())); + .getDetails())); } } else { if (s_logger.isDebugEnabled()) { @@ -179,7 +179,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { } // 2. Get a list of all the ROOT volumes within this storage pool - List allVolumes = this.volumeDao.findByPoolId(pool + List allVolumes = volumeDao.findByPoolId(pool .getId()); // 3. Enqueue to the work queue @@ -234,81 +234,45 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { if (vmInstance.getType().equals( VirtualMachine.Type.ConsoleProxy)) { // call the consoleproxymanager - ConsoleProxyVO consoleProxy = _consoleProxyDao - .findById(vmInstance.getId()); - if (!vmMgr.advanceStop(consoleProxy, true, user, account)) { - String errorMsg = "There was an error stopping the console proxy id: " - + vmInstance.getId() - + " ,cannot enable storage maintenance"; - s_logger.warn(errorMsg); - throw new CloudRuntimeException(errorMsg); - } else { - // update work status - work.setStoppedForMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId()); + vmMgr.advanceStop(consoleProxy.getUuid(), false); + // update work status + work.setStoppedForMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); if (restart) { - if (this.vmMgr.advanceStart(consoleProxy, null, user, - account) == null) { - String errorMsg = "There was an error starting the console proxy id: " - + vmInstance.getId() - + " on another storage pool, cannot enable primary storage maintenance"; - s_logger.warn(errorMsg); - } else { - // update work status - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(consoleProxy.getUuid(), null); + // update work status + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } } // if the instance is of type uservm, call the user vm manager - if (vmInstance.getType().equals(VirtualMachine.Type.User)) { + if (vmInstance.getType() == VirtualMachine.Type.User) { UserVmVO userVm = userVmDao.findById(vmInstance.getId()); - if (!vmMgr.advanceStop(userVm, true, user, account)) { - String errorMsg = "There was an error stopping the user vm id: " - + vmInstance.getId() - + " ,cannot enable storage maintenance"; - s_logger.warn(errorMsg); - throw new CloudRuntimeException(errorMsg); - } else { - // update work status - work.setStoppedForMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStop(userVm.getUuid(), false); + // update work status + work.setStoppedForMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } // if the instance is of type secondary storage vm, call the // secondary storage vm manager if (vmInstance.getType().equals( VirtualMachine.Type.SecondaryStorageVm)) { - SecondaryStorageVmVO secStrgVm = _secStrgDao - .findById(vmInstance.getId()); - if (!vmMgr.advanceStop(secStrgVm, true, user, account)) { - String errorMsg = "There was an error stopping the ssvm id: " - + vmInstance.getId() - + " ,cannot enable storage maintenance"; - s_logger.warn(errorMsg); - throw new CloudRuntimeException(errorMsg); - } else { - // update work status - work.setStoppedForMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + SecondaryStorageVmVO secStrgVm = _secStrgDao.findById(vmInstance.getId()); + vmMgr.advanceStop(secStrgVm.getUuid(), false); + // update work status + work.setStoppedForMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); if (restart) { - if (vmMgr.advanceStart(secStrgVm, null, user, account) == null) { - String errorMsg = "There was an error starting the ssvm id: " - + vmInstance.getId() - + " on another storage pool, cannot enable primary storage maintenance"; - s_logger.warn(errorMsg); - } else { - // update work status - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(secStrgVm.getUuid(), null); + // update work status + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } } @@ -317,37 +281,24 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { if (vmInstance.getType().equals( VirtualMachine.Type.DomainRouter)) { DomainRouterVO domR = _domrDao.findById(vmInstance.getId()); - if (!vmMgr.advanceStop(domR, true, user, account)) { - String errorMsg = "There was an error stopping the domain router id: " - + vmInstance.getId() - + " ,cannot enable primary storage maintenance"; - s_logger.warn(errorMsg); - throw new CloudRuntimeException(errorMsg); - } else { - // update work status - work.setStoppedForMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStop(domR.getUuid(), false); + // update work status + work.setStoppedForMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); if (restart) { - if (vmMgr.advanceStart(domR, null, user, account) == null) { - String errorMsg = "There was an error starting the domain router id: " - + vmInstance.getId() - + " on another storage pool, cannot enable primary storage maintenance"; - s_logger.warn(errorMsg); - } else { - // update work status - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(domR.getUuid(), null); + // update work status + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } } } - } catch(Exception e) { + } catch (Exception e) { s_logger.error( "Exception in enabling primary storage maintenance:", e); pool.setStatus(StoragePoolStatus.ErrorInMaintenance); - this.primaryDataStoreDao.update(pool.getId(), pool); + primaryDataStoreDao.update(pool.getId(), pool); throw new CloudRuntimeException(e.getMessage()); } return true; @@ -359,7 +310,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { Long userId = CallContext.current().getCallingUserId(); User user = _userDao.findById(userId); Account account = CallContext.current().getCallingAccount(); - StoragePoolVO poolVO = this.primaryDataStoreDao + StoragePoolVO poolVO = primaryDataStoreDao .findById(store.getId()); StoragePool pool = (StoragePool)store; @@ -370,7 +321,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId()); } else { hosts = _resourceMgr.listHostsInClusterByStatus( - pool.getClusterId(), Status.Up); + pool.getClusterId(), Status.Up); } if (hosts == null || hosts.size() == 0) { @@ -385,7 +336,7 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { if (s_logger.isDebugEnabled()) { s_logger.debug("ModifyStoragePool add failed due to " + ((answer == null) ? "answer null" : answer - .getDetails())); + .getDetails())); } } else { if (s_logger.isDebugEnabled()) { @@ -414,17 +365,10 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { ConsoleProxyVO consoleProxy = _consoleProxyDao .findById(vmInstance.getId()); - if (vmMgr.advanceStart(consoleProxy, null, user, account) == null) { - String msg = "There was an error starting the console proxy id: " - + vmInstance.getId() - + " on storage pool, cannot complete primary storage maintenance"; - s_logger.warn(msg); - throw new ExecutionException(msg); - } else { - // update work queue - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(consoleProxy.getUuid(), null); + // update work queue + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } // if the instance is of type ssvm, call the ssvm manager @@ -432,52 +376,29 @@ public class StoragePoolAutomationImpl implements StoragePoolAutomation { VirtualMachine.Type.SecondaryStorageVm)) { SecondaryStorageVmVO ssVm = _secStrgDao.findById(vmInstance .getId()); - if (vmMgr.advanceStart(ssVm, null, user, account) == null) { - String msg = "There was an error starting the ssvm id: " - + vmInstance.getId() - + " on storage pool, cannot complete primary storage maintenance"; - s_logger.warn(msg); - throw new ExecutionException(msg); - } else { - // update work queue - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(ssVm.getUuid(), null); + // update work queue + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } // if the instance is of type ssvm, call the ssvm manager if (vmInstance.getType().equals( VirtualMachine.Type.DomainRouter)) { DomainRouterVO domR = _domrDao.findById(vmInstance.getId()); - if (vmMgr.advanceStart(domR, null, user, account) == null) { - String msg = "There was an error starting the domR id: " - + vmInstance.getId() - + " on storage pool, cannot complete primary storage maintenance"; - s_logger.warn(msg); - throw new ExecutionException(msg); - } else { - // update work queue - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(domR.getUuid(), null); + // update work queue + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } // if the instance is of type user vm, call the user vm manager if (vmInstance.getType().equals(VirtualMachine.Type.User)) { UserVmVO userVm = userVmDao.findById(vmInstance.getId()); - if (vmMgr.advanceStart(userVm, null, user, account) == null) { - - String msg = "There was an error starting the user vm id: " - + vmInstance.getId() - + " on storage pool, cannot complete primary storage maintenance"; - s_logger.warn(msg); - throw new ExecutionException(msg); - } else { - // update work queue - work.setStartedAfterMaintenance(true); - _storagePoolWorkDao.update(work.getId(), work); - } + vmMgr.advanceStart(userVm.getUuid(), null); // update work queue + work.setStartedAfterMaintenance(true); + _storagePoolWorkDao.update(work.getId(), work); } return true; } catch (Exception e) { diff --git a/server/src/com/cloud/storage/VolumeManager.java b/server/src/com/cloud/storage/VolumeManager.java index 2e44a3c35b3..d9bbd541713 100644 --- a/server/src/com/cloud/storage/VolumeManager.java +++ b/server/src/com/cloud/storage/VolumeManager.java @@ -41,7 +41,6 @@ import com.cloud.storage.Volume.Type; import com.cloud.user.Account; import com.cloud.vm.DiskProfile; import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public interface VolumeManager extends VolumeApiService { @@ -85,7 +84,7 @@ public interface VolumeManager extends VolumeApiService { @Override Volume detachVolumeFromVM(DetachVolumeCmd cmmd); - void release(VirtualMachineProfile profile); + void release(VirtualMachineProfile profile); void cleanupVolumes(long vmId) throws ConcurrentOperationException; @@ -95,15 +94,11 @@ public interface VolumeManager extends VolumeApiService { void migrateVolumes(T vm, VirtualMachineTO vmTo, Host srcHost, Host destHost, Map volumeToPool); - boolean storageMigration( - VirtualMachineProfile vm, - StoragePool destPool); + boolean storageMigration(VirtualMachineProfile vm, StoragePool destPool); - void prepareForMigration( - VirtualMachineProfile vm, - DeployDestination dest); + void prepareForMigration(VirtualMachineProfile vm, DeployDestination dest); - void prepare(VirtualMachineProfile vm, + void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException; diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java index 7b44c5c29d8..e8957b4b081 100644 --- a/server/src/com/cloud/storage/VolumeManagerImpl.java +++ b/server/src/com/cloud/storage/VolumeManagerImpl.java @@ -31,10 +31,6 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; @@ -73,7 +69,9 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; - +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.CreateVolumeOVAAnswer; @@ -2031,7 +2029,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @DB protected VolumeVO switchVolume(VolumeVO existingVolume, - VirtualMachineProfile vm) + VirtualMachineProfile vm) throws StorageUnavailableException { Transaction txn = Transaction.currentTxn(); @@ -2070,7 +2068,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @Override - public void release(VirtualMachineProfile profile) { + public void release(VirtualMachineProfile profile) { // add code here } @@ -2269,7 +2267,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @Override public boolean storageMigration( - VirtualMachineProfile vm, + VirtualMachineProfile vm, StoragePool destPool) { List vols = _volsDao.findUsableVolumesForInstance(vm.getId()); List volumesNeedToMigrate = new ArrayList(); @@ -2307,7 +2305,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { @Override public void prepareForMigration( - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest) { List vols = _volsDao.findUsableVolumesForInstance(vm.getId()); if (s_logger.isDebugEnabled()) { @@ -2320,13 +2318,10 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { vm.addDisk(disk); } - if (vm.getType() == VirtualMachine.Type.User) { - UserVmVO userVM = (UserVmVO) vm.getVirtualMachine(); - if (userVM.getIsoId() != null) { - DataTO dataTO = tmplFactory.getTemplate(userVM.getIsoId(), DataStoreRole.Image, userVM.getDataCenterId()).getTO(); - DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO); - vm.addDisk(iso); - } + if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) { + DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO(); + DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO); + vm.addDisk(iso); } } @@ -2439,7 +2434,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { return tasks; } - private Pair recreateVolume(VolumeVO vol, VirtualMachineProfile vm, + private Pair recreateVolume(VolumeVO vol, VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException { VolumeVO newVol; boolean recreate = _recreateSystemVmEnabled; @@ -2506,7 +2501,7 @@ public class VolumeManagerImpl extends ManagerBase implements VolumeManager { } @Override - public void prepare(VirtualMachineProfile vm, + public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException { diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java index 4918bf55f1f..f0550855bb5 100755 --- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java +++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java @@ -55,6 +55,7 @@ import com.cloud.agent.api.storage.Proxy; import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.storage.RegisterVolumePayload; +import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; import com.cloud.storage.Volume; @@ -215,7 +216,15 @@ public class DownloadMonitorImpl extends ManagerBase implements DownloadMonitor if (isTemplateUpdateable(templateId, store.getId())) { if (template != null && template.getUri() != null) { initiateTemplateDownload(template, callback); + } else { + s_logger.info("Template url is null, cannot download"); + DownloadAnswer ans = new DownloadAnswer("Template url is null", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR.UNKNOWN); + callback.complete(ans); } + } else { + s_logger.info("Template download is already in progress or already downloaded"); + DownloadAnswer ans = new DownloadAnswer("Template download is already in progress or already downloaded", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR.UNKNOWN); + callback.complete(ans); } } diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java index b80892a7641..56b8dba84f4 100755 --- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java +++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java @@ -107,7 +107,6 @@ import com.cloud.storage.template.TemplateConstants; import com.cloud.template.TemplateManager; import com.cloud.user.Account; import com.cloud.user.AccountService; -import com.cloud.user.User; import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -156,7 +155,7 @@ import com.cloud.vm.dao.VMInstanceDao; // because sooner or later, it will be driven into Running state // @Local(value = { SecondaryStorageVmManager.class }) -public class SecondaryStorageManagerImpl extends ManagerBase implements SecondaryStorageVmManager, VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { +public class SecondaryStorageManagerImpl extends ManagerBase implements SecondaryStorageVmManager, VirtualMachineGuru, SystemVmLoadScanHandler, ResourceStateAdapter { private static final Logger s_logger = Logger.getLogger(SecondaryStorageManagerImpl.class); private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 @@ -257,9 +256,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId) { try { SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId); - Account systemAcct = _accountMgr.getSystemAccount(); - User systemUser = _accountMgr.getSystemUser(); - return _itMgr.start(secStorageVm, null, systemUser, systemAcct); + _itMgr.advanceStart(secStorageVm.getUuid(), null); + return _secStorageVmDao.findById(secStorageVm.getId()); } catch (StorageUnavailableException e) { s_logger.warn("Exception while trying to start secondary storage vm", e); return null; @@ -907,11 +905,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar try { if (secStorageVmLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC)) { try { - boolean result = _itMgr.stop(secStorageVm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); - if (result) { - } - - return result; + _itMgr.stop(secStorageVm.getUuid()); + return true; } finally { secStorageVmLock.unlock(); } @@ -1005,14 +1000,9 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public SecondaryStorageVmVO findById(long id) { - return _secStorageVmDao.findById(id); - } + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - @Override - public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - - SecondaryStorageVmVO vm = profile.getVirtualMachine(); + SecondaryStorageVmVO vm = _secStorageVmDao.findById(profile.getId()); Map details = _vmDetailsDao.findDetails(vm.getId()); vm.setDetails(details); @@ -1043,7 +1033,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } buf.append(" instance=SecStorage"); buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy)); - buf.append(" role=").append(profile.getVirtualMachine().getRole().toString()); + buf.append(" role=").append(vm.getRole().toString()); buf.append(" mtu=").append(_secStorageVmMtuSize); boolean externalDhcp = false; @@ -1109,11 +1099,11 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { finalizeCommandsOnStart(cmds, profile); - SecondaryStorageVmVO secVm = profile.getVirtualMachine(); + SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId()); DataCenter dc = dest.getDataCenter(); List nics = profile.getNics(); for (NicProfile nic : nics) { @@ -1132,7 +1122,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { + public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile) { NicProfile managementNic = null; NicProfile controlNic = null; @@ -1159,7 +1149,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh"); if (!answer.getResult()) { s_logger.warn("Unable to ssh to the VM: " + answer.getDetails()); @@ -1171,7 +1161,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar _rulesMgr.getSystemIpAndEnableStaticNatForVm(profile.getVirtualMachine(), false); IPAddressVO ipaddr = _ipAddressDao.findByAssociatedVmId(profile.getVirtualMachine().getId()); if (ipaddr != null && ipaddr.getSystem()) { - SecondaryStorageVmVO secVm = profile.getVirtualMachine(); + SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId()); // override SSVM guest IP with EIP, so that download url's with be prepared with EIP secVm.setPublicIpAddress(ipaddr.getAddress().addr()); _secStorageVmDao.update(secVm.getId(), secVm); @@ -1185,7 +1175,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { //release elastic IP here IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); if (ip != null && ip.getSystem()) { @@ -1199,11 +1189,13 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public void finalizeExpunge(SecondaryStorageVmVO vm) { - vm.setPublicIpAddress(null); - vm.setPublicMacAddress(null); - vm.setPublicNetmask(null); - _secStorageVmDao.update(vm.getId(), vm); + public void finalizeExpunge(VirtualMachine vm) { + SecondaryStorageVmVO ssvm = _secStorageVmDao.findByUuid(vm.getUuid()); + + ssvm.setPublicIpAddress(null); + ssvm.setPublicMacAddress(null); + ssvm.setPublicNetmask(null); + _secStorageVmDao.update(ssvm.getId(), ssvm); } @Override @@ -1380,7 +1372,7 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar } @Override - public void prepareStop(VirtualMachineProfile profile) { + public void prepareStop(VirtualMachineProfile profile) { } } diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index d766f7a09d1..123c5957baa 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -910,6 +910,12 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, if (host.getHypervisorType() != HypervisorType.KVM) { return true; } + + //Turn off snapshot by default for KVM, unless it is set in the global flag + boolean snapshotEnabled = Boolean.parseBoolean(_configDao.getValue("KVM.snapshot.enabled")); + if (!snapshotEnabled) { + return false; + } // Determine host capabilities String caps = host.getCapabilities(); diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index 512f9130a06..53e3f51f262 100755 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -822,11 +822,11 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M try { try { if (vm.getType() == Type.User) { - success = (success && _itMgr.advanceStop(_userVmDao.findById(vm.getId()), false, getSystemUser(), getSystemAccount())); + _itMgr.advanceStop(vm.getUuid(), false); } else if (vm.getType() == Type.DomainRouter) { - success = (success && _itMgr.advanceStop(_routerDao.findById(vm.getId()), false, getSystemUser(), getSystemAccount())); + _itMgr.advanceStop(vm.getUuid(), false); } else { - success = (success && _itMgr.advanceStop(vm, false, getSystemUser(), getSystemAccount())); + _itMgr.advanceStop(vm.getUuid(), false); } } catch (OperationTimedoutException ote) { s_logger.warn("Operation for stopping vm timed out, unable to stop vm " + vm.getHostName(), ote); diff --git a/server/src/com/cloud/vm/SystemVmLoadScanner.java b/server/src/com/cloud/vm/SystemVmLoadScanner.java index 4251b405e1b..3932c3b9641 100644 --- a/server/src/com/cloud/vm/SystemVmLoadScanner.java +++ b/server/src/com/cloud/vm/SystemVmLoadScanner.java @@ -22,10 +22,11 @@ import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; +import org.apache.cloudstack.context.ServerContexts; + import com.cloud.utils.Pair; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.GlobalLock; -import com.cloud.utils.db.Transaction; // // TODO: simple load scanner, to minimize code changes required in console proxy manager and SSVM, we still leave most of work at handler @@ -67,13 +68,13 @@ public class SystemVmLoadScanner { @Override public void run() { - Transaction txn = Transaction.open(Transaction.CLOUD_DB); + ServerContexts.registerSystemContext(); try { reallyRun(); } catch (Throwable e) { s_logger.warn("Unexpected exception " + e.getMessage(), e); } finally { - txn.close(); + ServerContexts.unregisterSystemContext(); } } diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index 348017a0a44..635d15e76e1 100755 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -23,7 +23,11 @@ import java.util.Map; import com.cloud.agent.api.VmDiskStatsEntry; import com.cloud.agent.api.VmStatsEntry; import com.cloud.api.query.vo.UserVmJoinVO; -import com.cloud.exception.*; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ManagementServerException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.server.Criteria; import com.cloud.user.Account; @@ -34,7 +38,7 @@ import com.cloud.utils.Pair; * * */ -public interface UserVmManager extends VirtualMachineGuru, UserVmService{ +public interface UserVmManager extends UserVmService { static final int MAX_USER_DATA_LENGTH_BYTES = 2048; /** diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index adcf4759f8f..694ef5bf1c6 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -33,9 +33,6 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; - import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroupService; @@ -69,6 +66,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.TemplateObjectTO; +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -107,6 +106,8 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.deploy.PlannerHostReservationVO; +import com.cloud.deploy.dao.PlannerHostReservationDao; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.ActionEvent; @@ -178,6 +179,7 @@ import com.cloud.server.ConfigurationServer; import com.cloud.server.Criteria; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.service.dao.ServiceOfferingDetailsDao; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.GuestOSVO; @@ -221,6 +223,7 @@ import com.cloud.user.dao.SSHKeyPairDao; import com.cloud.user.dao.UserDao; import com.cloud.user.dao.VmDiskStatisticsDao; import com.cloud.uservm.UserVm; +import com.cloud.utils.DateUtil; import com.cloud.utils.Journal; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -254,7 +257,7 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; @Local(value = { UserVmManager.class, UserVmService.class }) -public class UserVmManagerImpl extends ManagerBase implements UserVmManager, UserVmService { +public class UserVmManagerImpl extends ManagerBase implements UserVmManager, VirtualMachineGuru, UserVmService { private static final Logger s_logger = Logger .getLogger(UserVmManagerImpl.class); @@ -418,11 +421,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use ConfigurationServer _configServer; @Inject AffinityGroupService _affinityGroupService; + @Inject + PlannerHostReservationDao _plannerHostReservationDao; + @Inject + private ServiceOfferingDetailsDao serviceOfferingDetailsDao; protected ScheduledExecutorService _executor = null; protected int _expungeInterval; protected int _expungeDelay; protected boolean _dailyOrHourly = false; + private int capacityReleaseInterval; protected String _name; protected String _instance; @@ -539,7 +547,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId()); NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); - VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); + VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); UserDataServiceProvider element = _networkMgr.getPasswordResetProvider(defaultNetwork); @@ -656,7 +664,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork)); - VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); + VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance); if (template != null && template.getEnablePassword()) { vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password); @@ -1424,6 +1432,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use String workers = configs.get("expunge.workers"); int wrks = NumbersUtil.parseInt(workers, 10); + capacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()), 3600); String time = configs.get("expunge.interval"); _expungeInterval = NumbersUtil.parseInt(time, 86400); @@ -1831,7 +1840,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(template.getHypervisorType(), network)); - VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl((VMInstanceVO)vm); + VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm); UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network); if (element == null) { @@ -2888,10 +2897,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } @Override - public boolean finalizeVirtualMachineProfile( - VirtualMachineProfile profile, DeployDestination dest, - ReservationContext context) { - UserVmVO vm = profile.getVirtualMachine(); + public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { + UserVmVO vm = _vmDao.findById(profile.getId()); Map details = _vmDetailsDao.findDetails(vm.getId()); vm.setDetails(details); @@ -2959,9 +2966,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public boolean finalizeDeployment(Commands cmds, - VirtualMachineProfile profile, DeployDestination dest, + VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { - UserVmVO userVm = profile.getVirtualMachine(); + UserVmVO userVm = _vmDao.findById(profile.getId()); List nics = _nicDao.listByVmId(userVm.getId()); for (NicVO nic : nics) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); @@ -2987,14 +2994,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Override public boolean finalizeCommandsOnStart(Commands cmds, - VirtualMachineProfile profile) { + VirtualMachineProfile profile) { return true; } @Override - public boolean finalizeStart(VirtualMachineProfile profile, + public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context) { - UserVmVO vm = profile.getVirtualMachine(); + UserVmVO vm = _vmDao.findById(profile.getId()); Answer[] answersToCmds = cmds.getAnswers(); if (answersToCmds == null) { @@ -3055,7 +3062,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } if (ipChanged) { DataCenterVO dc = _dcDao.findById(vm.getDataCenterId()); - UserVmVO userVm = profile.getVirtualMachine(); + UserVmVO userVm = _vmDao.findById(profile.getId()); // dc.getDhcpProvider().equalsIgnoreCase(Provider.ExternalDhcpServer.getName()) if (_ntwkSrvcDao.canProviderSupportServiceInNetwork( guestNetwork.getId(), Service.Dhcp, @@ -3085,12 +3092,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } @Override - public void finalizeExpunge(UserVmVO vm) { - } - - @Override - public UserVmVO findById(long id) { - return _vmDao.findById(id); + public void finalizeExpunge(VirtualMachine vm) { } @Override @@ -3135,8 +3137,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } @Override - public void finalizeStop(VirtualMachineProfile profile, - StopAnswer answer) { + public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) { + VirtualMachine vm = profile.getVirtualMachine(); // release elastic IP here IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); if (ip != null && ip.getSystem()) { @@ -3156,7 +3158,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } } - VMInstanceVO vm = profile.getVirtualMachine(); List nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); @@ -3841,22 +3842,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use + destinationHost.getResourceState()); } - HostVO srcHost = _hostDao.findById(srcHostId); - HostVO destHost = _hostDao.findById(destinationHost.getId()); - //if srcHost is dedicated and destination Host is not - if (checkIfHostIsDedicated(srcHost) && !checkIfHostIsDedicated(destHost)) { - //raise an alert - String msg = "VM is migrated on a non-dedicated host " + destinationHost.getName(); - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); - } - //if srcHost is non dedicated but destination Host is. - if (!checkIfHostIsDedicated(srcHost) && checkIfHostIsDedicated(destHost)) { - //raise an alert - String msg = "VM is migrated on a dedicated host " + destinationHost.getName(); - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); - } + checkHostsDedication(vm, srcHostId, destinationHost.getId()); - // call to core process + // call to core process DataCenterVO dcVO = _dcDao.findById(destinationHost.getDataCenterId()); HostPodVO pod = _podDao.findById(destinationHost.getPodId()); Cluster cluster = _clusterDao.findById(destinationHost.getClusterId()); @@ -3899,6 +3887,210 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } } + private Long accountOfDedicatedHost(HostVO host) { + long hostId = host.getId(); + DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); + DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); + DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); + if(dedicatedHost != null) { + return dedicatedHost.getAccountId(); + } + if(dedicatedClusterOfHost != null) { + return dedicatedClusterOfHost.getAccountId(); + } + if(dedicatedPodOfHost != null) { + return dedicatedPodOfHost.getAccountId(); + } + return null; + } + + private Long domainOfDedicatedHost(HostVO host) { + long hostId = host.getId(); + DedicatedResourceVO dedicatedHost = _dedicatedDao.findByHostId(hostId); + DedicatedResourceVO dedicatedClusterOfHost = _dedicatedDao.findByClusterId(host.getClusterId()); + DedicatedResourceVO dedicatedPodOfHost = _dedicatedDao.findByPodId(host.getPodId()); + if(dedicatedHost != null) { + return dedicatedHost.getDomainId(); + } + if(dedicatedClusterOfHost != null) { + return dedicatedClusterOfHost.getDomainId(); + } + if(dedicatedPodOfHost != null) { + return dedicatedPodOfHost.getDomainId(); + } + return null; + } + + public void checkHostsDedication (VMInstanceVO vm, long srcHostId, long destHostId) { + HostVO srcHost = _hostDao.findById(srcHostId); + HostVO destHost = _hostDao.findById(destHostId); + boolean srcExplDedicated = checkIfHostIsDedicated(srcHost); + boolean destExplDedicated = checkIfHostIsDedicated(destHost); + //if srcHost is explicitly dedicated and destination Host is not + if (srcExplDedicated && !destExplDedicated) { + //raise an alert + String msg = "VM is being migrated from a explicitly dedicated host " + srcHost.getName() +" to non-dedicated host " + destHost.getName(); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + } + //if srcHost is non dedicated but destination Host is explicitly dedicated + if (!srcExplDedicated && destExplDedicated) { + //raise an alert + String msg = "VM is being migrated from a non dedicated host " + srcHost.getName() + " to a explicitly dedicated host "+ destHost.getName(); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + } + + //if hosts are dedicated to different account/domains, raise an alert + if (srcExplDedicated && destExplDedicated) { + if((accountOfDedicatedHost(srcHost) != null) && (accountOfDedicatedHost(srcHost)!= accountOfDedicatedHost(destHost))) { + String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(srcHost) + + " to host " + destHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(destHost); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + } + if((domainOfDedicatedHost(srcHost) != null) && (domainOfDedicatedHost(srcHost)!= domainOfDedicatedHost(destHost))) { + String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly dedicated to domain " + domainOfDedicatedHost(srcHost) + + " to host " + destHost.getName() + " explicitly dedicated to domain " + domainOfDedicatedHost(destHost); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + } + } + + // Checks for implicitly dedicated hosts + ServiceOfferingVO deployPlanner = _offeringDao.findById(vm.getServiceOfferingId()); + if(deployPlanner.getDeploymentPlanner() != null && deployPlanner.getDeploymentPlanner().equals("ImplicitDedicationPlanner")) { + //VM is deployed using implicit planner + long accountOfVm = vm.getAccountId(); + String msg = "VM of account " + accountOfVm + " with implicit deployment planner being migrated to host " + destHost.getName(); + //Get all vms on destination host + boolean emptyDestination = false; + List vmsOnDest= getVmsOnHost(destHostId); + if (vmsOnDest == null || vmsOnDest.isEmpty()) { + emptyDestination = true; + } + + if (!emptyDestination) { + //Check if vm is deployed using strict implicit planner + if(!isServiceOfferingUsingPlannerInPreferredMode(vm.getServiceOfferingId())) { + //Check if all vms on destination host are created using strict implicit mode + if(!checkIfAllVmsCreatedInStrictMode(accountOfVm, vmsOnDest)) { + msg = "VM of account " + accountOfVm + " with strict implicit deployment planner being migrated to host " + destHost.getName() + + " not having all vms strict implicitly dedicated to account " + accountOfVm; + } + } else { + //If vm is deployed using preferred implicit planner, check if all vms on destination host must be + //using implicit planner and must belong to same account + for (VMInstanceVO vmsDest : vmsOnDest) { + ServiceOfferingVO destPlanner = _offeringDao.findById(vmsDest.getServiceOfferingId()); + if (!((destPlanner.getDeploymentPlanner() != null && destPlanner.getDeploymentPlanner().equals("ImplicitDedicationPlanner")) && + vmsDest.getAccountId()==accountOfVm)) { + msg = "VM of account " + accountOfVm + " with preffered implicit deployment planner being migrated to host " + destHost.getName() + + " not having all vms implicitly dedicated to account " + accountOfVm; + } + } + } + } + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + + } else { + //VM is not deployed using implicit planner, check if it migrated between dedicated hosts + List reservedHosts = _plannerHostReservationDao.listAllDedicatedHosts(); + boolean srcImplDedicated = false; + boolean destImplDedicated = false; + String msg = null; + for (PlannerHostReservationVO reservedHost : reservedHosts) { + if(reservedHost.getHostId() == srcHostId) { + srcImplDedicated = true; + } + if(reservedHost.getHostId() == destHostId) { + destImplDedicated = true; + } + } + if(srcImplDedicated) { + if(destImplDedicated){ + msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName() + " to another implicitly dedicated host " + destHost.getName(); + } else { + msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName() + " to shared host " + destHost.getName(); + } + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + } else { + if (destImplDedicated) { + msg = "VM is being migrated from shared host " + srcHost.getName() + " to implicitly dedicated host " + destHost.getName(); + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); + s_logger.warn(msg); + } + } + } + } + + private List getVmsOnHost(long hostId) { + List vms = _vmInstanceDao.listUpByHostId(hostId); + List vmsByLastHostId = _vmInstanceDao.listByLastHostId(hostId); + if (vmsByLastHostId.size() > 0) { + // check if any VMs are within skip.counting.hours, if yes we have to consider the host. + for (VMInstanceVO stoppedVM : vmsByLastHostId) { + long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - stoppedVM.getUpdateTime() + .getTime()) / 1000; + if (secondsSinceLastUpdate < capacityReleaseInterval) { + vms.add(stoppedVM); + } + } + } + + return vms; + } + private boolean isServiceOfferingUsingPlannerInPreferredMode(long serviceOfferingId) { + boolean preferred = false; + Map details = serviceOfferingDetailsDao.findDetails(serviceOfferingId); + if (details != null && !details.isEmpty()) { + String preferredAttribute = details.get("ImplicitDedicationMode"); + if (preferredAttribute != null && preferredAttribute.equals("Preferred")) { + preferred = true; + } + } + return preferred; + } + + private boolean checkIfAllVmsCreatedInStrictMode(Long accountId, List allVmsOnHost) { + boolean createdByImplicitStrict = true; + if (allVmsOnHost.isEmpty()) + return false; + for (VMInstanceVO vm : allVmsOnHost) { + if (!isImplicitPlannerUsedByOffering(vm.getServiceOfferingId()) || vm.getAccountId()!= accountId) { + s_logger.info("Host " + vm.getHostId() + " found to be running a vm created by a planner other" + + " than implicit, or running vms of other account"); + createdByImplicitStrict = false; + break; + } else if (isServiceOfferingUsingPlannerInPreferredMode(vm.getServiceOfferingId()) || vm.getAccountId()!= accountId) { + s_logger.info("Host " + vm.getHostId() + " found to be running a vm created by an implicit planner" + + " in preferred mode, or running vms of other account"); + createdByImplicitStrict = false; + break; + } + } + return createdByImplicitStrict; + } + + private boolean isImplicitPlannerUsedByOffering(long offeringId) { + boolean implicitPlannerUsed = false; + ServiceOfferingVO offering = _serviceOfferingDao.findByIdIncludingRemoved(offeringId); + if (offering == null) { + s_logger.error("Couldn't retrieve the offering by the given id : " + offeringId); + } else { + String plannerName = offering.getDeploymentPlanner(); + if (plannerName != null) { + if(plannerName.equals("ImplicitDedicationPlanner")) { + implicitPlannerUsed = true; + } + } + } + + return implicitPlannerUsed; + } + @Override @ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription = "migrating VM", async = true) public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, @@ -4016,6 +4208,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use " migrate to this host"); } + checkHostsDedication(vm, srcHostId, destinationHost.getId()); + VMInstanceVO migratedVm = _itMgr.migrateWithStorage(vm, srcHostId, destinationHost.getId(), volToPoolObjectMap); return migratedVm; } @@ -4209,9 +4403,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use txn.commit(); - VMInstanceVO vmoi = _itMgr.findByIdAndType(vm.getType(), vm.getId()); - VirtualMachineProfileImpl vmOldProfile = new VirtualMachineProfileImpl( - vmoi); + VirtualMachine vmoi = _itMgr.findById(vm.getId()); + VirtualMachineProfileImpl vmOldProfile = new VirtualMachineProfileImpl(vmoi); // OS 3: update the network List networkIdList = cmd.getNetworkIds(); @@ -4287,9 +4480,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use networks.add(new Pair(networkList.get(0), profile)); - VMInstanceVO vmi = _itMgr.findByIdAndType(vm.getType(), vm.getId()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl( - vmi); + VirtualMachine vmi = _itMgr.findById(vm.getId()); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmi); _networkMgr.allocate(vmProfile, networks); _securityGroupMgr.addInstanceToGroups(vm.getId(), @@ -4421,10 +4613,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use networks.add(new Pair(appNet, defaultNic)); } - VMInstanceVO vmi = _itMgr.findByIdAndType(vm.getType(), - vm.getId()); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl( - vmi); + VirtualMachine vmi = _itMgr.findById(vm.getId()); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmi); _networkMgr.allocate(vmProfile, networks); s_logger.debug("AssignVM: Advance virtual, adding networks no " + networks.size() + " to " + vm.getInstanceName()); @@ -4535,7 +4725,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use if (needRestart) { try { - _itMgr.stop(vm, user, caller); + _itMgr.stop(vm.getUuid()); } catch (ResourceUnavailableException e) { s_logger.debug("Stop vm " + vm.getUuid() + " failed", e); CloudRuntimeException ex = new CloudRuntimeException( @@ -4588,7 +4778,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use if (needRestart) { try { - _itMgr.start(vm, null, user, caller); + _itMgr.start(vm.getUuid(), null); } catch (Exception e) { s_logger.debug("Unable to start VM " + vm.getUuid(), e); CloudRuntimeException ex = new CloudRuntimeException( @@ -4598,14 +4788,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } } - s_logger.debug("Restore VM " + vmId + " with template " - + template.getUuid() + " done successfully"); + s_logger.debug("Restore VM " + vmId + " with template " + template.getUuid() + " done successfully"); return vm; } @Override - public void prepareStop(VirtualMachineProfile profile) { + public void prepareStop(VirtualMachineProfile profile) { UserVmVO vm = _vmDao.findById(profile.getId()); if (vm.getState() == State.Running) collectVmDiskStatistics(vm); diff --git a/server/src/com/cloud/vm/VirtualMachineGuru.java b/server/src/com/cloud/vm/VirtualMachineGuru.java index df34e0eafa7..3fb065bcd24 100644 --- a/server/src/com/cloud/vm/VirtualMachineGuru.java +++ b/server/src/com/cloud/vm/VirtualMachineGuru.java @@ -5,7 +5,7 @@ // 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, @@ -25,10 +25,9 @@ import com.cloud.exception.ResourceUnavailableException; * A VirtualMachineGuru knows how to process a certain type of virtual machine. * */ -public interface VirtualMachineGuru { - T findById(long id); +public interface VirtualMachineGuru { - boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); + boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context); /** * finalize the virtual machine deployment. @@ -37,7 +36,7 @@ public interface VirtualMachineGuru { * @param dest destination to send the command. * @return true if everything checks out. false if not and we should try again. */ - boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException; + boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException; /** * Check the deployment results. @@ -46,18 +45,18 @@ public interface VirtualMachineGuru { * @param dest destination it was sent to. * @return true if deployment was fine; false if it didn't go well. */ - boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context); + boolean finalizeStart(VirtualMachineProfile profile, long hostId, Commands cmds, ReservationContext context); - boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile); + boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile profile); - void finalizeStop(VirtualMachineProfile profile, StopAnswer answer); + void finalizeStop(VirtualMachineProfile profile, StopAnswer answer); - void finalizeExpunge(T vm); + void finalizeExpunge(VirtualMachine vm); /** * Prepare Vm for Stop * @param profile * @return */ - void prepareStop(VirtualMachineProfile profile); + void prepareStop(VirtualMachineProfile profile); } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index bf6af442876..cf0ede2293d 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -72,29 +72,31 @@ public interface VirtualMachineManager extends Manager { DeploymentPlan plan, HypervisorType hyperType) throws InsufficientCapacityException; - T start(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException; + void start(String vmUuid, Map params); - T start(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ResourceUnavailableException; + void start(String vmUuid, Map params, DeploymentPlan planToDeploy); - boolean stop(T vm, User caller, Account account) throws ResourceUnavailableException; + void stop(String vmUuid) throws ResourceUnavailableException; boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException; - void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru); + void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru); boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException; - T advanceStart(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; + void advanceStart(String vmUuid, Map params) throws InsufficientCapacityException, ResourceUnavailableException, + ConcurrentOperationException, OperationTimedoutException; - T advanceStart(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; + void advanceStart(String vmUuid, Map params, DeploymentPlan planToDeploy) throws InsufficientCapacityException, + ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; - boolean advanceStop(T vm, boolean forced, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException; + void advanceStop(String vmUuid, boolean cleanupEvenIfUnableToStop) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException; boolean advanceExpunge(T vm, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException; boolean remove(T vm, User caller, Account account); - boolean destroy(T vm, User caller, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException; + void destroy(String vmUuid) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException; boolean migrateAway(VirtualMachine.Type type, long vmid, long hostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException; @@ -106,8 +108,6 @@ public interface VirtualMachineManager extends Manager { T advanceReboot(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException; - VMInstanceVO findByIdAndType(VirtualMachine.Type type, long vmId); - /** * Check to see if a virtual machine can be upgraded to the given service offering * @@ -117,7 +117,7 @@ public interface VirtualMachineManager extends Manager { */ boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering); - VMInstanceVO findById(long vmId); + VirtualMachine findById(long vmId); T storageMigration(T vm, StoragePool storagePoolId); @@ -177,7 +177,7 @@ public interface VirtualMachineManager extends Manager { * @param hvGuru * @return */ - VirtualMachineTO toVmTO(VirtualMachineProfile profile); + VirtualMachineTO toVmTO(VirtualMachineProfile profile); VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering newServiceOffering, boolean sameHost) diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 7a4bf50f128..a0c5c3a85ae 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -19,7 +19,6 @@ package com.cloud.vm; import java.net.URI; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -39,6 +38,7 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; @@ -324,7 +324,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Inject DeploymentPlanningManager _dpMgr; - Map> _vmGurus = new HashMap>(); + Map _vmGurus = new HashMap(); protected StateMachine2 _stateMachine; ScheduledExecutorService _executor = null; @@ -340,7 +340,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac protected boolean _forceStop; @Override - public void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru) { + public void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru) { synchronized (_vmGurus) { _vmGurus.put(type, guru); } @@ -413,9 +413,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac allocate(vmInstanceName, template, serviceOffering, new Pair(serviceOffering, null), null, networks, null, plan, hyperType); } - @SuppressWarnings("unchecked") - private VirtualMachineGuru getVmGuru(T vm) { - return (VirtualMachineGuru) _vmGurus.get(vm.getType()); + private VirtualMachineGuru getVmGuru(VirtualMachine vm) { + return _vmGurus.get(vm.getType()); } @Override @@ -445,11 +444,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return true; } - if (!this.advanceStop(vm, false, caller, account)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to stop the VM so we can't expunge it."); - } - } + advanceStop(vm, false); try { if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) { @@ -469,7 +464,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac removeDhcpServiceInsubnet(vm); } - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); @@ -481,7 +476,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac List rootVol = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT); volumeMgr.cleanupVolumes(vm.getId()); - VirtualMachineGuru guru = getVmGuru(vm); + VirtualMachineGuru guru = getVmGuru(vm); guru.finalizeExpunge(vm); //remove the overcommit detials from the uservm details _uservmDetailsDao.deleteDetails(vm.getId()); @@ -603,17 +598,20 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public T start(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException { - return start(vm, params, caller, account, null); + public void start(String vmUuid, Map params) { + start(vmUuid, params, null); } @Override - public T start(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, - ResourceUnavailableException { + public void start(String vmUuid, Map params, DeploymentPlan planToDeploy) { try { - return advanceStart(vm, params, caller, account, planToDeploy); + advanceStart(vmUuid, params, planToDeploy); } catch (ConcurrentOperationException e) { - throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e); + throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e).add(VirtualMachine.class, vmUuid); + } catch (InsufficientCapacityException e) { + throw new CloudRuntimeException("Unable to start a VM due to insufficient capacity", e).add(VirtualMachine.class, vmUuid); + } catch (ResourceUnavailableException e) { + throw new CloudRuntimeException("Unable to start a VM due to concurrent operation", e).add(VirtualMachine.class, vmUuid); } } @@ -651,7 +649,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @DB - protected Ternary changeToStartState(VirtualMachineGuru vmGuru, T vm, User caller, Account account) + protected Ternary changeToStartState(VirtualMachineGuru vmGuru, VMInstanceVO vm, User caller, Account account) throws ConcurrentOperationException { long vmId = vm.getId(); @@ -659,7 +657,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac int retry = _lockStateRetry; while (retry-- != 0) { Transaction txn = Transaction.currentTxn(); - Ternary result = null; + Ternary result = null; txn.start(); try { Journal journal = new Journal.LogJournal("Creating " + vm, s_logger); @@ -670,7 +668,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (s_logger.isDebugEnabled()) { s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId()); } - result = new Ternary(vmGuru.findById(vmId), context, work); + result = new Ternary(vm, context, work); txn.commit(); return result; } @@ -733,7 +731,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) { + protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) { VirtualMachine vm = vmProfile.getVirtualMachine(); long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId()); @@ -744,28 +742,32 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public T advanceStart(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException { - return advanceStart(vm, params, caller, account, null); + public void advanceStart(String vmUuid, Map params) + throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { + advanceStart(vmUuid, params, null); } @Override - public T advanceStart(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) + public void advanceStart(String vmUuid, Map params, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { - long vmId = vm.getId(); - VirtualMachineGuru vmGuru = getVmGuru(vm); + CallContext cctxt = CallContext.current(); + Account account = cctxt.getCallingAccount(); + User caller = cctxt.getCallingUser(); + + VMInstanceVO vm = _vmDao.findByUuid(vmUuid); - vm = vmGuru.findById(vm.getId()); - Ternary start = changeToStartState(vmGuru, vm, caller, account); + VirtualMachineGuru vmGuru = getVmGuru(vm); + + Ternary start = changeToStartState(vmGuru, vm, caller, account); if (start == null) { - return vmGuru.findById(vmId); + return; } vm = start.first(); ReservationContext ctx = start.second(); ItWorkVO work = start.third(); - T startedVm = null; + VMInstanceVO startedVm = null; ServiceOfferingVO offering = _offeringDao.findById(vm.getServiceOfferingId()); VMTemplateVO template = _templateDao.findById(vm.getTemplateId()); @@ -845,7 +847,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, ctx); - }else{ + } else { plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, ctx); if (s_logger.isDebugEnabled()) { s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + " , and clusterId: " + rootVolClusterId); @@ -856,7 +858,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, offering, account, params); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, template, offering, account, params); DeployDestination dest = null; try { dest = _dpMgr.planDeployment(vmProfile, plan, avoids); @@ -955,7 +957,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (s_logger.isDebugEnabled()) { s_logger.debug("Start completed for VM " + vm); } - return startedVm; + return; } else { if (s_logger.isDebugEnabled()) { s_logger.info("The guru did not like the answers so stopping " + vm); @@ -1008,10 +1010,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac _workDao.updateStep(work, Step.Release); // If previous step was started/ing && we got a valid answer if((prevStep == Step.Started || prevStep == Step.Starting) && (startAnswer != null && startAnswer.getResult())){ //TODO check the response of cleanup and record it in DB for retry - cleanup(vmGuru, vmProfile, work, Event.OperationFailed, false, caller, account); + cleanup(vmGuru, vmProfile, work, Event.OperationFailed, false); } else { //if step is not starting/started, send cleanup command with force=true - cleanup(vmGuru, vmProfile, work, Event.OperationFailed, true, caller, account); + cleanup(vmGuru, vmProfile, work, Event.OperationFailed, true); } } } @@ -1036,23 +1038,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException("Unable to start instance '" + vm.getHostName() + "' (" + vm.getUuid() + "), see management server log for details"); } - - return startedVm; } @Override - public boolean stop(T vm, User user, Account account) throws ResourceUnavailableException { + public void stop(String vmUuid) throws ResourceUnavailableException { try { - return advanceStop(vm, false, user, account); + advanceStop(vmUuid, false); } catch (OperationTimedoutException e) { - throw new AgentUnavailableException("Unable to stop vm because the operation to stop timed out", vm.getHostId(), e); + throw new AgentUnavailableException("Unable to stop vm because the operation to stop timed out", e.getAgentId(), e); } catch (ConcurrentOperationException e) { throw new CloudRuntimeException("Unable to stop vm because of a concurrent operation", e); } } - protected boolean sendStop(VirtualMachineGuru guru, VirtualMachineProfile profile, boolean force) { - VMInstanceVO vm = profile.getVirtualMachine(); + protected boolean sendStop(VirtualMachineGuru guru, VirtualMachineProfile profile, boolean force) { + VirtualMachine vm = profile.getVirtualMachine(); StopCommand stop = new StopCommand(vm, _mgmtServer.getExecuteInSequence()); try { Answer answer = _agentMgr.send(vm.getHostId(), stop); @@ -1075,20 +1075,20 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return true; } - protected boolean cleanup(VirtualMachineGuru guru, VirtualMachineProfile profile, ItWorkVO work, Event event, boolean force, User user, Account account) { - T vm = profile.getVirtualMachine(); + protected boolean cleanup(VirtualMachineGuru guru, VirtualMachineProfile profile, ItWorkVO work, Event event, boolean cleanUpEvenIfUnableToStop) { + VirtualMachine vm = profile.getVirtualMachine(); State state = vm.getState(); s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state"); if (state == State.Starting) { Step step = work.getStep(); - if (step == Step.Starting && !force) { + if (step == Step.Starting && !cleanUpEvenIfUnableToStop) { s_logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect: " + step); return false; } if (step == Step.Started || step == Step.Starting || step == Step.Release) { if (vm.getHostId() != null) { - if (!sendStop(guru, profile, force)) { + if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop)) { s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process"); return false; } @@ -1101,33 +1101,33 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } else if (state == State.Stopping) { if (vm.getHostId() != null) { - if (!sendStop(guru, profile, force)) { + if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop)) { s_logger.warn("Failed to stop vm " + vm + " in " + State.Stopping + " state as a part of cleanup process"); return false; } } } else if (state == State.Migrating) { if (vm.getHostId() != null) { - if (!sendStop(guru, profile, force)) { + if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop)) { s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process"); return false; } } if (vm.getLastHostId() != null) { - if (!sendStop(guru, profile, force)) { + if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop)) { s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process"); return false; } } } else if (state == State.Running) { - if (!sendStop(guru, profile, force)) { + if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop)) { s_logger.warn("Failed to stop vm " + vm + " in " + State.Running + " state as a part of cleanup process"); return false; } } try { - _networkMgr.release(profile, force); + _networkMgr.release(profile, cleanUpEvenIfUnableToStop); s_logger.debug("Successfully released network resources for the vm " + vm); } catch (Exception e) { s_logger.warn("Unable to release some network resources.", e); @@ -1139,20 +1139,26 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public boolean advanceStop(T vm, boolean forced, User user, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { + public void advanceStop(String vmUuid, boolean cleanUpEvenIfUnableToStop) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { + VMInstanceVO vm = _vmDao.findByUuid(vmUuid); + + advanceStop(vm, cleanUpEvenIfUnableToStop); + } + + private void advanceStop(VMInstanceVO vm, boolean cleanUpEvenIfUnableToStop) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { State state = vm.getState(); if (state == State.Stopped) { if (s_logger.isDebugEnabled()) { s_logger.debug("VM is already stopped: " + vm); } - return true; + return; } if (state == State.Destroyed || state == State.Expunging || state == State.Error) { if (s_logger.isDebugEnabled()) { s_logger.debug("Stopped called on " + vm + " but the state is " + state); } - return true; + return; } // grab outstanding work item if any ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState()); @@ -1163,11 +1169,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } Long hostId = vm.getHostId(); if (hostId == null) { - if (!forced) { + if (!cleanUpEvenIfUnableToStop) { if (s_logger.isDebugEnabled()) { s_logger.debug("HostId is null but this is not a forced stop, cannot stop vm " + vm + " with state:" + vm.getState()); } - return false; + throw new CloudRuntimeException("Unable to stop " + vm); } try { stateTransitTo(vm, Event.AgentReportStopped, null, null); @@ -1182,18 +1188,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac work.setStep(Step.Done); _workDao.update(work.getId(), work); } - return true; + return; } - VirtualMachineGuru vmGuru = getVmGuru(vm); - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineGuru vmGuru = getVmGuru(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); try { if (!stateTransitTo(vm, Event.StopRequested, vm.getHostId())) { throw new ConcurrentOperationException("VM is being operated on."); } } catch (NoTransitionException e1) { - if (!forced) { + if (!cleanUpEvenIfUnableToStop) { throw new CloudRuntimeException("We cannot stop " + vm + " when it is in state " + vm.getState()); } boolean doCleanup = false; @@ -1214,15 +1220,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (doCleanup) { - if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, forced, user, account)) { + if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) { try { if (s_logger.isDebugEnabled()) { s_logger.debug("Updating work item to Done, id:" + work.getId()); } - return changeState(vm, Event.AgentReportStopped, null, work, Step.Done); + if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) { + throw new CloudRuntimeException("Unable to stop " + vm); + } } catch (NoTransitionException e) { s_logger.warn("Unable to cleanup " + vm); - return false; + throw new CloudRuntimeException("Unable to stop " + vm, e); } } else { if (s_logger.isDebugEnabled()) { @@ -1261,18 +1269,20 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (AgentUnavailableException e) { s_logger.warn("Unable to stop vm, agent unavailable: " + e.toString()); + throw e; } catch (OperationTimedoutException e) { s_logger.warn("Unable to stop vm, operation timed out: " + e.toString()); + throw e; } finally { if (!stopped) { - if (!forced) { + if (!cleanUpEvenIfUnableToStop) { s_logger.warn("Unable to stop vm " + vm); try { stateTransitTo(vm, Event.OperationFailed, vm.getHostId()); } catch (NoTransitionException e) { s_logger.warn("Unable to transition the state " + vm); } - return false; + throw new CloudRuntimeException("Unable to stop " + vm); } else { s_logger.warn("Unable to actually stop " + vm + " but continue with release because it's a force stop"); vmGuru.finalizeStop(profile, answer); @@ -1285,7 +1295,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } try { - _networkMgr.release(profile, forced); + _networkMgr.release(profile, cleanUpEvenIfUnableToStop); s_logger.debug("Successfully released network resources for the vm " + vm); } catch (Exception e) { s_logger.warn("Unable to release some network resources.", e); @@ -1309,10 +1319,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac _workDao.update(work.getId(), work); } - return stateTransitTo(vm, Event.OperationSucceeded, null); + if (!stateTransitTo(vm, Event.OperationSucceeded, null)) { + throw new CloudRuntimeException("unable to stop " + vm); + } } catch (NoTransitionException e) { s_logger.warn(e.getMessage()); - return false; + throw new CloudRuntimeException("Unable to stop " + vm); } } @@ -1352,38 +1364,35 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public boolean destroy(T vm, User user, Account caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Destroying vm " + vm); - } + public void destroy(String vmUuid) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { + VMInstanceVO vm = _vmDao.findByUuid(vmUuid); if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging || vm.getRemoved() != null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to find vm or vm is destroyed: " + vm); } - return true; + return; } - if (!advanceStop(vm, _forceStop, user, caller)) { - s_logger.debug("Unable to stop " + vm); - return false; + if (s_logger.isDebugEnabled()) { + s_logger.debug("Destroying vm " + vm); } + advanceStop(vm, _forceStop); + if (!_vmSnapshotMgr.deleteAllVMSnapshots(vm.getId(),null)){ s_logger.debug("Unable to delete all snapshots for " + vm); - return false; + throw new CloudRuntimeException("Unable to delete vm snapshots for " + vm); } try { if (!stateTransitTo(vm, VirtualMachine.Event.DestroyRequested, vm.getHostId())) { s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm); - return false; + throw new CloudRuntimeException("Unable to destroy " + vm); } } catch (NoTransitionException e) { s_logger.debug(e.getMessage()); - return false; + throw new CloudRuntimeException("Unable to destroy " + vm, e); } - - return true; } //list all the nics which belong to this vm and are the last nics in the subnets. @@ -1418,11 +1427,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public T storageMigration(T vm, StoragePool destPool) { - VirtualMachineGuru vmGuru = getVmGuru(vm); - - long vmId = vm.getId(); - vm = vmGuru.findById(vmId); + public T storageMigration(T vmm, StoragePool destPool) { + VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid()); try { stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null); @@ -1431,7 +1437,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException("Unable to migrate vm: " + e.toString()); } - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); boolean migrationResult = false; try { migrationResult = volumeMgr.storageMigration(profile, destPool); @@ -1441,7 +1447,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (!vm.getPodIdToDeployIn().equals(destPool.getPodId())) { DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null); _networkMgr.reallocate(vmProfile, plan); } @@ -1472,12 +1478,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - return vm; + return vmm; } @Override - public T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, + public T migrate(T vmm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, + ManagementServerException, VirtualMachineMigrationException { + VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid()); + if (vm == null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Unable to find the vm " + vm); + } + throw new CloudRuntimeException("Unable to find a virtual machine with id " + vmm.getUuid()); + } + s_logger.info("Migrating " + vm + " to " + dest); long dstHostId = dest.getHost().getId(); @@ -1492,16 +1507,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId()); } - VirtualMachineGuru vmGuru = getVmGuru(vm); - - long vmId = vm.getId(); - vm = vmGuru.findById(vmId); - if (vm == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find the vm " + vm); - } - throw new ManagementServerException("Unable to find a virtual machine with id " + vmId); - } + VirtualMachineGuru vmGuru = getVmGuru(vm); if (vm.getState() != State.Running) { if (s_logger.isDebugEnabled()) { @@ -1517,12 +1523,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac alertType = AlertManager.ALERT_TYPE_CONSOLE_PROXY_MIGRATE; } - VirtualMachineProfile vmSrc = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile vmSrc = new VirtualMachineProfileImpl(vm); for(NicProfile nic: _networkMgr.getNicProfiles(vm)){ vmSrc.addNic(nic); } - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); _networkMgr.prepareNicForMigration(profile, dest); volumeMgr.prepareForMigration(profile, dest); @@ -1602,14 +1608,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (AgentUnavailableException e) { s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId); } - cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); return null; } } catch (OperationTimedoutException e) { } migrated = true; - return vm; + return vmm; } finally { if (!migrated) { s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); @@ -1637,7 +1643,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - private Map getPoolListForVolumesForMigration(VirtualMachineProfile profile, + private Map getPoolListForVolumesForMigration(VirtualMachineProfile profile, Host host, Map volumeToPool) { List allVolumes = _volsDao.findUsableVolumesForInstance(profile.getId()); for (VolumeVO volume : allVolumes) { @@ -1725,13 +1731,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public T migrateWithStorage(T vm, long srcHostId, long destHostId, + public T migrateWithStorage(T vmm, long srcHostId, long destHostId, Map volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid()); HostVO srcHost = _hostDao.findById(srcHostId); HostVO destHost = _hostDao.findById(destHostId); - VirtualMachineGuru vmGuru = getVmGuru(vm); + VirtualMachineGuru vmGuru = getVmGuru(vm); DataCenterVO dc = _dcDao.findById(destHost.getDataCenterId()); HostPodVO pod = _podDao.findById(destHost.getPodId()); @@ -1739,9 +1746,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac DeployDestination destination = new DeployDestination(dc, pod, cluster, destHost); // Create a map of which volume should go in which storage pool. - long vmId = vm.getId(); - vm = vmGuru.findById(vmId); - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); volumeToPool = getPoolListForVolumesForMigration(profile, destHost, volumeToPool); // If none of the volumes have to be migrated, fail the call. Administrator needs to make a call for migrating @@ -1789,8 +1794,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (AgentUnavailableException e) { s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId); } - cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true, - _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); return null; } } catch (OperationTimedoutException e) { @@ -1798,7 +1802,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } migrated = true; - return vm; + return vmm; } finally { if (!migrated) { s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); @@ -1821,7 +1825,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public VirtualMachineTO toVmTO(VirtualMachineProfile profile) { + public VirtualMachineTO toVmTO(VirtualMachineProfile profile) { HypervisorGuru hvGuru = _hvGuruMgr.getGuru(profile.getVirtualMachine().getHypervisorType()); VirtualMachineTO to = hvGuru.implement(profile); return to; @@ -1868,14 +1872,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public boolean migrateAway(VirtualMachine.Type vmType, long vmId, long srcHostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException { - VirtualMachineGuru vmGuru = _vmGurus.get(vmType); - VMInstanceVO vm = vmGuru.findById(vmId); + VMInstanceVO vm = _vmDao.findById(vmId); if (vm == null) { s_logger.debug("Unable to find a VM for " + vmId); return true; } - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); Long hostId = vm.getHostId(); if (hostId == null) { @@ -1934,8 +1937,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return true; } try { - boolean result = advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); - return result; + advanceStop(vm, true); + return true; } catch (ResourceUnavailableException e) { s_logger.debug("Unable to stop VM due to " + e.getMessage()); } catch (ConcurrentOperationException e) { @@ -2016,12 +2019,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return rebootedVm; } - @Override - public VMInstanceVO findByIdAndType(VirtualMachine.Type type, long vmId) { - VirtualMachineGuru guru = _vmGurus.get(type); - return guru.findById(vmId); - } - public Command cleanup(VirtualMachine vm) { return new StopCommand(vm, _mgmtServer.getExecuteInSequence()); } @@ -2292,7 +2289,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (newStates == null) { return map; } - Collection> vmGurus = _vmGurus.values(); boolean is_alien_vm = true; long alien_vm_count = -1; for (Map.Entry> entry : newStates.entrySet()) { @@ -2302,7 +2298,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (vm != null) { map.put(vm.getId(), new AgentVmInfo(entry.getKey(), vm, entry.getValue().second(), entry.getValue().first())); is_alien_vm = false; - break; } // alien VMs if (is_alien_vm){ @@ -2467,7 +2462,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (agentState == State.Shutdowned) { if (serverState == State.Running || serverState == State.Starting || serverState == State.Stopping) { try { - advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + advanceStop(vm, true); } catch (AgentUnavailableException e) { assert (false) : "How do we hit this with forced on?"; return null; @@ -2531,10 +2526,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } private void ensureVmRunningContext(long hostId, VMInstanceVO vm, Event cause) throws OperationTimedoutException, ResourceUnavailableException, NoTransitionException, InsufficientAddressCapacityException { - VirtualMachineGuru vmGuru = getVmGuru(vm); + VirtualMachineGuru vmGuru = getVmGuru(vm); s_logger.debug("VM state is starting on full sync so updating it to running"); - vm = findByIdAndType(vm.getType(), vm.getId()); + vm = _vmDao.findById(vm.getId()); // grab outstanding work item if any ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState()); @@ -2551,10 +2546,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } s_logger.debug("VM's " + vm + " state is starting on full sync so updating it to Running"); - vm = vmGuru.findById(vm.getId()); // this should ensure vm has the most + vm = _vmDao.findById(vm.getId()); // this should ensure vm has the most // up to date info - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); List nics = _nicsDao.listByVmId(profile.getId()); for (NicVO nic : nics) { Network network = _networkModel.getNetwork(nic.getNetworkId()); @@ -2754,7 +2749,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public String hostUuid; public VMInstanceVO vm; - @SuppressWarnings("unchecked") public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) { this.name = name; this.state = state; @@ -2869,7 +2863,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); DataCenter dc = _configMgr.getZone(network.getDataCenterId()); @@ -2889,8 +2883,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); //4) plug the nic to the vm - VirtualMachineGuru vmGuru = getVmGuru(vmVO); - s_logger.debug("Plugging nic for vm " + vm + " in network " + network); boolean result = false; @@ -2938,13 +2930,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); DataCenter dc = _configMgr.getZone(network.getDataCenterId()); Host host = _hostDao.findById(vm.getHostId()); DeployDestination dest = new DeployDestination(dc, null, null, host); - VirtualMachineGuru vmGuru = getVmGuru(vmVO); HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); @@ -3002,13 +2993,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM)); - VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null); DataCenter dc = _configMgr.getZone(network.getDataCenterId()); Host host = _hostDao.findById(vm.getHostId()); DeployDestination dest = new DeployDestination(dc, null, null, host); - VirtualMachineGuru vmGuru = getVmGuru(vmVO); HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType()); VirtualMachineTO vmTO = hvGuru.implement(vmProfile); @@ -3066,7 +3056,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId, ExcludeList excludes) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, VirtualMachineMigrationException, ManagementServerException { - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); Long srcHostId = vm.getHostId(); Long oldSvcOfferingId = vm.getServiceOfferingId(); @@ -3128,8 +3118,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } @Override - public T migrateForScale(T vm, long srcHostId, DeployDestination dest, Long oldSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, + public T migrateForScale(T vmm, long srcHostId, DeployDestination dest, Long oldSvcOfferingId) throws ResourceUnavailableException, + ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { + VMInstanceVO vm = _vmDao.findByUuid(vmm.getUuid()); s_logger.info("Migrating " + vm + " to " + dest); vm.getServiceOfferingId(); @@ -3145,10 +3137,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId()); } - VirtualMachineGuru vmGuru = getVmGuru(vm); + VirtualMachineGuru vmGuru = getVmGuru(vm); long vmId = vm.getId(); - vm = vmGuru.findById(vmId); + vm = _vmDao.findByUuid(vmm.getUuid()); if (vm == null) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to find the vm " + vm); @@ -3170,7 +3162,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac alertType = AlertManager.ALERT_TYPE_CONSOLE_PROXY_MIGRATE; } - VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); _networkMgr.prepareNicForMigration(profile, dest); volumeMgr.prepareForMigration(profile, dest); @@ -3250,14 +3242,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (AgentUnavailableException e) { s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId); } - cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount()); + cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); return null; } } catch (OperationTimedoutException e) { } migrated = true; - return vm; + return vmm; } finally { if (!migrated) { s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); diff --git a/server/src/com/cloud/vm/VirtualMachineProfileImpl.java b/server/src/com/cloud/vm/VirtualMachineProfileImpl.java index 033daf33422..5e84c1f235d 100644 --- a/server/src/com/cloud/vm/VirtualMachineProfileImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineProfileImpl.java @@ -21,9 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import com.cloud.agent.api.to.DiskTO; - import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; import com.cloud.service.ServiceOfferingVO; @@ -39,9 +37,9 @@ import com.cloud.user.dao.AccountDao; * Implementation of VirtualMachineProfile. * */ -public class VirtualMachineProfileImpl implements VirtualMachineProfile { +public class VirtualMachineProfileImpl implements VirtualMachineProfile { - T _vm; + VirtualMachine _vm; ServiceOfferingVO _offering; VMTemplateVO _template; UserVmDetailVO _userVmDetails; @@ -56,7 +54,7 @@ public class VirtualMachineProfileImpl implements Virtua VirtualMachine.Type _type; - public VirtualMachineProfileImpl(T vm, VMTemplateVO template, ServiceOfferingVO offering, Account owner, Map params) { + public VirtualMachineProfileImpl(VirtualMachine vm, VMTemplateVO template, ServiceOfferingVO offering, Account owner, Map params) { _vm = vm; _template = template; _offering = offering; @@ -69,7 +67,7 @@ public class VirtualMachineProfileImpl implements Virtua _type = vm.getType(); } - public VirtualMachineProfileImpl(T vm) { + public VirtualMachineProfileImpl(VirtualMachine vm) { this(vm, null, null, null, null); } @@ -83,7 +81,7 @@ public class VirtualMachineProfileImpl implements Virtua } @Override - public T getVirtualMachine() { + public VirtualMachine getVirtualMachine() { return _vm; } @@ -102,7 +100,7 @@ public class VirtualMachineProfileImpl implements Virtua @Override public void setBootLoaderType(BootloaderType bootLoader) { - this._bootloader = bootLoader; + _bootloader = bootLoader; } @Override @@ -232,7 +230,7 @@ public class VirtualMachineProfileImpl implements Virtua @Override public BootloaderType getBootLoaderType() { - return this._bootloader; + return _bootloader; } @Override @@ -256,11 +254,11 @@ public class VirtualMachineProfileImpl implements Virtua @Override public Float getCpuOvercommitRatio() { - return this.cpuOvercommitRatio; + return cpuOvercommitRatio; } @Override public Float getMemoryOvercommitRatio() { - return this.memoryOvercommitRatio; + return memoryOvercommitRatio; } } diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 686c6888ca1..5fea480e89c 100644 --- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -27,15 +27,15 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -61,8 +61,8 @@ 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.dao.HypervisorCapabilitiesDao; import com.cloud.hypervisor.HypervisorGuruManager; +import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.storage.GuestOSVO; import com.cloud.storage.Snapshot; @@ -74,7 +74,6 @@ import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.user.Account; import com.cloud.user.AccountManager; -import com.cloud.user.UserVO; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.uservm.UserVm; @@ -205,7 +204,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana } if (state == null) { - VMSnapshot.State[] status = { VMSnapshot.State.Ready, VMSnapshot.State.Creating, VMSnapshot.State.Allocated, + VMSnapshot.State[] status = { VMSnapshot.State.Ready, VMSnapshot.State.Creating, VMSnapshot.State.Allocated, VMSnapshot.State.Error, VMSnapshot.State.Expunging, VMSnapshot.State.Reverting }; sc.setParameters("status", (Object[]) status); } else { @@ -237,7 +236,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana } @Override - public VMSnapshot allocVMSnapshot(Long vmId, String vsDisplayName, String vsDescription, Boolean snapshotMemory) + public VMSnapshot allocVMSnapshot(Long vmId, String vsDisplayName, String vsDescription, Boolean snapshotMemory) throws ResourceAllocationException { Account caller = getCaller(); @@ -265,7 +264,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana vsDisplayName = vmSnapshotName; } if(_vmSnapshotDao.findByName(vmId,vsDisplayName) != null){ - throw new InvalidParameterValueException("Creating VM snapshot failed due to VM snapshot with name" + vsDisplayName + " already exists"); + throw new InvalidParameterValueException("Creating VM snapshot failed due to VM snapshot with name" + vsDisplayName + " already exists"); } // check VM state @@ -322,7 +321,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana } catch (Exception e) { String msg = e.getMessage(); s_logger.error("Create vm snapshot record failed for vm: " + vmId + " due to: " + msg); - } + } return null; } @@ -352,7 +351,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana } protected VMSnapshot createVmSnapshotInternal(UserVmVO userVm, VMSnapshotVO vmSnapshot, Long hostId) { - try { + try { CreateVMSnapshotAnswer answer = null; GuestOSVO guestOS = _guestOSDao.findById(userVm.getGuestOSId()); @@ -412,7 +411,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana List volumeVos = _volumeDao.findByInstance(vmId); for (VolumeVO volume : volumeVos) { - StoragePool pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId()); + StoragePool pool = (StoragePool)dataStoreMgr.getPrimaryDataStore(volume.getPoolId()); VolumeTO volumeTO = new VolumeTO(volume, pool); volumeTOs.add(volumeTO); } @@ -488,7 +487,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana _vmSnapshotDao.persist(child); } - // update current snapshot + // update current snapshot VMSnapshotVO current = _vmSnapshotDao.findCurrentSnapshotByVmId(vmSnapshot.getVmId()); if(current != null && current.getId() == vmSnapshot.getId() && vmSnapshot.getParent() != null){ VMSnapshotVO parent = _vmSnapshotDao.findById(vmSnapshot.getParent()); @@ -550,7 +549,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana @Override public boolean hasActiveVMSnapshotTasks(Long vmId){ - List activeVMSnapshots = _vmSnapshotDao.listByInstanceId(vmId, + List activeVMSnapshots = _vmSnapshotDao.listByInstanceId(vmId, VMSnapshot.State.Creating, VMSnapshot.State.Expunging,VMSnapshot.State.Reverting,VMSnapshot.State.Allocated); return activeVMSnapshots.size() > 0; } @@ -602,7 +601,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana // prepare DeleteVMSnapshotCommand String vmInstanceName = userVm.getInstanceName(); VMSnapshotTO parent = getSnapshotWithParents(vmSnapshot).getParent(); - VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), + VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent); GuestOSVO guestOS = _guestOSDao.findById(userVm.getGuestOSId()); DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs,guestOS.getDisplayName()); @@ -664,16 +663,14 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana "VM Snapshot reverting failed due to vm snapshot is not in the state of Created."); } - UserVO callerUser = _userDao.findById(CallContext.current().getCallingUserId()); - UserVmVO vm = null; Long hostId = null; - Account owner = _accountDao.findById(vmSnapshotVo.getAccountId()); // start or stop VM first, if revert from stopped state to running state, or from running to stopped if(userVm.getState() == VirtualMachine.State.Stopped && vmSnapshotVo.getType() == VMSnapshot.Type.DiskAndMemory){ try { - vm = _itMgr.advanceStart(userVm, new HashMap(), callerUser, owner); + _itMgr.advanceStart(userVm.getUuid(), new HashMap()); + vm = _userVMDao.findById(userVm.getId()); hostId = vm.getHostId(); } catch (Exception e) { s_logger.error("Start VM " + userVm.getInstanceName() + " before reverting failed due to " + e.getMessage()); @@ -682,7 +679,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana }else { if(userVm.getState() == VirtualMachine.State.Running && vmSnapshotVo.getType() == VMSnapshot.Type.Disk){ try { - _itMgr.advanceStop(userVm, true, callerUser, owner); + _itMgr.advanceStop(userVm.getUuid(), true); } catch (Exception e) { s_logger.error("Stop VM " + userVm.getInstanceName() + " before reverting failed due to " + e.getMessage()); throw new CloudRuntimeException(e.getMessage()); @@ -715,7 +712,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana List volumeTOs = getVolumeTOList(userVm.getId()); String vmInstanceName = userVm.getInstanceName(); VMSnapshotTO parent = getSnapshotWithParents(snapshot).getParent(); - VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(), + VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(), snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent); GuestOSVO guestOS = _guestOSDao.findById(userVm.getGuestOSId()); @@ -746,7 +743,7 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana String errMsg = "revert vm: " + userVm.getInstanceName() + " to snapshot " + vmSnapshotVo.getName() + " failed due to " + e.getMessage(); s_logger.error(errMsg); throw new CloudRuntimeException(e.getMessage()); - } + } return userVm; } diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java deleted file mode 100755 index 4577d0ae781..00000000000 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ /dev/null @@ -1,962 +0,0 @@ -// 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.network; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; -import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; -import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; -import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; -import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; -import org.springframework.stereotype.Component; - -import com.cloud.dc.DataCenter; -import com.cloud.dc.Pod; -import com.cloud.dc.Vlan.VlanType; -import com.cloud.deploy.DataCenterDeployment; -import com.cloud.deploy.DeployDestination; -import com.cloud.deploy.DeploymentPlan; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientAddressCapacityException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InsufficientVirtualNetworkCapcityException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.Network.Provider; -import com.cloud.network.Network.Service; -import com.cloud.network.Networks.TrafficType; -import com.cloud.network.addr.PublicIp; -import com.cloud.network.dao.IPAddressVO; -import com.cloud.network.dao.NetworkVO; -import com.cloud.network.GuestVlan; -import com.cloud.network.element.DhcpServiceProvider; -import com.cloud.network.element.LoadBalancingServiceProvider; -import com.cloud.network.element.StaticNatServiceProvider; -import com.cloud.network.element.UserDataServiceProvider; -import com.cloud.network.guru.NetworkGuru; -import com.cloud.network.rules.FirewallRule; -import com.cloud.network.rules.FirewallRule.Purpose; -import com.cloud.network.rules.FirewallRule.State; -import com.cloud.network.rules.LoadBalancerContainer.Scheme; -import com.cloud.network.rules.StaticNat; -import com.cloud.offering.NetworkOffering; -import com.cloud.offerings.NetworkOfferingVO; -import com.cloud.user.Account; -import com.cloud.user.User; -import com.cloud.utils.Pair; -import com.cloud.utils.component.ManagerBase; -import com.cloud.vm.*; -import com.cloud.vm.VirtualMachine.Type; -import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; -import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd; -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; -import org.apache.cloudstack.api.command.user.network.*; -import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; -import org.springframework.stereotype.Component; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; -import java.util.List; -import java.util.Map; -import java.util.Set; - -@Component -@Local(value = { NetworkManager.class, NetworkService.class }) -public class MockNetworkManagerImpl extends ManagerBase implements NetworkManager, NetworkService { - - @Override - public List getIsolatedNetworksOwnedByAccountInZone(long zoneId, Account owner) { - // TODO Auto-generated method stub - return null; - } - - @Override - public IPAddressVO associateIPToGuestNetwork(long ipId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - @Override - public IPAddressVO associatePortableIPToGuestNetwork(long ipAddrId, long networkId, boolean releaseOnFailure) throws ResourceAllocationException, ResourceUnavailableException { - return null;// TODO Auto-generated method stub - } - - @Override - public IPAddressVO disassociatePortableIPToGuestNetwork(long ipAddrId, long networkId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException { - return null; // TODO Auto-generated method stub - } - - @Override - public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) { - return false; - } - - @Override - public void transferPortableIP(long ipAddrId, long currentNetworkId, long newNetworkId) throws ResourceAllocationException, ResourceUnavailableException, - InsufficientAddressCapacityException, ConcurrentOperationException { - - } - - @Override - public boolean releaseIpAddress(long ipAddressId) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException { - // TODO Auto-generated method stub - return null; - } - - @Override - public List searchForNetworks(ListNetworksCmd cmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean deleteNetwork(long networkId) { - // TODO Auto-generated method stub - return false; - } - - @Override - public int getActiveNicsInNetwork(long networkId) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public Network getNetwork(long networkId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Network getNetwork(String networkUuid) { - // TODO Auto-generated method stub - return null; - } - - @Override - public IpAddress getIp(long id) { - // TODO Auto-generated method stub - return null; - } - - @Override - public NetworkProfile convertNetworkToNetworkProfile(long networkId) { - // TODO Auto-generated method stub - return null; - } - - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - // TODO Auto-generated method stub - return false; - } - - @Override - public String getName() { - // TODO Auto-generated method stub - return null; - } - - - @Override - public boolean disassociatePublicIpAddress(long id, long userId, Account caller) { - // TODO Auto-generated method stub - return false; - } - - - - @Override - public List setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) - throws ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - @Override - public List setupNetwork(Account owner, NetworkOffering offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId, - ACLType aclType, Boolean subdomainAccess, Long vpcId, Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - - - @Override - public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - - } - - @Override - public void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, - ResourceUnavailableException { - // TODO Auto-generated method stub - - } - - @Override - public void release(VirtualMachineProfile vmProfile, boolean forced) { - // TODO Auto-generated method stub - - } - - @Override - public void cleanupNics(VirtualMachineProfile vm) { - // TODO Auto-generated method stub - - } - - @Override - public void expungeNics(VirtualMachineProfile vm) { - // TODO Auto-generated method stub - - } - - - @Override - public List getNicProfiles(VirtualMachine vm) { - // TODO Auto-generated method stub - return null; - } - - - - - - @Override - public Pair implementNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, - InsufficientCapacityException { - // TODO Auto-generated method stub - return null; - } - - - @Override - public boolean destroyNetwork(long networkId, ReservationContext context) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, String networkDomain, Account owner, Long domainId, - PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String gatewayv6, String cidrv6, Boolean displayNetworkEnabled, String isolatedPvlan) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network networkToAssociateWith) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - - - - - @Override - public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - - - @Override - public boolean startNetwork(long networkId, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - - @Override - public IPAddressVO markIpAsUnavailable(long addrId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String acquireGuestIpAddress(Network network, String requestedIp) { - // TODO Auto-generated method stub - return null; - } - - - @Override - public boolean applyStaticNats(List staticNats, boolean continueOnError, boolean forRevoke) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - - - public Map> getNetworkOfferingServiceProvidersMap(long networkOfferingId) { - return null; - } - - - - - - @Override - public PhysicalNetwork createPhysicalNetwork(Long zoneId, String vnetRange, String networkSpeed, List isolationMethods, String broadcastDomainRange, Long domainId, List tags, String name) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Pair, Integer> searchPhysicalNetworks(Long id, Long zoneId, String keyword, Long startIndex, Long pageSize, String name) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetwork updatePhysicalNetwork(Long id, String networkSpeed, List tags, String newVnetRangeString, String state, String removeVlan) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean deletePhysicalNetwork(Long id) { - // TODO Auto-generated method stub - return false; - } - - @Override - public GuestVlan dedicateGuestVlanRange(DedicateGuestVlanRangeCmd cmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Pair, Integer> listDedicatedGuestVlanRanges(ListDedicatedGuestVlanRangesCmd cmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean releaseDedicatedGuestVlanRange(Long dedicatedGuestVlanRangeId) { - // TODO Auto-generated method stub - return true; - } - - @Override - public List listNetworkServices(String providerName) { - // TODO Auto-generated method stub - return null; - } - - - @Override - public PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List enabledServices) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Pair, Integer> listNetworkServiceProviders(Long physicalNetworkId, String name, String state, Long startIndex, Long pageSize) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean deleteNetworkServiceProvider(Long id) { - // TODO Auto-generated method stub - return false; - } - - @Override - public PhysicalNetwork getPhysicalNetwork(Long physicalNetworkId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetwork getCreatedPhysicalNetwork(Long physicalNetworkId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetworkServiceProvider getPhysicalNetworkServiceProvider(Long providerId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetworkServiceProvider getCreatedPhysicalNetworkServiceProvider(Long providerId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public long findPhysicalNetworkId(long zoneId, String tag, TrafficType trafficType) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public PhysicalNetworkTrafficType getPhysicalNetworkTrafficType(Long id) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetworkTrafficType updatePhysicalNetworkTrafficType(Long id, String xenLabel, String kvmLabel, String vmwareLabel) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean deletePhysicalNetworkTrafficType(Long id) { - // TODO Auto-generated method stub - return false; - } - - @Override - public Pair, Integer> listTrafficTypes(Long physicalNetworkId) { - // TODO Auto-generated method stub - return null; - } - - - @Override - public Network getExclusiveGuestNetwork(long zoneId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public UserDataServiceProvider getPasswordResetProvider(Network network) { - // TODO Auto-generated method stub - return null; - } - - @Override - public UserDataServiceProvider getSSHKeyResetProvider(Network network) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetworkServiceProvider updateNetworkServiceProvider(Long id, String state, List enabledServices) { - // TODO Auto-generated method stub - return null; - } - - @Override - public PhysicalNetworkTrafficType addTrafficTypeToPhysicalNetwork(Long physicalNetworkId, String trafficType, String xenLabel, String kvmLabel, String vmwareLabel, String simulatorLabel, String vlan) { - // TODO Auto-generated method stub - return null; - } - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#applyRules(java.util.List, com.cloud.network.rules.FirewallRule.Purpose, com.cloud.network.NetworkRuleApplier, boolean) - */ - @Override - public boolean applyRules(List rules, Purpose purpose, NetworkRuleApplier applier, - boolean continueOnError) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#applyIpAssociations(com.cloud.network.Network, boolean, boolean, java.util.List) - */ - @Override - public boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError, - List publicIps) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#restartNetwork(java.lang.Long, com.cloud.user.Account, com.cloud.user.User, boolean) - */ - @Override - public boolean restartNetwork(Long networkId, Account callerAccount, User callerUser, boolean cleanup) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#shutdownNetworkElementsAndResources(com.cloud.vm.ReservationContext, boolean, com.cloud.network.NetworkVO) - */ - @Override - public boolean shutdownNetworkElementsAndResources(ReservationContext context, boolean b, NetworkVO network) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#implementNetworkElementsAndResources(com.cloud.deploy.DeployDestination, com.cloud.vm.ReservationContext, com.cloud.network.NetworkVO, com.cloud.offerings.NetworkOfferingVO) - */ - @Override - public void implementNetworkElementsAndResources(DeployDestination dest, ReservationContext context, - NetworkVO network, NetworkOfferingVO findById) throws ConcurrentOperationException, - InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#allocateIp(com.cloud.user.Account, boolean, com.cloud.user.Account, com.cloud.dc.DataCenter) - */ - @Override - public IpAddress allocateIp(Account ipOwner, boolean isSystem, Account caller, long callerId, DataCenter zone) - throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#finalizeServicesAndProvidersForNetwork(com.cloud.offering.NetworkOffering, java.lang.Long) - */ - @Override - public Map finalizeServicesAndProvidersForNetwork(NetworkOffering offering, Long physicalNetworkId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#getNicProfileForVm(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.VirtualMachine) - */ - protected NicProfile getNicProfileForVm(Network network, NicProfile requested, VirtualMachine vm) { - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#getOnePhysicalNetworkByZoneAndTrafficType(long, com.cloud.network.Networks.TrafficType) - */ - protected PhysicalNetwork getOnePhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#getZoneNetworkDomain(long) - */ - protected String getZoneNetworkDomain(long zoneId) { - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#getNicInNetworkIncludingRemoved(long, long) - */ - protected Nic getNicInNetworkIncludingRemoved(long vmId, long networkId) { - return null; - } - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#restartNetwork(com.cloud.api.commands.RestartNetworkCmd, boolean) - */ - @Override - public boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, - ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#updateGuestNetwork(long, java.lang.String, java.lang.String, com.cloud.user.Account, com.cloud.user.User, java.lang.String, java.lang.Long, java.lang.Boolean) - */ - @Override - public Network updateGuestNetwork(long networkId, String name, String displayText, Account callerAccount, - User callerUser, String domainSuffix, Long networkOfferingId, Boolean changeCidr, String guestVmCidr, Boolean displayNetwork) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#listTrafficTypeImplementor(com.cloud.api.commands.ListTrafficTypeImplementorsCmd) - */ - @Override - public List> listTrafficTypeImplementor(ListTrafficTypeImplementorsCmd cmd) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long, com.cloud.user.Account) - */ - @Override - public List getIsolatedNetworksWithSourceNATOwnedByAccountInZone(long zoneId, Account owner) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#associateIPToNetwork(long, long) - */ - @Override - public IpAddress associateIPToNetwork(long ipId, long networkId) throws InsufficientAddressCapacityException, - ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - @Override - - public Network createPrivateNetwork(String networkName, String displayText, long physicalNetworkId, String vlan, - String startIp, String endIP, String gateway, String netmask, long networkOwnerId, Long vpcId, Boolean sourceNat) - throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#assignPublicIpAddress(long, java.lang.Long, com.cloud.user.Account, com.cloud.dc.Vlan.VlanType, java.lang.Long, java.lang.String, boolean) - */ - @Override - public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId, - String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#shutdownNetwork(long, com.cloud.vm.ReservationContext, boolean) - */ - @Override - public boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#reallocate(com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DataCenterDeployment) - */ - @Override - public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) - throws InsufficientCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#assignSystemIp(long, com.cloud.user.Account, boolean, boolean) - */ - @Override - public IpAddress assignSystemIp(long networkId, Account owner, boolean forElasticLb, boolean forElasticIp) - throws InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#handleSystemIpRelease(com.cloud.network.IpAddress) - */ - @Override - public boolean handleSystemIpRelease(IpAddress ip) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String) - */ - @Override - public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, - Network network, String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException, - InsufficientAddressCapacityException { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#assignSourceNatIpAddressToGuestNetwork(com.cloud.user.Account, com.cloud.network.Network) - */ - @Override - public PublicIp assignSourceNatIpAddressToGuestNetwork(Account owner, Network guestNetwork) - throws InsufficientAddressCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#allocateNic(com.cloud.vm.NicProfile, com.cloud.network.Network, java.lang.Boolean, int, com.cloud.vm.VirtualMachineProfile) - */ - @Override - public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, - int deviceId, VirtualMachineProfile vm) - throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, - ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#prepareNic(com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DeployDestination, com.cloud.vm.ReservationContext, long, com.cloud.network.NetworkVO) - */ - @Override - public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, - ReservationContext context, long nicId, NetworkVO network) - throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, - ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#removeNic(com.cloud.vm.VirtualMachineProfile, com.cloud.vm.Nic) - */ - @Override - public void removeNic(VirtualMachineProfile vm, Nic nic) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#setupDns(com.cloud.network.Network, com.cloud.network.Network.Provider) - */ - @Override - public boolean setupDns(Network network, Provider provider) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.vm.Nic) - */ - @Override - public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) - throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#createNicForVm(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.ReservationContext, com.cloud.vm.VirtualMachineProfileImpl, boolean) - */ - @Override - public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, - VirtualMachineProfile vmProfile, boolean prepare) - throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, - ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#markPublicIpAsAllocated(com.cloud.network.IPAddressVO) - */ - @Override - public void markPublicIpAsAllocated(IPAddressVO addr) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#assignDedicateIpAddress(com.cloud.user.Account, java.lang.Long, java.lang.Long, long, boolean) - */ - @Override - public PublicIp assignDedicateIpAddress(Account owner, Long guestNtwkId, Long vpcId, long dcId, boolean isSourceNat) - throws ConcurrentOperationException, InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkManager#getNetworkLockTimeout() - */ - @Override - public int getNetworkLockTimeout() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public boolean isNetworkInlineMode(Network network) { - // TODO Auto-generated method stub - return false; - } - - @Override - public StaticNatServiceProvider getStaticNatProviderForNetwork(Network network) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getProvidersForServiceInNetwork(Network network, - Service service) { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getRuleCountForIp(Long addressId, Purpose purpose, State state) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network, Scheme lbScheme) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.network.NetworkService#allocateIP(com.cloud.user.Account, boolean, long) - */ - @Override - public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, - InsufficientAddressCapacityException, ConcurrentOperationException { - // TODO Auto-generated method stub - return null; - } - - @Override - public IpAddress allocatePortableIp(Account ipOwner, Account caller, long dcId, Long networkId, Long vpcID) - throws ConcurrentOperationException, ResourceAllocationException, InsufficientAddressCapacityException { - return null;// TODO Auto-generated method stub - } - - @Override - public IpAddress allocatePortableIP(Account ipOwner, int regionId, Long zoneId, Long networkId, Long vpcId) throws ResourceAllocationException, - InsufficientAddressCapacityException, ConcurrentOperationException { - return null; - } - - @Override - public boolean releasePortableIpAddress(long ipAddressId) { - return false;// TODO Auto-generated method stub - } - - @Override - public boolean isSecondaryIpSetForNic(long nicId) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean releaseSecondaryIpFromNic(long ipAddressId) { - // TODO Auto-generated method stub - return false; - } - - @Override - public NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId, - Long nicId, Long networkId, String ipaddress) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String allocateGuestIP(Account ipOwner, boolean isSystem, - long zoneId, Long networkId, String requestedIp) - throws InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - - - @Override - public List listVmNics(Long vmId, Long nicId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List listNics(ListNicsCmd listNicsCmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Map getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, - Pod pod, Account caller, String requestedIp) - throws InsufficientAddressCapacityException { - // TODO Auto-generated method stub - return null; - } - - - @Override - public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) { - // TODO Auto-generated method stub - return null; - } - - @Override - public DhcpServiceProvider getDhcpServiceProvider(Network network) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public PublicIp assignPublicIpAddressFromVlans(long dcId, Long podId, Account owner, VlanType type, List vlanDbIds, Long networkId, String requestedIp, boolean isSystem) throws InsufficientAddressCapacityException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void prepareNicForMigration( - VirtualMachineProfile vm, - DeployDestination dest) { - // TODO Auto-generated method stub - - } - - @Override - public void commitNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { - // TODO Auto-generated method stub - - } - - @Override - public void rollbackNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { - // TODO Auto-generated method stub - } -} diff --git a/server/test/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImplTest.java b/server/test/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImplTest.java deleted file mode 100644 index 071f658f056..00000000000 --- a/server/test/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImplTest.java +++ /dev/null @@ -1,121 +0,0 @@ -// 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.network.router; - - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockingDetails; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import com.cloud.configuration.ZoneConfig; -import com.cloud.network.Network; -import com.cloud.network.NetworkModel; -import com.cloud.vm.VirtualMachine; -import org.apache.log4j.Logger; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.cloud.agent.AgentManager.OnError; -import com.cloud.agent.api.routing.DnsMasqConfigCommand; -import com.cloud.agent.manager.Commands; -import com.cloud.dc.DataCenter.NetworkType; -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.NetworkManager; -import com.cloud.network.router.VirtualRouter.RedundantState; -import com.cloud.network.vpc.VpcVO; -import com.cloud.network.vpc.dao.VpcDao; -import com.cloud.vm.DomainRouterVO; -import com.cloud.vm.NicVO; -import com.cloud.vm.dao.DomainRouterDao; -import com.cloud.vm.dao.NicDao; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations="classpath:/VpcVirtNetAppContext.xml") -public class VpcVirtualNetworkApplianceManagerImplTest { - private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImplTest.class); - - @Mock DataCenterDao _dcDao; - @Mock VpcDao _vpcDao; - @Mock VirtualRouter router; - @Mock NicDao _nicDao; - @Mock DomainRouterDao _routerDao; - @Mock NetworkModel _networkmodel; - @Mock NicVO nicVO; - @Mock DataCenterVO dcVO; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - - } - - @Test - public void testConfigDnsMasq() { - VpcVirtualNetworkApplianceManagerImpl vpcVirtNetAppMgr = new VpcVirtualNetworkApplianceManagerImpl(); - vpcVirtNetAppMgr._vpcDao = _vpcDao; - vpcVirtNetAppMgr._dcDao = _dcDao; - vpcVirtNetAppMgr._nicDao = _nicDao; - vpcVirtNetAppMgr._routerDao = _routerDao; - when(router.getId()).thenReturn(1L); - when(router.getVpcId()).thenReturn(1L); - when(router.getDataCenterId()).thenReturn(1L); - VpcVO vpc = new VpcVO(1L,"bla","bla",1L,1L,1L,"10.0.0.0/8","blieb.net"); - when( _vpcDao.findById(1L)).thenReturn(vpc); - DataCenterVO dcVo = new DataCenterVO(1L,"dc","dc","8.8.8.8",null,null,null,"10.0.0.0/8","bla.net",new Long(1L),NetworkType.Advanced,null,".net"); - Map map = new HashMap(); - dcVo.setDetails(map); - dcVo.setDetail(ZoneConfig.DnsSearchOrder.getName(), "dummy"); - when(_dcDao.findById(1L)).thenReturn(dcVo); - DomainRouterVO routerVo = new DomainRouterVO(1L,1L,1L,"brr",1L,HypervisorType.Any,1L,1L,1L,false,0,false,RedundantState.MASTER,false,false,1L); - when( _routerDao.findById(1L)).thenReturn(routerVo); -// when( vpcVirtNetAppMgr.getRouterControlIp(1L)).thenReturn("10.0.0.1"); - when( router.getInstanceName()).thenReturn("r-vm-1"); - when( router.getPublicIpAddress()).thenReturn("11.11.11.11"); - NicVO nicvo = new NicVO("server", 1l, 1l, VirtualMachine.Type.DomainRouter); - nicvo.setNetworkId(1l); - when(_nicDao.findByIp4AddressAndVmId(anyString(), anyLong())).thenReturn(nicvo); - NetworkManager netMgr = mock(NetworkManager.class); - vpcVirtNetAppMgr._networkMgr = netMgr; - vpcVirtNetAppMgr._networkModel = _networkmodel; - when(nicVO.getNetworkId()).thenReturn(1l); - when(_networkmodel.isProviderSupportServiceInNetwork(1l, Network.Service.Dhcp, Network.Provider.VirtualRouter)).thenReturn(true); - when(dcVO.getDetail(anyString())).thenReturn(null); - Commands cmds = new Commands(OnError.Stop); - - vpcVirtNetAppMgr.configDnsMasq(router, cmds); - Assert.assertEquals("expected one command",1, cmds.size()); - - DnsMasqConfigCommand cmd = cmds.getCommand(DnsMasqConfigCommand.class); - } - -} diff --git a/server/test/com/cloud/vm/UserVmManagerTest.java b/server/test/com/cloud/vm/UserVmManagerTest.java index 0eb9a089609..36ec9350881 100755 --- a/server/test/com/cloud/vm/UserVmManagerTest.java +++ b/server/test/com/cloud/vm/UserVmManagerTest.java @@ -197,8 +197,6 @@ public class UserVmManagerTest { when(_rootVols.get(eq(0))).thenReturn(_volumeMock); doReturn(3L).when(_volumeMock).getTemplateId(); when(_templateDao.findById(anyLong())).thenReturn(_templateMock); - when(_itMgr.stop(_vmMock, _userMock, _account)).thenReturn(true); - when(_itMgr.start(_vmMock, null, _userMock, _account)).thenReturn(_vmMock); when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock); doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong()); when(_volumeMock.getId()).thenReturn(3L); @@ -231,13 +229,11 @@ public class UserVmManagerTest { doReturn(ImageFormat.VHD).when(_templateMock).getFormat(); when(_templateDao.findById(anyLong())).thenReturn(_templateMock); doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock); - when(_itMgr.stop(_vmMock, _userMock, _account)).thenReturn(true); when(_storageMgr.allocateDuplicateVolume(_volumeMock, 14L)).thenReturn(_volumeMock); when(_templateMock.getGuestOSId()).thenReturn(5L); doNothing().when(_vmMock).setGuestOSId(anyLong()); doNothing().when(_vmMock).setTemplateId(3L); when(_vmDao.update(314L, _vmMock)).thenReturn(true); - when(_itMgr.start(_vmMock, null, _userMock, _account)).thenReturn(_vmMock); when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock); doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong()); when(_volumeMock.getId()).thenReturn(3L); @@ -271,14 +267,12 @@ public class UserVmManagerTest { doReturn(ImageFormat.ISO).when(_templateMock).getFormat(); when(_templateDao.findById(anyLong())).thenReturn(_templateMock); doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock); - when(_itMgr.stop(_vmMock, _userMock, _account)).thenReturn(true); when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock); doNothing().when(_vmMock).setIsoId(14L); when(_templateMock.getGuestOSId()).thenReturn(5L); doNothing().when(_vmMock).setGuestOSId(anyLong()); doNothing().when(_vmMock).setTemplateId(3L); when(_vmDao.update(314L, _vmMock)).thenReturn(true); - when(_itMgr.start(_vmMock, null, _userMock, _account)).thenReturn(_vmMock); when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock); doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong()); when(_volumeMock.getId()).thenReturn(3L); diff --git a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java index 1e6d005ca60..fba95b3d265 100644 --- a/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/server/test/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -223,6 +223,7 @@ public class VirtualMachineManagerImplTest { when(_workDao.update("1", _work)).thenReturn(true); when(_work.getId()).thenReturn("1"); doNothing().when(_work).setStep(ItWorkVO.Step.Done); + when(_vmInstanceDao.findByUuid(any(String.class))).thenReturn(_vmMock); //doNothing().when(_volsDao).detachVolume(anyLong()); //when(_work.setStep(ItWorkVO.Step.Done)).thenReturn("1"); @@ -270,7 +271,7 @@ public class VirtualMachineManagerImplTest { @Test (expected=CloudRuntimeException.class) public void testScaleVM3() throws Exception { - /*VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + /*VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); Long srcHostId = vm.getHostId(); Long oldSvcOfferingId = vm.getServiceOfferingId(); @@ -332,10 +333,9 @@ public class VirtualMachineManagerImplTest { doNothing().when(_work).setStep(ItWorkVO.Step.Done); // Mock the vm guru and the user vm object that gets returned. - _vmMgr._vmGurus = new HashMap>(); + _vmMgr._vmGurus = new HashMap(); UserVmManagerImpl userVmManager = mock(UserVmManagerImpl.class); _vmMgr.registerGuru(VirtualMachine.Type.User, userVmManager); - when(userVmManager.findById(anyLong())).thenReturn(_vmMock); // Mock the iteration over all the volumes of an instance. Iterator volumeIterator = mock(Iterator.class); diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java index fd61bc65c90..c10ec328d9c 100644 --- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java @@ -24,7 +24,9 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; -import com.cloud.vm.*; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd; @@ -33,8 +35,6 @@ import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd; import org.apache.cloudstack.api.command.user.network.ListNetworksCmd; import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd; import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; @@ -66,7 +66,11 @@ import com.cloud.network.addr.PublicIp; import com.cloud.network.dao.IPAddressVO; import com.cloud.network.dao.NetworkServiceMapDao; import com.cloud.network.dao.NetworkVO; -import com.cloud.network.element.*; +import com.cloud.network.element.DhcpServiceProvider; +import com.cloud.network.element.LoadBalancingServiceProvider; +import com.cloud.network.element.NetworkElement; +import com.cloud.network.element.StaticNatServiceProvider; +import com.cloud.network.element.UserDataServiceProvider; import com.cloud.network.guru.NetworkGuru; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule.Purpose; @@ -80,19 +84,15 @@ import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.utils.Pair; import com.cloud.utils.component.ManagerBase; +import com.cloud.vm.Nic; +import com.cloud.vm.NicProfile; +import com.cloud.vm.NicSecondaryIp; +import com.cloud.vm.NicVO; +import com.cloud.vm.ReservationContext; +import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; - import com.cloud.vm.VirtualMachineProfile; -import org.apache.cloudstack.acl.ControlledEntity.ACLType; -import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; -import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd; -import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd; -import org.apache.cloudstack.api.command.user.network.*; -import org.apache.cloudstack.api.command.user.vm.ListNicsCmd; -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - @Component @Local(value = { NetworkManager.class, NetworkService.class }) @@ -738,7 +738,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#allocate(com.cloud.vm.VirtualMachineProfile, java.util.List) */ @Override - public void allocate(VirtualMachineProfile vm, List> networks) + public void allocate(VirtualMachineProfile vm, List> networks) throws InsufficientCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub @@ -752,7 +752,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#prepare(com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DeployDestination, com.cloud.vm.ReservationContext) */ @Override - public void prepare(VirtualMachineProfile profile, DeployDestination dest, + public void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub @@ -767,7 +767,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#release(com.cloud.vm.VirtualMachineProfile, boolean) */ @Override - public void release(VirtualMachineProfile vmProfile, boolean forced) + public void release(VirtualMachineProfile vmProfile, boolean forced) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub @@ -781,7 +781,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#cleanupNics(com.cloud.vm.VirtualMachineProfile) */ @Override - public void cleanupNics(VirtualMachineProfile vm) { + public void cleanupNics(VirtualMachineProfile vm) { // TODO Auto-generated method stub } @@ -794,7 +794,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#expungeNics(com.cloud.vm.VirtualMachineProfile) */ @Override - public void expungeNics(VirtualMachineProfile vm) { + public void expungeNics(VirtualMachineProfile vm) { // TODO Auto-generated method stub } @@ -1001,7 +1001,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#reallocate(com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DataCenterDeployment) */ @Override - public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) + public boolean reallocate(VirtualMachineProfile vm, DataCenterDeployment dest) throws InsufficientCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub return false; @@ -1042,7 +1042,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#allocateDirectIp(com.cloud.vm.NicProfile, com.cloud.dc.DataCenter, com.cloud.vm.VirtualMachineProfile, com.cloud.network.Network, java.lang.String) */ @Override - public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, + public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile vm, Network network, String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { // TODO Auto-generated method stub @@ -1071,7 +1071,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage */ @Override public Pair allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, - int deviceId, VirtualMachineProfile vm) + int deviceId, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException { // TODO Auto-generated method stub @@ -1086,7 +1086,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#prepareNic(com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DeployDestination, com.cloud.vm.ReservationContext, long, com.cloud.network.NetworkVO) */ @Override - public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, + public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { @@ -1102,7 +1102,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#removeNic(com.cloud.vm.VirtualMachineProfile, com.cloud.vm.Nic) */ @Override - public void removeNic(VirtualMachineProfile vm, Nic nic) { + public void removeNic(VirtualMachineProfile vm, Nic nic) { // TODO Auto-generated method stub } @@ -1147,7 +1147,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage * @see com.cloud.network.NetworkManager#releaseNic(com.cloud.vm.VirtualMachineProfile, com.cloud.vm.Nic) */ @Override - public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) + public void releaseNic(VirtualMachineProfile vmProfile, Nic nic) throws ConcurrentOperationException, ResourceUnavailableException { // TODO Auto-generated method stub @@ -1158,7 +1158,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage */ @Override public NicProfile createNicForVm(Network network, NicProfile requested, ReservationContext context, - VirtualMachineProfile vmProfile, boolean prepare) + VirtualMachineProfile vmProfile, boolean prepare) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { // TODO Auto-generated method stub @@ -1419,7 +1419,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage @Override public void prepareNicForMigration( - VirtualMachineProfile vm, + VirtualMachineProfile vm, DeployDestination dest) { // TODO Auto-generated method stub @@ -1431,8 +1431,8 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage @Override public void commitNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { + VirtualMachineProfile src, + VirtualMachineProfile dst) { // TODO Auto-generated method stub } @@ -1443,8 +1443,8 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage @Override public void rollbackNicForMigration( - VirtualMachineProfile src, - VirtualMachineProfile dst) { + VirtualMachineProfile src, + VirtualMachineProfile dst) { // TODO Auto-generated method stub } diff --git a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java index f325c4af077..7f1048fa616 100644 --- a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java +++ b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java @@ -72,14 +72,14 @@ VpcVirtualNetworkApplianceService { * @see com.cloud.network.router.VirtualNetworkApplianceManager#savePasswordToRouter(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.VirtualMachineProfile, java.util.List) */ @Override - public boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + public boolean savePasswordToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @Override - public boolean saveSSHPublicKeyToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers, String SSHPublicKey) throws ResourceUnavailableException { + public boolean saveSSHPublicKeyToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers, String SSHPublicKey) throws ResourceUnavailableException { return false; //To change body of implemented methods use File | Settings | File Templates. } @@ -87,7 +87,7 @@ VpcVirtualNetworkApplianceService { * @see com.cloud.network.router.VirtualNetworkApplianceManager#saveUserDataToRouter(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.VirtualMachineProfile, java.util.List) */ @Override - public boolean saveUserDataToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, + public boolean saveUserDataToRouter(Network network, NicProfile nic, VirtualMachineProfile profile, List routers) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; @@ -196,7 +196,7 @@ VpcVirtualNetworkApplianceService { * @see com.cloud.network.router.VirtualNetworkApplianceManager#applyDhcpEntry(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DeployDestination, java.util.List) */ @Override - public boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, + public boolean applyDhcpEntry(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; @@ -206,14 +206,14 @@ VpcVirtualNetworkApplianceService { * @see com.cloud.network.router.VirtualNetworkApplianceManager#applyUserData(com.cloud.network.Network, com.cloud.vm.NicProfile, com.cloud.vm.VirtualMachineProfile, com.cloud.deploy.DeployDestination, java.util.List) */ @Override - public boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, + public boolean applyUserData(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, List routers) throws ResourceUnavailableException { // TODO Auto-generated method stub return false; } @Override - public boolean configDhcpForSubnet(Network network, NicProfile nic, VirtualMachineProfile uservm, DeployDestination dest, List routers) throws ResourceUnavailableException { + public boolean configDhcpForSubnet(Network network, NicProfile nic, VirtualMachineProfile uservm, DeployDestination dest, List routers) throws ResourceUnavailableException { return false; //To change body of implemented methods use File | Settings | File Templates. } diff --git a/server/test/resources/VpcVirtNetAppContext.xml b/server/test/resources/VpcVirtNetAppContext.xml deleted file mode 100644 index f8a8aa4ea4d..00000000000 --- a/server/test/resources/VpcVirtNetAppContext.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 054edd9fe72..003c87acd5b 100755 --- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -273,7 +273,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S newTemplTO.setSize(size); newDestTO = newTemplTO; } else { - return new CopyCmdAnswer("not implemented yet"); + VolumeObjectTO newVolTO = new VolumeObjectTO(); + newVolTO.setPath(finalDownloadPath); + newVolTO.setName(finalFileName); + newVolTO.setSize(size); + newDestTO = newVolTO; } return new CopyCmdAnswer(newDestTO); @@ -313,11 +317,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S File destFile = S3Utils.getFile(s3, s3.getBucketName(), srcData.getPath(), downloadDirectory, new FileNamingStrategy() { - @Override - public String determineFileName(final String key) { - return substringAfterLast(key, S3Utils.SEPARATOR); - } - }); + @Override + public String determineFileName(final String key) { + return substringAfterLast(key, S3Utils.SEPARATOR); + } + }); if (destFile == null) { return new CopyCmdAnswer("Can't find template"); @@ -589,10 +593,10 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, swiftPath, swiftPath, file.length(), file.length(), md5sum - ); + ); return answer; } catch (Exception e) { - s_logger.debug("Failed to register template into swift", e); + s_logger.debug("Failed to register template into swift", e); return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); } finally { if (file != null) { @@ -650,16 +654,17 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S ext = filePath.substring(i + 1); } if (ext != null) { - if (ext.equalsIgnoreCase("vhd")) + if (ext.equalsIgnoreCase("vhd")) { return ImageFormat.VHD; - else if (ext.equalsIgnoreCase("qcow2")) + } else if (ext.equalsIgnoreCase("qcow2")) { return ImageFormat.QCOW2; - else if (ext.equalsIgnoreCase("ova")) + } else if (ext.equalsIgnoreCase("ova")) { return ImageFormat.OVA; - else if (ext.equalsIgnoreCase("tar")) + } else if (ext.equalsIgnoreCase("tar")) { return ImageFormat.TAR; - else if (ext.equalsIgnoreCase("img")) + } else if (ext.equalsIgnoreCase("img")) { return ImageFormat.RAW; + } } return null; @@ -921,16 +926,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } else if (dstore instanceof SwiftTO) { String path = cmd.getDirectory(); String volumeId = StringUtils.substringAfterLast(path, "/"); // assuming - // that - // the - // filename - // is - // the - // last - // section - // in - // the - // path + // that + // the + // filename + // is + // the + // last + // section + // in + // the + // path String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId.toString(), ""); if (result != null) { String errMsg = "failed to delete snapshot for volume " + volumeId + " , err=" + result; @@ -971,12 +976,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S final File targetFile = S3Utils.getFile(s3, s3.getBucketName(), key, _storage.getFile(directoryName), new FileNamingStrategy() { - @Override - public String determineFileName(String key) { - return snapshotFileName; - } + @Override + public String determineFileName(String key) { + return snapshotFileName; + } - }); + }); if (cmd.getParent() != null) { @@ -1125,8 +1130,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S return new Answer(cmd, false, checksum); } finally { try { - if (is != null) + if (is != null) { is.close(); + } } catch (IOException e) { if (s_logger.isDebugEnabled()) { s_logger.debug("Could not close the file " + absoluteTemplatePath); @@ -1239,24 +1245,24 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S final String result = executeWithNoWaitLock(determineSnapshotLockId(accountId, volumeId), new Callable() { - @Override - public String call() throws Exception { + @Override + public String call() throws Exception { - if (deleteAllFlag) { - S3Utils.deleteDirectory(s3, bucket, determineSnapshotS3Directory(accountId, volumeId)); - } else { - S3Utils.deleteObject( - s3, - bucket, - determineSnapshotS3Key(accountId, volumeId, - determineSnapshotBackupFilename(name))); - } + if (deleteAllFlag) { + S3Utils.deleteDirectory(s3, bucket, determineSnapshotS3Directory(accountId, volumeId)); + } else { + S3Utils.deleteObject( + s3, + bucket, + determineSnapshotS3Key(accountId, volumeId, + determineSnapshotBackupFilename(name))); + } - return null; + return null; - } + } - }); + }); return result; @@ -1330,16 +1336,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } else if (dstore instanceof SwiftTO) { String path = obj.getPath(); String filename = StringUtils.substringAfterLast(path, "/"); // assuming - // that - // the - // filename - // is - // the - // last - // section - // in - // the - // path + // that + // the + // filename + // is + // the + // last + // section + // in + // the + // path String volumeId = StringUtils.substringAfterLast(StringUtils.substringBeforeLast(path, "/"), "/"); String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId, filename); if (result != null) { @@ -1391,8 +1397,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S String bucket = s3.getBucketName(); // List the objects in the source directory on S3 final List objectSummaries = S3Utils.getDirectory(s3, bucket, this.TEMPLATE_ROOT_DIR); - if (objectSummaries == null) + if (objectSummaries == null) { return null; + } Map tmpltInfos = new HashMap(); for (S3ObjectSummary objectSummary : objectSummaries) { String key = objectSummary.getKey(); @@ -1412,8 +1419,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S String bucket = s3.getBucketName(); // List the objects in the source directory on S3 final List objectSummaries = S3Utils.getDirectory(s3, bucket, this.VOLUME_ROOT_DIR); - if (objectSummaries == null) + if (objectSummaries == null) { return null; + } Map tmpltInfos = new HashMap(); for (S3ObjectSummary objectSummary : objectSummaries) { String key = objectSummary.getKey(); @@ -1596,8 +1604,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S boolean success = true; String result; result = configureIpFirewall(ipList, cmd.getIsAppendAIp()); - if (result != null) + if (result != null) { success = false; + } return new Answer(cmd, success, result); } @@ -1807,16 +1816,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S Long volumeId = obj.getId(); String path = obj.getPath(); String filename = StringUtils.substringAfterLast(path, "/"); // assuming - // that - // the - // filename - // is - // the - // last - // section - // in - // the - // path + // that + // the + // filename + // is + // the + // last + // section + // in + // the + // path String result = swiftDelete((SwiftTO) dstore, "V-" + volumeId.toString(), filename); if (result != null) { String errMsg = "failed to delete volume " + filename + " , err=" + result; @@ -1882,8 +1891,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S @Override public Type getType() { - if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role)) + if (SecondaryStorageVm.Role.templateProcessor.toString().equals(_role)) { return Host.Type.SecondaryStorage; + } return Host.Type.SecondaryStorageCmdExecutor; } @@ -1946,8 +1956,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } } - if (_inSystemVM) + if (_inSystemVM) { _storage.mkdirs(_parent); + } _configSslScr = Script.findScript(getDefaultScriptsDir(), "config_ssl.sh"); if (_configSslScr != null) { @@ -1972,8 +1983,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } _role = (String) params.get("role"); - if (_role == null) + if (_role == null) { _role = SecondaryStorageVm.Role.templateProcessor.toString(); + } s_logger.info("Secondary storage runs in role " + _role); _guid = (String) params.get("guid"); @@ -2189,8 +2201,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S if (result != null) { s_logger.warn("Unable to mount " + nfsPath + " due to " + result); file = new File(root); - if (file.exists()) + if (file.exists()) { file.delete(); + } return null; } @@ -2223,8 +2236,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S final StartupSecondaryStorageCommand cmd = new StartupSecondaryStorageCommand(); fillNetworkInformation(cmd); - if (_publicIp != null) + if (_publicIp != null) { cmd.setPublicIpAddress(_publicIp); + } if (_inSystemVM) { Script command = new Script("/bin/bash", s_logger); diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 596723c9fa4..664e9b0b2de 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -892,114 +892,6 @@ CREATE VIEW `cloud`.`host_view` AS and async_job.instance_type = 'Host' and async_job.job_status = 0; -DROP VIEW IF EXISTS `cloud`.`volume_view`; -CREATE VIEW `cloud`.`volume_view` AS - select - volumes.id, - volumes.uuid, - volumes.name, - volumes.device_id, - volumes.volume_type, - volumes.size, - volumes.min_iops, - volumes.max_iops, - volumes.created, - volumes.state, - volumes.attached, - volumes.removed, - volumes.pod_id, - account.id account_id, - account.uuid account_uuid, - account.account_name account_name, - account.type account_type, - domain.id domain_id, - domain.uuid domain_uuid, - domain.name domain_name, - domain.path domain_path, - projects.id project_id, - projects.uuid project_uuid, - projects.name project_name, - data_center.id data_center_id, - data_center.uuid data_center_uuid, - data_center.name data_center_name, - data_center.networktype data_center_type, - vm_instance.id vm_id, - vm_instance.uuid vm_uuid, - vm_instance.name vm_name, - vm_instance.state vm_state, - vm_instance.vm_type, - user_vm.display_name vm_display_name, - volume_host_ref.size volume_host_size, - volume_host_ref.created volume_host_created, - volume_host_ref.format, - volume_host_ref.download_pct, - volume_host_ref.download_state, - volume_host_ref.error_str, - disk_offering.id disk_offering_id, - disk_offering.uuid disk_offering_uuid, - disk_offering.name disk_offering_name, - disk_offering.display_text disk_offering_display_text, - disk_offering.use_local_storage, - disk_offering.system_use, - disk_offering.bytes_read_rate, - disk_offering.bytes_write_rate, - disk_offering.iops_read_rate, - disk_offering.iops_write_rate, - storage_pool.id pool_id, - storage_pool.uuid pool_uuid, - storage_pool.name pool_name, - cluster.hypervisor_type, - vm_template.id template_id, - vm_template.uuid template_uuid, - vm_template.extractable, - vm_template.type template_type, - resource_tags.id tag_id, - resource_tags.uuid tag_uuid, - resource_tags.key tag_key, - resource_tags.value tag_value, - resource_tags.domain_id tag_domain_id, - resource_tags.account_id tag_account_id, - resource_tags.resource_id tag_resource_id, - resource_tags.resource_uuid tag_resource_uuid, - resource_tags.resource_type tag_resource_type, - resource_tags.customer tag_customer, - async_job.id job_id, - async_job.uuid job_uuid, - async_job.job_status job_status, - async_job.account_id job_account_id - from - `cloud`.`volumes` - inner join - `cloud`.`account` ON volumes.account_id = account.id - inner join - `cloud`.`domain` ON volumes.domain_id = domain.id - left join - `cloud`.`projects` ON projects.project_account_id = account.id - left join - `cloud`.`data_center` ON volumes.data_center_id = data_center.id - left join - `cloud`.`vm_instance` ON volumes.instance_id = vm_instance.id - left join - `cloud`.`user_vm` ON user_vm.id = vm_instance.id - left join - `cloud`.`volume_host_ref` ON volumes.id = volume_host_ref.volume_id - and volumes.data_center_id = volume_host_ref.zone_id - left join - `cloud`.`disk_offering` ON volumes.disk_offering_id = disk_offering.id - left join - `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id - left join - `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id - left join - `cloud`.`vm_template` ON volumes.template_id = vm_template.id - left join - `cloud`.`resource_tags` ON resource_tags.resource_id = volumes.id - and resource_tags.resource_type = 'Volume' - left join - `cloud`.`async_job` ON async_job.instance_id = volumes.id - and async_job.instance_type = 'Volume' - and async_job.job_status = 0; - DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; CREATE VIEW `cloud`.`storage_pool_view` AS select @@ -1780,6 +1672,7 @@ CREATE VIEW `cloud`.`volume_view` AS volumes.removed, volumes.pod_id, volumes.display_volume, + volumes.format, account.id account_id, account.uuid account_uuid, account.account_name account_name, @@ -1801,12 +1694,11 @@ CREATE VIEW `cloud`.`volume_view` AS vm_instance.state vm_state, vm_instance.vm_type, user_vm.display_name vm_display_name, - volume_host_ref.size volume_host_size, - volume_host_ref.created volume_host_created, - volume_host_ref.format, - volume_host_ref.download_pct, - volume_host_ref.download_state, - volume_host_ref.error_str, + volume_store_ref.size volume_store_size, + volume_store_ref.download_pct, + volume_store_ref.download_state, + volume_store_ref.error_str, + volume_store_ref.created created_on_store, disk_offering.id disk_offering_id, disk_offering.uuid disk_offering_uuid, disk_offering.name disk_offering_name, @@ -1854,8 +1746,7 @@ CREATE VIEW `cloud`.`volume_view` AS left join `cloud`.`user_vm` ON user_vm.id = vm_instance.id left join - `cloud`.`volume_host_ref` ON volumes.id = volume_host_ref.volume_id - and volumes.data_center_id = volume_host_ref.zone_id + `cloud`.`volume_store_ref` ON volumes.id = volume_store_ref.volume_id left join `cloud`.`disk_offering` ON volumes.disk_offering_id = disk_offering.id left join @@ -1964,7 +1855,7 @@ CREATE VIEW `cloud`.`template_view` AS left join `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id left join - `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id + `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and template_store_ref.store_role = 'Image' left join `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id left join @@ -2257,3 +2148,5 @@ ALTER TABLE `cloud`.`network_offerings` ADD COLUMN `concurrent_connections` int( ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size` smallint(6) NOT NULL DEFAULT '0' COMMENT 'number of items being processed by the queue'; ALTER TABLE `cloud`.`sync_queue` MODIFY `queue_size_limit` smallint(6) NOT NULL DEFAULT '1' COMMENT 'max number of items the queue can process concurrently'; + +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'ucs.sync.blade.interval', '3600', 'the interval cloudstack sync with UCS manager for available blades in case user remove blades from chassis without notifying CloudStack'); diff --git a/test/integration/component/test_accounts.py b/test/integration/component/test_accounts.py index 7d0aeb1e352..92f7a6fa8b9 100644 --- a/test/integration/component/test_accounts.py +++ b/test/integration/component/test_accounts.py @@ -24,8 +24,7 @@ from marvin.integration.lib.base import * from marvin.integration.lib.common import * from marvin import remoteSSHClient from nose.plugins.attrib import attr -import datetime - +from marvin.cloudstackException import cloudstackAPIException class Services: """Test Account Services @@ -831,12 +830,12 @@ class TestServiceOfferingHierarchy(cloudstackTestCase): return -class TesttemplateHierarchy(cloudstackTestCase): +class TestTemplateHierarchy(cloudstackTestCase): @classmethod def setUpClass(cls): cls.api_client = super( - TesttemplateHierarchy, + TestTemplateHierarchy, cls).getClsTestClient().getApiClient() cls.services = Services().services # Get Zone settings @@ -877,10 +876,17 @@ class TesttemplateHierarchy(cloudstackTestCase): account=cls.account_1.name, domainid=cls.domain_1.id ) + + # Wait for template to download + cls.template.download(cls.api_client) + + # Wait for template status to be changed across + time.sleep(60) + cls._cleanup = [ cls.account_2, cls.domain_2, - cls.template, + cls.template, cls.account_1, cls.domain_1, ] @@ -946,7 +952,8 @@ class TesttemplateHierarchy(cloudstackTestCase): # Verify private service offering is not visible to other domain templates = list_templates( self.apiclient, - templatefilter='self', + id=self.template.id, + templatefilter='all', account=self.account_2.name, domainid=self.domain_2.id ) @@ -1560,9 +1567,8 @@ class TestUserLogin(cloudstackTestCase): respose = User.login( self.apiclient, username=self.account.name, - password=self.services["account"]["password"] - ) - self.assertEqual(respose, None, "Login response should not be none") + password=self.services["account"]["password"], + domainid=domain.id) self.debug("Login API response: %s" % respose) self.assertNotEqual( @@ -1788,18 +1794,13 @@ class TestDomainForceRemove(cloudstackTestCase): # Sleep to ensure that all resources are deleted time.sleep(int(configurations[0].value) * 2) self.debug("Checking if the resources in domain are deleted or not..") - accounts = Account.list( - self.apiclient, - name=self.account_1.name, - domainid=self.account_1.domainid, - listall=True - ) - - self.assertEqual( - accounts, - None, - "Account should get automatically deleted after domain removal" - ) + with self.assertRaises(cloudstackAPIException): + Account.list( + self.apiclient, + name=self.account_1.name, + domainid=self.account_1.domainid, + listall=True + ) return @attr(tags=["domains", "advanced", "advancedns", "simulator"]) diff --git a/test/integration/component/test_netscaler_nw_off.py b/test/integration/component/test_netscaler_nw_off.py index c328f48ea64..5fd21950fe7 100644 --- a/test/integration/component/test_netscaler_nw_off.py +++ b/test/integration/component/test_netscaler_nw_off.py @@ -783,21 +783,21 @@ class TestNetScalerSharedMode(cloudstackTestCase): self.network_3 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_3.id) - self.debug("Deploying VM in account: %s" % self.account_3.account.name) + self.debug("Deploying VM in account: %s" % self.account_3.name) with self.assertRaises(Exception): # Spawn an instance in that network virtual_machine_3 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_3.id)] ) @@ -857,8 +857,8 @@ class TestNetScalerSharedMode(cloudstackTestCase): self.network_offering.id) networks = Network.list( self.apiclient, - account=self.account_3.account.name, - domainid=self.account_3.account.domainid, + account=self.account_3.name, + domainid=self.account_3.domainid, zoneid=self.zone.id, listall=True ) @@ -866,19 +866,19 @@ class TestNetScalerSharedMode(cloudstackTestCase): isinstance(networks, list), True, "Network should be present for the account: %s" % - self.account_3.account.name + self.account_3.name ) self.network_3 = networks[0] self.debug("Created network with ID: %s" % self.network_3.id) - self.debug("Deploying VM in account: %s" % self.account_3.account.name) + self.debug("Deploying VM in account: %s" % self.account_3.name) # Spawn an instance in that network virtual_machine_3 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_3.id)] ) @@ -923,21 +923,21 @@ class TestNetScalerSharedMode(cloudstackTestCase): self.network_4 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_4.account.name, - domainid=self.account_4.account.domainid, + accountid=self.account_4.name, + domainid=self.account_4.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_4.id) - self.debug("Deploying VM in account: %s" % self.account_4.account.name) + self.debug("Deploying VM in account: %s" % self.account_4.name) # Spawn an instance in that network virtual_machine_4 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_4.account.name, - domainid=self.account_4.account.domainid, + accountid=self.account_4.name, + domainid=self.account_4.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_4.id)] ) @@ -970,22 +970,22 @@ class TestNetScalerSharedMode(cloudstackTestCase): self.network_5 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_5.account.name, - domainid=self.account_5.account.domainid, + accountid=self.account_5.name, + domainid=self.account_5.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_5.id) - self.debug("Deploying VM in account: %s" % self.account_5.account.name) + self.debug("Deploying VM in account: %s" % self.account_5.name) with self.assertRaises(Exception): # Spawn an instance in that network virtual_machine_5 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_5.account.name, - domainid=self.account_5.account.domainid, + accountid=self.account_5.name, + domainid=self.account_5.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_5.id)] ) @@ -1005,9 +1005,9 @@ class TestNetScalerSharedMode(cloudstackTestCase): # 2. Create an instance from another account # 3. Deploy instance should succeed - self.debug("Delete account: %s" % self.account_4.account.name) + self.debug("Delete account: %s" % self.account_4.name) self.account_4.delete(self.apiclient) - self.debug("Account: %s is deleted" % self.account_4.account.name) + self.debug("Account: %s is deleted" % self.account_4.name) interval = list_configurations( self.apiclient, @@ -1027,21 +1027,21 @@ class TestNetScalerSharedMode(cloudstackTestCase): self.network_5 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_5.account.name, - domainid=self.account_5.account.domainid, + accountid=self.account_5.name, + domainid=self.account_5.domainid, networkofferingid=self.network_offering.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_5.id) - self.debug("Deploying VM in account: %s" % self.account_5.account.name) + self.debug("Deploying VM in account: %s" % self.account_5.name) # Spawn an instance in that network virtual_machine_5 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_5.account.name, - domainid=self.account_5.account.domainid, + accountid=self.account_5.name, + domainid=self.account_5.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_5.id)] ) @@ -1504,21 +1504,21 @@ class TestNwOffNetscaler(cloudstackTestCase): self.network_3 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, networkofferingid=self.network_offering_shared.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_3.id) - self.debug("Deploying VM in account: %s" % self.account_3.account.name) + self.debug("Deploying VM in account: %s" % self.account_3.name) # Spawn an instance in that network virtual_machine_3 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_3.id)] ) @@ -1803,20 +1803,20 @@ class TestNwOffSToDUpgrade(cloudstackTestCase): self.network_3 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, networkofferingid=self.network_offering_dedicated.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_3.id) - self.debug("Deploying VM in account: %s" % self.account_3.account.name) + self.debug("Deploying VM in account: %s" % self.account_3.name) # Spawn an instance in that network virtual_machine_3 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_3.id)] ) @@ -2220,20 +2220,20 @@ class TestNwOffDToSUpgrade(cloudstackTestCase): self.network_3 = Network.create( self.apiclient, self.services["network"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, networkofferingid=self.network_offering_dedicated.id, zoneid=self.zone.id ) self.debug("Created network with ID: %s" % self.network_3.id) - self.debug("Deploying VM in account: %s" % self.account_3.account.name) + self.debug("Deploying VM in account: %s" % self.account_3.name) # Spawn an instance in that network virtual_machine_3 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], - accountid=self.account_3.account.name, - domainid=self.account_3.account.domainid, + accountid=self.account_3.name, + domainid=self.account_3.domainid, serviceofferingid=self.service_offering.id, networkids=[str(self.network_3.id)] ) @@ -2261,7 +2261,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase): "VM state should be running after deployment" ) - self.debug("Stopping all VMs in account: %s" % self.account_3.account.name) + self.debug("Stopping all VMs in account: %s" % self.account_3.name) virtual_machine_3.stop(self.apiclient) list_vm_response = VirtualMachine.list( @@ -2314,7 +2314,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase): self.network_offering_shared.id, "Network offering ID should match with new offering ID" ) - self.debug("Starting instances in account: %s" % self.account_3.account.name) + self.debug("Starting instances in account: %s" % self.account_3.name) virtual_machine_3.start(self.apiclient) list_vm_response = VirtualMachine.list( @@ -2346,9 +2346,9 @@ class TestNwOffDToSUpgrade(cloudstackTestCase): public_ip = PublicIPAddress.create( self.apiclient, - accountid=self.account_3.account.name, + accountid=self.account_3.name, zoneid=self.zone.id, - domainid=self.account_3.account.domainid, + domainid=self.account_3.domainid, networkid=self.network_3.id ) self.debug( @@ -2359,7 +2359,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase): self.apiclient, self.services["lbrule"], ipaddressid=public_ip.ipaddress.id, - accountid=self.account_3.account.name, + accountid=self.account_3.name, networkid=self.network_3.id ) self.debug("Created the load balancing rule for public IP: %s" % diff --git a/test/integration/component/test_project_configs.py b/test/integration/component/test_project_configs.py index 641649702e1..a9654c82f57 100644 --- a/test/integration/component/test_project_configs.py +++ b/test/integration/component/test_project_configs.py @@ -537,7 +537,7 @@ class TestProjectInviteRequired(cloudstackTestCase): project.addAccount( self.apiclient, self.user.name, - self.user.email + self.user.user[0].email ) # listProjectAccount to verify the user is added to project or not @@ -690,7 +690,7 @@ class TestProjectInviteRequiredTrue(cloudstackTestCase): project.addAccount( self.apiclient, self.user.name, - self.user.email + self.user.user[0].email ) # listProjectAccount to verify the user is added to project or not @@ -859,7 +859,7 @@ class TestProjectInviteTimeout(cloudstackTestCase): project.addAccount( self.apiclient, self.user.name, - self.user.email + self.user.user[0].email ) # listProjectAccount to verify the user is added to project or not diff --git a/test/integration/component/test_project_usage.py b/test/integration/component/test_project_usage.py index bb253e1c04a..1422febf975 100644 --- a/test/integration/component/test_project_usage.py +++ b/test/integration/component/test_project_usage.py @@ -1659,7 +1659,10 @@ class TestVpnUsage(cloudstackTestCase): # Remove VPN user self.debug("Deleting VPN user: %s" % vpnuser.id) - vpnuser.delete(self.apiclient) + vpnuser.delete( + self.apiclient, + projectid=self.project.id + ) # Delete VPN access self.debug("Deleting VPN: %s" % vpn.publicipid) diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 8f59dfe82cb..cfe97a4838e 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -136,7 +136,6 @@ class Services: }, "ostype": 'CentOS 5.3 (64-bit)', # Cent OS 5.3 (64 bit) - "sleep": 90, "timeout": 10, "mode": 'advanced' } @@ -207,33 +206,35 @@ class TestSharedNetworks(cloudstackTestCase): vm.delete(self.api_client) except Exception as e: raise Exception("Warning: Exception during virtual machines cleanup : %s" % e) - + try: for project in self.cleanup_projects: project.delete(self.api_client) except Exception as e: raise Exception("Warning: Exception during project cleanup : %s" % e) - + try: for account in self.cleanup_accounts: account.delete(self.api_client) except Exception as e: raise Exception("Warning: Exception during account cleanup : %s" % e) + #Wait till all resources created are cleaned up completely and then attempt to delete domains + wait_for_cleanup(self.api_client, ["account.cleanup.interval"]) + + try: + for network in self.cleanup_networks: + network.delete(self.api_client) + except Exception: + self.debug("Network %s failed to delete. Moving on" % network.id) + pass #because domain/account deletion will get rid of the network + try: for domain in self.cleanup_domains: domain.delete(self.api_client) except Exception as e: raise Exception("Warning: Exception during domain cleanup : %s" % e) - - #Wait till all resources created are cleaned up completely and then attempt to delete Network - time.sleep(self.services["sleep"]) - - try: - for network in self.cleanup_networks: - network.delete(self.api_client) - except Exception as e: - raise Exception("Warning: Exception during network cleanup : %s" % e) + return @attr(tags=["advanced", "advancedns"]) @@ -322,9 +323,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - - #Verify that the network offering got created + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -565,7 +564,7 @@ class TestSharedNetworks(cloudstackTestCase): # - conservemode = false # - specifyVlan = true # - specifyIpRanges = true - # 4. Enable network offering - updateNetworkOffering - state=Enabled + # 4. Create network offering - updateNetworkOffering - state=Enabled # 5. createNetwork # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = 123 (say) @@ -683,8 +682,8 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -750,7 +749,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.cleanup_networks.append(self.network) - + list_networks_response = Network.list( self.api_client, id=self.network.id @@ -836,7 +835,7 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_accountSpecific(self): - """ Test Shared Networm with scope account """ + """ Test Shared Network with scope account """ # Steps, # 1. create an Admin Account - admin-XABU1 @@ -966,9 +965,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - - #Verify that the network offering got created + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -1292,8 +1289,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1354,6 +1350,7 @@ class TestSharedNetworks(cloudstackTestCase): self.network = Network.create( self.api_client, self.services["network"], + accountid=self.domain_admin_account.name, domainid=self.dom_domain.id, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id @@ -1405,6 +1402,7 @@ class TestSharedNetworks(cloudstackTestCase): networkids=self.network.id, serviceofferingid=self.service_offering.id ) + self.cleanup_vms.append(self.domain_user_account_virtual_machine) vms = VirtualMachine.list( self.api_client, id=self.domain_user_account_virtual_machine.id, @@ -1433,6 +1431,7 @@ class TestSharedNetworks(cloudstackTestCase): networkids=self.network.id, serviceofferingid=self.service_offering.id ) + self.cleanup_vms.append(self.domain_admin_account_virtual_machine) vms = VirtualMachine.list( self.api_client, id=self.domain_admin_account_virtual_machine.id, @@ -1612,8 +1611,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1836,8 +1834,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1996,8 +1993,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2115,7 +2111,7 @@ class TestSharedNetworks(cloudstackTestCase): # Validations, # 1. shared networks should be created successfully # 2. a. VM should deploy successfully - # b. VM should bedeployed in both networks and have IP in both the networks + # b. VM should be deployed in both networks and have IP in both the networks #Create admin account self.admin_account = Account.create( @@ -2181,8 +2177,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2377,7 +2372,7 @@ class TestSharedNetworks(cloudstackTestCase): # 2. isolated network should be created successfully # 3. # a. VM should deploy successfully - # b. VM should bedeployed in both networks and have IP in both the networks + # b. VM should be deployed in both networks and have IP in both the networks # 4. FW and PF should apply successfully, ssh into the VM should work over isolated network #Create admin account @@ -2394,7 +2389,7 @@ class TestSharedNetworks(cloudstackTestCase): list_accounts_response = Account.list( self.api_client, id=self.admin_account.id, - liistall=True + listall=True ) self.assertEqual( isinstance(list_accounts_response, list), @@ -2424,8 +2419,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2484,8 +2478,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.isolated_network_offering) - + #Update network offering state from disabled to enabled. network_offering_update_response = NetworkOffering.update( self.isolated_network_offering, @@ -2534,13 +2527,14 @@ class TestSharedNetworks(cloudstackTestCase): physical_network = list_physical_networks_response[0] - #create network using the shared network offering created + #create network using the shared network offering created self.services["network"]["acltype"] = "domain" self.services["network"]["networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.shared_network = Network.create( self.api_client, self.services["network"], + accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id @@ -2597,15 +2591,16 @@ class TestSharedNetworks(cloudstackTestCase): ) self.debug("Isolated Network created: %s" % self.isolated_network.id) - - self.shared_network_admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.shared_network.id, - serviceofferingid=self.service_offering.id - ) + + self.shared_network_admin_account_virtual_machine =\ + VirtualMachine.create( + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.shared_network.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( self.api_client, id=self.shared_network_admin_account_virtual_machine.id, @@ -2623,16 +2618,18 @@ class TestSharedNetworks(cloudstackTestCase): ) self.debug("Virtual Machine created: %s" % self.shared_network_admin_account_virtual_machine.id) - self.assertTrue(self.shared_network_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") - - self.isolated_network_admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.isolated_network.id, - serviceofferingid=self.service_offering.id - ) + self.assertTrue(self.shared_network_admin_account_virtual_machine.nic[0].ipaddress is not None, + "ip should be assigned to running virtual machine") + + self.isolated_network_admin_account_virtual_machine = \ + VirtualMachine.create( + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.isolated_network.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( self.api_client, id=self.isolated_network_admin_account_virtual_machine.id, @@ -2678,7 +2675,7 @@ class TestSharedNetworks(cloudstackTestCase): #Create Firewall rule on source NAT fw_rule = FireWallRule.create( self.api_client, - ipaddressid=self.public_ip.ipaddress, + ipaddressid=self.public_ip.ipaddress.id, protocol='TCP', cidrlist=[self.services["fw_rule"]["cidr"]], startport=self.services["fw_rule"]["startport"], @@ -2782,8 +2779,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2927,9 +2923,7 @@ class TestSharedNetworks(cloudstackTestCase): conservemode=False ) - self.cleanup.append(self.shared_network_offering) - - #Verify that the network offering got created + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id diff --git a/test/integration/component/test_snapshots.py b/test/integration/component/test_snapshots.py index 18dcefd7672..7b480e57397 100644 --- a/test/integration/component/test_snapshots.py +++ b/test/integration/component/test_snapshots.py @@ -375,8 +375,8 @@ class TestSnapshots(cloudstackTestCase): #6. Mount/Attach volume to another server #7. Compare data - random_data_0 = random_gen(100) - random_data_1 = random_gen(100) + random_data_0 = random_gen(size=100) + random_data_1 = random_gen(size=100) volume = Volume.create( self.apiclient, @@ -644,8 +644,8 @@ class TestSnapshots(cloudstackTestCase): "Check list response returns a valid list" ) volume = volumes[0] - random_data_0 = random_gen(100) - random_data_1 = random_gen(100) + random_data_0 = random_gen(size=100) + random_data_1 = random_gen(size=100) try: ssh_client = self.virtual_machine.get_ssh_client() @@ -838,8 +838,8 @@ class TestSnapshots(cloudstackTestCase): #5. Login to newly created virtual machine #6. Compare data - random_data_0 = random_gen(100) - random_data_1 = random_gen(100) + random_data_0 = random_gen(size=100) + random_data_1 = random_gen(size=100) try: #Login to virtual machine diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py index 52df6da5554..f10641b762c 100644 --- a/test/integration/component/test_tags.py +++ b/test/integration/component/test_tags.py @@ -1083,12 +1083,12 @@ class TestResourceTags(cloudstackTestCase): 'CentOS', 'The tag should have original value' ) - isos = Iso.list( self.apiclient, - listall=True, key='OS', - value='CentOS' + value='CentOS', + account=self.account.name, + domainid=self.account.domainid ) self.assertEqual( @@ -1096,7 +1096,7 @@ class TestResourceTags(cloudstackTestCase): True, "List isos should not return an empty response" ) - + self.debug("Deleting the created tag..") try: tag.delete( @@ -1454,14 +1454,14 @@ class TestResourceTags(cloudstackTestCase): self.debug("Available hosts: ") for host in hosts: - self.debug("Host: %s", host.id) + self.debug("Host: %s" % host.id) # Filtering out the source host from list host response temp_hosts = [host for host in hosts if host.id != source_host] dest_host = temp_hosts[0] self.debug("Destination host is: %s" % dest_host.id) - self.debug("Source host is: %s" % source_host.id) + self.debug("Source host is: %s" % source_host) self.debug("Creating a tag for user VM") tag = Tag.create( diff --git a/test/integration/component/test_vpc.py b/test/integration/component/test_vpc.py index 63c10aacdb2..3a661d59b8e 100644 --- a/test/integration/component/test_vpc.py +++ b/test/integration/component/test_vpc.py @@ -143,9 +143,9 @@ class Services: # Any network (For creating FW rule) "protocol": "TCP" }, - "http_rule": { - "startport": 80, - "endport": 80, + "icmp_rule": { + "icmptype": -1, + "icmpcode": -1, "cidrlist": '0.0.0.0/0', "protocol": "ICMP" }, @@ -275,9 +275,189 @@ class TestVPC(cloudstackTestCase): ) self.debug("VPC network validated - %s" % network.name) return - + + #list_vpc_apis should be the first case otherwise the vpc counts would be wrong @attr(tags=["advanced", "intervlan"]) - def test_01_restart_vpc_no_networks(self): + def test_01_list_vpc_apis(self): + """ Test list VPC APIs + """ + + # Validate the following + # 1. Create multiple VPCs + # 2. listVPCs() by name. VPC with the provided name should be listed. + # 3. listVPCs() by displayText. VPC with the provided displayText + # should be listed. + # 4. listVPCs() by cidr. All the VPCs with the provided cidr should + # be listed. + # 5. listVPCs() by vpcofferingId.All the VPCs with the vpcofferingId + # should be listed. + # 6. listVPCs() by supported Services(). All the VPCs that provide the + # list of services should be listed. + # 7. listVPCs() by restartRequired (set to true). All the VPCs that + # require restart should be listed. + + self.services["vpc"]["cidr"] = "10.1.1.1/16" + self.debug("creating a VPC network in the account: %s" % + self.account.name) + vpc_1 = VPC.create( + self.apiclient, + self.services["vpc"], + vpcofferingid=self.vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) + self.validate_vpc_network(vpc_1) + + self.services["vpc"]["cidr"] = "10.1.46.1/16" + vpc_2 = VPC.create( + self.apiclient, + self.services["vpc"], + vpcofferingid=self.vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) + self.validate_vpc_network(vpc_2) + + self.debug("Check list VPC API by Name?") + vpcs = VPC.list( + self.apiclient, + name=vpc_1.name, + listall=True + ) + self.assertEqual( + isinstance(vpcs, list), + True, + "List VPC shall return a valid resposne" + ) + vpc = vpcs[0] + self.assertEqual( + vpc.name, + vpc_1.name, + "VPC name should match with the existing one" + ) + + self.debug("Check list VPC API by displayText?") + vpcs = VPC.list( + self.apiclient, + displaytext=vpc_1.displaytext, + listall=True + ) + self.assertEqual( + isinstance(vpcs, list), + True, + "List VPC shall return a valid resposne" + ) + vpc = vpcs[0] + self.assertEqual( + vpc.displaytext, + vpc_1.displaytext, + "VPC displaytext should match with the existing one" + ) + + self.debug("Check list VPC API by cidr?") + vpcs = VPC.list( + self.apiclient, + cidr=vpc_2.cidr, + listall=True + ) + self.assertEqual( + isinstance(vpcs, list), + True, + "List VPC shall return a valid resposne" + ) + vpc = vpcs[0] + self.assertEqual( + vpc.cidr, + vpc_2.cidr, + "VPC cidr should match with the existing one" + ) + self.debug("Validating list VPC by Id") + self.validate_vpc_network(vpc_1) + + self.debug("Validating list VPC by vpcofferingId") + vpcs = VPC.list( + self.apiclient, + vpcofferingid=self.vpc_off.id, + listall=True + ) + self.assertEqual( + isinstance(vpcs, list), + True, + "List VPC by vpcofferingId should return a valid response" + ) + self.debug("Length of list VPC response: %s" % len(vpcs)) + self.assertEqual( + len(vpcs), + 2, + "List VPC should return 2 enabled VPCs" + ) + for vpc in vpcs: + self.assertEqual( + vpc.vpcofferingid, + self.vpc_off.id, + "VPC offering ID should match with that of resposne" + ) + + self.debug("Validating list VPC by supportedservices") + vpcs = VPC.list( + self.apiclient, + supportedservices='Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', + listall=True, + account=self.account.name, + domainid=self.account.domainid + ) + self.assertEqual( + isinstance(vpcs, list), + True, + "List VPC by vpcofferingId should return a valid response" + ) + for vpc in vpcs: + self.assertIn( + vpc.id, + [vpc_1.id, vpc_2.id], + "VPC offering ID should match with that of resposne" + ) + self.debug("Validating list VPC by restart required") + vpcs = VPC.list( + self.apiclient, + restartrequired=True, + listall=True, + account=self.account.name, + domainid=self.account.domainid + ) + if vpcs is not None: + for vpc in vpcs: + self.assertEqual( + vpc.restartrequired, + True, + "RestartRequired should be set as True" + ) + self.debug("Validating list VPC by restart required") + vpcs = VPC.list( + self.apiclient, + restartrequired=False, + listall=True, + account=self.account.name, + domainid=self.account.domainid + ) + self.assertEqual( + isinstance(vpcs, list), + True, + "List VPC by vpcofferingId should return a valid response" + ) + if vpcs is not None: + for vpc in vpcs: + self.assertEqual( + vpc.restartrequired, + False, + "RestartRequired should be set as False" + ) + return + + @attr(tags=["advanced", "intervlan"]) + def test_02_restart_vpc_no_networks(self): """ Test restart VPC having no networks """ @@ -308,7 +488,7 @@ class TestVPC(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - def test_02_restart_vpc_with_networks(self): + def test_03_restart_vpc_with_networks(self): """ Test restart VPC having networks """ @@ -393,7 +573,7 @@ class TestVPC(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - def test_03_delete_vpc_no_networks(self): + def test_04_delete_vpc_no_networks(self): """ Test delete VPC having no networks """ @@ -433,7 +613,7 @@ class TestVPC(cloudstackTestCase): return @attr(tags=["advanced", "intervlan"]) - def test_04_delete_vpc_with_networks(self): + def test_05_delete_vpc_with_networks(self): """ Test delete VPC having networks """ @@ -563,185 +743,6 @@ class TestVPC(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"]) - def test_05_list_vpc_apis(self): - """ Test list VPC APIs - """ - - # Validate the following - # 1. Create multiple VPCs - # 2. listVPCs() by name. VPC with the provided name should be listed. - # 3. listVPCs() by displayText. VPC with the provided displayText - # should be listed. - # 4. listVPCs() by cidr. All the VPCs with the provided cidr should - # be listed. - # 5. listVPCs() by vpcofferingId.All the VPCs with the vpcofferingId - # should be listed. - # 6. listVPCs() by supported Services(). All the VPCs that provide the - # list of services should be listed. - # 7. listVPCs() by restartRequired (set to true). All the VPCs that - # require restart should be listed. - - self.services["vpc"]["cidr"] = "10.1.1.1/16" - self.debug("creating a VPC network in the account: %s" % - self.account.name) - vpc_1 = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=self.vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) - self.validate_vpc_network(vpc_1) - - self.services["vpc"]["cidr"] = "10.1.46.1/16" - vpc_2 = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=self.vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) - self.validate_vpc_network(vpc_2) - - self.debug("Check list VPC API by Name?") - vpcs = VPC.list( - self.apiclient, - name=vpc_1.name, - listall=True - ) - self.assertEqual( - isinstance(vpcs, list), - True, - "List VPC shall return a valid resposne" - ) - vpc = vpcs[0] - self.assertEqual( - vpc.name, - vpc_1.name, - "VPC name should match with the existing one" - ) - - self.debug("Check list VPC API by displayText?") - vpcs = VPC.list( - self.apiclient, - displaytext=vpc_1.displaytext, - listall=True - ) - self.assertEqual( - isinstance(vpcs, list), - True, - "List VPC shall return a valid resposne" - ) - vpc = vpcs[0] - self.assertEqual( - vpc.displaytext, - vpc_1.displaytext, - "VPC displaytext should match with the existing one" - ) - - self.debug("Check list VPC API by cidr?") - vpcs = VPC.list( - self.apiclient, - cidr=vpc_2.cidr, - listall=True - ) - self.assertEqual( - isinstance(vpcs, list), - True, - "List VPC shall return a valid resposne" - ) - vpc = vpcs[0] - self.assertEqual( - vpc.cidr, - vpc_2.cidr, - "VPC cidr should match with the existing one" - ) - self.debug("Validating list VPC by Id") - self.validate_vpc_network(vpc_1) - - self.debug("Validating list VPC by vpcofferingId") - vpcs = VPC.list( - self.apiclient, - vpcofferingid=self.vpc_off.id, - listall=True - ) - self.assertEqual( - isinstance(vpcs, list), - True, - "List VPC by vpcofferingId should return a valid response" - ) - self.debug("Length of list VPC response: %s" % len(vpcs)) - self.assertEqual( - len(vpcs), - 2, - "List VPC should return 3 enabled VPCs" - ) - for vpc in vpcs: - self.assertEqual( - vpc.vpcofferingid, - self.vpc_off.id, - "VPC offering ID should match with that of resposne" - ) - - self.debug("Validating list VPC by supportedservices") - vpcs = VPC.list( - self.apiclient, - supportedservices='Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', - listall=True, - account=self.account.name, - domainid=self.account.domainid - ) - self.assertEqual( - isinstance(vpcs, list), - True, - "List VPC by vpcofferingId should return a valid response" - ) - for vpc in vpcs: - self.assertIn( - vpc.id, - [vpc_1.id, vpc_2.id], - "VPC offering ID should match with that of resposne" - ) - self.debug("Validating list VPC by restart required") - vpcs = VPC.list( - self.apiclient, - restartrequired=True, - listall=True, - account=self.account.name, - domainid=self.account.domainid - ) - if vpcs is not None: - for vpc in vpcs: - self.assertEqual( - vpc.restartrequired, - True, - "RestartRequired should be set as True" - ) - self.debug("Validating list VPC by restart required") - vpcs = VPC.list( - self.apiclient, - restartrequired=False, - listall=True, - account=self.account.name, - domainid=self.account.domainid - ) - self.assertEqual( - isinstance(vpcs, list), - True, - "List VPC by vpcofferingId should return a valid response" - ) - if vpcs is not None: - for vpc in vpcs: - self.assertEqual( - vpc.restartrequired, - False, - "RestartRequired should be set as False" - ) - return - @attr(tags=["advanced", "intervlan"]) def test_06_list_vpc_apis_admin(self): """ Test list VPC APIs for different user roles @@ -1065,13 +1066,13 @@ class TestVPC(cloudstackTestCase): nwacl_internet_1 = NetworkACL.create( self.apiclient, networkid=network_1.id, - services=self.services["http_rule"], + services=self.services["icmp_rule"], traffictype='Egress' ) nwacl_internet_2 = NetworkACL.create( self.apiclient, networkid=network_2.id, - services=self.services["http_rule"], + services=self.services["icmp_rule"], traffictype='Egress' ) @@ -1410,13 +1411,13 @@ class TestVPC(cloudstackTestCase): nwacl_internet_1 = NetworkACL.create( self.apiclient, networkid=network_1.id, - services=self.services["http_rule"], + services=self.services["icmp_rule"], traffictype='Egress' ) nwacl_internet_2 = NetworkACL.create( self.apiclient, networkid=network_2.id, - services=self.services["http_rule"], + services=self.services["icmp_rule"], traffictype='Egress' ) @@ -2404,4 +2405,4 @@ class TestVPC(cloudstackTestCase): self.assertEqual(vpc_networks[0].displaytext, new_display_text, - "Updation of VPC display text failed.") \ No newline at end of file + "Updation of VPC display text failed.") diff --git a/test/integration/component/test_vpc_network.py b/test/integration/component/test_vpc_network.py index d76996ae85b..477c79e58e8 100644 --- a/test/integration/component/test_vpc_network.py +++ b/test/integration/component/test_vpc_network.py @@ -148,9 +148,9 @@ class Services: # Any network (For creating FW rule) "protocol": "TCP" }, - "http_rule": { - "startport": 80, - "endport": 80, + "icmp_rule": { + "icmptype": -1, + "icmpcode": -1, "cidrlist": '0.0.0.0/0', "protocol": "ICMP" }, @@ -690,6 +690,7 @@ class TestVPCNetwork(cloudstackTestCase): self.debug("Network creation failed") return + @unittest.skip("skipped - RvR didn't support VPC currently ") @attr(tags=["advanced", "intervlan"]) def test_06_create_network_with_rvr(self): """ Test create network with redundant router capability @@ -1823,7 +1824,7 @@ class TestVPCNetworkUpgrade(cloudstackTestCase): nwacl_internet_1 = NetworkACL.create( self.apiclient, networkid=network_1.id, - services=self.services["http_rule"], + services=self.services["icmp_rule"], traffictype='Egress' ) @@ -2212,7 +2213,7 @@ class TestVPCNetworkGc(cloudstackTestCase): cls.nwacl_internet_1 = NetworkACL.create( cls.api_client, networkid=cls.network_1.id, - services=cls.services["http_rule"], + services=cls.services["icmp_rule"], traffictype='Egress' ) cls._cleanup = [ diff --git a/test/integration/component/test_vpc_network_lbrules.py b/test/integration/component/test_vpc_network_lbrules.py index ae452c4f0f9..d3c5ce1dee1 100644 --- a/test/integration/component/test_vpc_network_lbrules.py +++ b/test/integration/component/test_vpc_network_lbrules.py @@ -42,6 +42,7 @@ from marvin.integration.lib.common import (get_domain, get_template, cleanup_resources, list_routers) +import socket class Services: """Test VPC network services Load Balancing Rules Test data @@ -179,6 +180,9 @@ class TestVPCNetworkLBRules(cloudstackTestCase): @classmethod def setUpClass(cls): + # We want to fail quicker if it's failure + socket.setdefaulttimeout(60) + cls.api_client = super( TestVPCNetworkLBRules, cls @@ -294,6 +298,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase): def start_VPC_VRouter(self, router): # Start the VPC Router + self.debug("Starting router ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) @@ -665,7 +670,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase): self.debug('lb_rule_http=%s' % lb_rule_http.__dict__) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) - lb_rule_nat.delete() + lb_rule_nat.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) return @@ -696,7 +701,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase): self.debug('lb_rule_http=%s' % lb_rule_http.__dict__) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) - lb_rule_nat.delete() + lb_rule_nat.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) return @@ -727,8 +732,8 @@ class TestVPCNetworkLBRules(cloudstackTestCase): self.debug('lb_rule_http=%s' % lb_rule_http.__dict__) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) - lb_rule_nat.delete() - lb_rule_http.delete() + lb_rule_nat.delete(self.apiclient) + lb_rule_http.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @@ -760,8 +765,8 @@ class TestVPCNetworkLBRules(cloudstackTestCase): self.debug('lb_rule_http=%s' % lb_rule_http.__dict__) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) - lb_rule_nat.delete() - lb_rule_http.delete() + lb_rule_nat.delete(self.apiclient) + lb_rule_http.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index 64a6aa23770..d9a045c4158 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -38,6 +38,7 @@ from marvin.integration.lib.common import (get_domain, get_template, cleanup_resources, list_routers) +import socket class Services: @@ -179,6 +180,9 @@ class TestVPCNetworkPFRules(cloudstackTestCase): @classmethod def setUpClass(cls): + # We want to fail quicker if it's failure + socket.setdefaulttimeout(60) + cls.api_client = super( TestVPCNetworkPFRules, cls @@ -294,6 +298,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): def start_vpcrouter(self, router): # Start the VPC Router + self.debug("Starting router ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id self.apiclient.startRouter(cmd) @@ -634,7 +639,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) router = self.stop_vpcrouter() - http_rule.delete() + http_rule.delete(self.apiclient) self.start_vpcrouter(router) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @@ -663,7 +668,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase): #http_rule = self.create_egress_Internet_Rule(network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) - http_rule.delete() + http_rule.delete(self.apiclient) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @@ -695,8 +700,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) router = self.stop_vpcrouter() - http_rule.delete() - nat_rule.delete() + http_rule.delete(self.apiclient) + nat_rule.delete(self.apiclient) self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) @@ -727,8 +732,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): #http_rule = self.create_egress_Internet_Rule(network_1) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) - http_rule.delete() - nat_rule.delete() + http_rule.delete(self.apiclient) + nat_rule.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @@ -764,34 +769,40 @@ class TestVPCNetworkPFRules(cloudstackTestCase): public_ip_2 = self.acquire_publicip(network_1) nat_rule1 = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule2 = self.create_natrule(vm_2, public_ip_2, network_1) - http_rule1 = self.open_egress_to_world(network_1) - nat_rule3 = self.create_natrule(vm_3, public_ip_1, network_2) - nat_rule4 = self.create_natrule(vm_4, public_ip_2, network_2) - http_rule2 = self.open_egress_to_world(network_2) + http_rule1 = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) + http_rule2 = self.create_natrule(vm_2, public_ip_2, network_1, self.services["http_rule"]) + public_ip_3 = self.acquire_publicip(network_2) + public_ip_4 = self.acquire_publicip(network_2) + nat_rule3 = self.create_natrule(vm_3, public_ip_3, network_2) + nat_rule4 = self.create_natrule(vm_4, public_ip_4, network_2) + http_rule3 = self.create_natrule(vm_3, public_ip_3, network_2, self.services["http_rule"]) + http_rule4 = self.create_natrule(vm_4, public_ip_4, network_2, self.services["http_rule"]) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) - self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=False) - self.check_ssh_into_vm(vm_4, public_ip_2, testnegative=False) + self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=False) + self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_2, public_ip_2, testnegative=False) - self.check_wget_from_vm(vm_3, public_ip_1, testnegative=False) - self.check_wget_from_vm(vm_4, public_ip_2, testnegative=False) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=False) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=False) router = self.stop_vpcrouter() - nat_rule1.delete() - nat_rule2.delete() - nat_rule3.delete() - nat_rule4.delete() - http_rule1.delete() - http_rule2.delete() + nat_rule1.delete(self.apiclient) + nat_rule2.delete(self.apiclient) + nat_rule3.delete(self.apiclient) + nat_rule4.delete(self.apiclient) + http_rule1.delete(self.apiclient) + http_rule2.delete(self.apiclient) + http_rule3.delete(self.apiclient) + http_rule4.delete(self.apiclient) self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) - self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=True) - self.check_ssh_into_vm(vm_4, public_ip_2, testnegative=True) + self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) + self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True) - self.check_wget_from_vm(vm_3, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_4, public_ip_2, testnegative=True) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True) return @attr(tags=["advanced", "intervlan"]) @@ -822,30 +833,36 @@ class TestVPCNetworkPFRules(cloudstackTestCase): public_ip_2 = self.acquire_publicip(network_1) nat_rule1 = self.create_natrule(vm_1, public_ip_1, network_1) nat_rule2 = self.create_natrule(vm_2, public_ip_2, network_1) - http_rule1 = self.open_egress_to_world(network_1) - nat_rule3 = self.create_natrule(vm_3, public_ip_1, network_2) - nat_rule4 = self.create_natrule(vm_4, public_ip_2, network_2) - http_rule2 = self.open_egress_to_world(network_2) + http_rule1 = self.create_natrule(vm_1, public_ip_1, network_1, self.services["http_rule"]) + http_rule2 = self.create_natrule(vm_2, public_ip_2, network_1, self.services["http_rule"]) + public_ip_3 = self.acquire_publicip(network_2) + public_ip_4 = self.acquire_publicip(network_2) + nat_rule3 = self.create_natrule(vm_3, public_ip_3, network_2) + nat_rule4 = self.create_natrule(vm_4, public_ip_4, network_2) + http_rule3 = self.create_natrule(vm_3, public_ip_3, network_2, self.services["http_rule"]) + http_rule4 = self.create_natrule(vm_4, public_ip_4, network_2, self.services["http_rule"]) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=False) - self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=False) - self.check_ssh_into_vm(vm_4, public_ip_2, testnegative=False) + self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=False) + self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_2, public_ip_2, testnegative=False) - self.check_wget_from_vm(vm_3, public_ip_1, testnegative=False) - self.check_wget_from_vm(vm_4, public_ip_2, testnegative=False) - nat_rule1.delete() - nat_rule2.delete() - nat_rule3.delete() - nat_rule4.delete() - http_rule1.delete() - http_rule2.delete() + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=False) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=False) + nat_rule1.delete(self.apiclient) + nat_rule2.delete(self.apiclient) + nat_rule3.delete(self.apiclient) + nat_rule4.delete(self.apiclient) + http_rule1.delete(self.apiclient) + http_rule2.delete(self.apiclient) + http_rule3.delete(self.apiclient) + http_rule4.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) - self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=True) - self.check_ssh_into_vm(vm_4, public_ip_2, testnegative=True) + self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) + self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True) - self.check_wget_from_vm(vm_3, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_4, public_ip_2, testnegative=True) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True) return diff --git a/test/integration/component/test_vpc_network_staticnatrule.py b/test/integration/component/test_vpc_network_staticnatrule.py index 80e8477289c..0d23d0325bc 100644 --- a/test/integration/component/test_vpc_network_staticnatrule.py +++ b/test/integration/component/test_vpc_network_staticnatrule.py @@ -38,6 +38,7 @@ from marvin.integration.lib.common import (get_domain, get_template, cleanup_resources, list_routers) +import socket class Services: @@ -178,6 +179,9 @@ class TestVPCNetworkPFRules(cloudstackTestCase): @classmethod def setUpClass(cls): + # We want to fail quicker if it's failure + socket.setdefaulttimeout(60) + cls.api_client = super( TestVPCNetworkPFRules, cls @@ -634,8 +638,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): http_rule = self.create_NatRule_For_VM(vm_1, public_ip_1, network_1, self.services["http_rule"]) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) - http_rule.delete() - nat_rule.delete() + http_rule.delete(self.apiclient) + nat_rule.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) return @@ -682,12 +686,12 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_wget_from_vm(vm_2, public_ip_2, testnegative=False) self.check_wget_from_vm(vm_3, public_ip_1, testnegative=False) self.check_wget_from_vm(vm_4, public_ip_2, testnegative=False) - nat_rule1.delete() - nat_rule2.delete() - nat_rule3.delete() - nat_rule4.delete() - http_rule1.delete() - http_rule2.delete() + nat_rule1.delete(self.apiclient) + nat_rule2.delete(self.apiclient) + nat_rule3.delete(self.apiclient) + nat_rule4.delete(self.apiclient) + http_rule1.delete(self.apiclient) + http_rule2.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_1, testnegative=True) diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py index c599d96113e..194b4061d4d 100644 --- a/test/integration/component/test_vpc_vms_deployment.py +++ b/test/integration/component/test_vpc_vms_deployment.py @@ -354,7 +354,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) # Creating network using the network offering created self.debug("Creating network with network offering: %s" % @@ -569,7 +569,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) # Creating network using the network offering created self.debug("Creating network with network offering: %s" % @@ -822,7 +822,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) # Creating network using the network offering created self.debug("Creating network with network offering: %s" % @@ -1091,7 +1091,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) # Creating network using the network offering created self.debug("Creating network with network offering: %s" % @@ -1375,7 +1375,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) configs = Configurations.list( self.apiclient, @@ -1546,7 +1546,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) # Creating network using the network offering created self.debug("Creating network with network offering: %s" % @@ -1810,7 +1810,7 @@ class TestVMDeployVPC(cloudstackTestCase): ) # Enable Network offering nw_off_no_lb.update(self.apiclient, state='Enabled') - self._cleanup.append(nw_off) + self._cleanup.append(nw_off_no_lb) # Creating network using the network offering created self.debug("Creating network with network offering: %s" % diff --git a/test/integration/smoke/test_loadbalance.py b/test/integration/smoke/test_loadbalance.py index 4e1f0c109d4..f5405da5e1f 100644 --- a/test/integration/smoke/test_loadbalance.py +++ b/test/integration/smoke/test_loadbalance.py @@ -323,11 +323,11 @@ class TestLoadBalance(cloudstackTestCase): hostnames = [] - self.try_ssh(src_nat_ip_addr, hostnames) - self.try_ssh(src_nat_ip_addr, hostnames) - self.try_ssh(src_nat_ip_addr, hostnames) - self.try_ssh(src_nat_ip_addr, hostnames) - self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) self.debug("Hostnames: %s" % str(hostnames)) self.assertIn( @@ -354,7 +354,7 @@ class TestLoadBalance(cloudstackTestCase): self.vm_2.id )) - self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) self.assertIn( self.vm_1.name, hostnames, @@ -368,7 +368,7 @@ class TestLoadBalance(cloudstackTestCase): with self.assertRaises(Exception): self.debug("Removed all VMs, trying to SSH") - self.try_ssh(src_nat_ip_addr, hostnames) + self.try_ssh(src_nat_ip_addr.ipaddress, hostnames) return @attr(tags = ["advanced", "advancedns", "smoke"]) @@ -440,11 +440,11 @@ class TestLoadBalance(cloudstackTestCase): ) try: hostnames = [] - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) self.debug("Hostnames: %s" % str(hostnames)) self.assertIn( @@ -468,7 +468,7 @@ class TestLoadBalance(cloudstackTestCase): # Making host list empty hostnames[:] = [] - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) self.assertIn( self.vm_1.name, hostnames, @@ -486,7 +486,7 @@ class TestLoadBalance(cloudstackTestCase): self.non_src_nat_ip.ipaddress.ipaddress, self.vm_1.id )) - self.try_ssh(self.non_src_nat_ip, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) return @attr(tags = ["advanced", "advancedns", "smoke"]) @@ -535,11 +535,11 @@ class TestLoadBalance(cloudstackTestCase): lb_rule.assign(self.apiclient, [self.vm_1, self.vm_2]) hostnames = [] - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) self.debug("Hostnames: %s" % str(hostnames)) self.assertIn( @@ -561,10 +561,10 @@ class TestLoadBalance(cloudstackTestCase): try: self.debug("SSHing again into IP address: %s with VM (ID: %s) added to LB rule" % ( - self.non_src_nat_ip.ipaddress, + self.non_src_nat_ip.ipaddress.ipaddress, self.vm_1.id, )) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) self.assertIn( self.vm_1.name, @@ -573,17 +573,17 @@ class TestLoadBalance(cloudstackTestCase): ) except Exception as e: self.fail("SSH failed for VM with IP: %s" % - self.non_src_nat_ip.ipaddress) + self.non_src_nat_ip.ipaddress.ipaddress) lb_rule.assign(self.apiclient, [self.vm_3]) # # Making hostnames list empty hostnames[:] = [] - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) - self.try_ssh(self.non_src_nat_ip.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) + self.try_ssh(self.non_src_nat_ip.ipaddress.ipaddress, hostnames) self.debug("Hostnames: %s" % str(hostnames)) self.assertIn( self.vm_1.name, diff --git a/test/integration/smoke/test_vm_snapshots.py b/test/integration/smoke/test_vm_snapshots.py index dd709828a60..b49a37c45b6 100644 --- a/test/integration/smoke/test_vm_snapshots.py +++ b/test/integration/smoke/test_vm_snapshots.py @@ -120,7 +120,7 @@ class TestVmSnapshot(cloudstackTestCase): serviceofferingid=cls.service_offering.id, mode=cls.services["mode"] ) - cls.random_data_0 = random_gen(100) + cls.random_data_0 = random_gen(size=100) cls._cleanup = [ cls.service_offering, cls.account, diff --git a/tools/devcloud-kvm/devcloud-kvm-advanced.cfg b/tools/devcloud-kvm/devcloud-kvm-advanced.cfg index 10cbce00779..45bdfceb0ef 100644 --- a/tools/devcloud-kvm/devcloud-kvm-advanced.cfg +++ b/tools/devcloud-kvm/devcloud-kvm-advanced.cfg @@ -103,7 +103,8 @@ "internaldns1": "8.8.4.4", "secondaryStorages": [ { - "url": "nfs://172.17.10.10:/nfs/secondary" + "url": "nfs://172.17.10.10:/nfs/secondary", + "provider": "NFS" } ] } diff --git a/tools/devcloud-kvm/devcloud-kvm.cfg b/tools/devcloud-kvm/devcloud-kvm.cfg index 9f310e32755..3122e5a9790 100644 --- a/tools/devcloud-kvm/devcloud-kvm.cfg +++ b/tools/devcloud-kvm/devcloud-kvm.cfg @@ -85,7 +85,8 @@ "internaldns1": "192.168.100.10", "secondaryStorages": [ { - "url": "nfs://192.168.100.10:/nfs/secondary" + "url": "nfs://192.168.100.10:/nfs/secondary", + "provider": "NFS" } ] } diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index 114928cdc03..742363d4ba2 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -15,22 +15,7 @@ # specific language governing permissions and limitations # under the License. -from cloudstackAPI import * import unittest -import cloudstackTestClient - -#class UserName(object): -# def __init__(self, account, domain, type=0): -# self.account = account -# self.domain = domain -# self.accounttype = type -# def __call__(self, cls): -# class Wrapped(cls): -# cls.UserName = self.account -# cls.DomainName = self.domain -# cls.AcctType = self.accounttype -# return Wrapped - def user(Name, DomainName, AcctType): def wrapper(cls): @@ -51,7 +36,6 @@ class cloudstackTestCase(unittest.case.TestCase): def __init__(self, args): unittest.case.TestCase.__init__(self, args) -# self.testClient = cloudstackTestClient.cloudstackTestClient() @classmethod def getClsTestClient(cls): diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py index ea32b90dcd1..eba53a16e20 100644 --- a/tools/marvin/marvin/cloudstackTestClient.py +++ b/tools/marvin/marvin/cloudstackTestClient.py @@ -37,8 +37,17 @@ class cloudstackTestClient(object): self.dbConnection = None self.asyncJobMgr = None self.ssh = None + self.id = None self.defaultWorkerThreads = defaultWorkerThreads + @property + def identifier(self): + return self.id + + @identifier.setter + def identifier(self, id): + self.id = id + def dbConfigure(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'): self.dbConnection = dbConnection.dbConnection(host, port, user, passwd, @@ -64,7 +73,10 @@ class cloudstackTestClient(object): def random_gen(self, size=6, chars=string.ascii_uppercase + string.digits): """Generate Random Strings of variable length""" - return ''.join(random.choice(chars) for x in range(size)) + randomstr = ''.join(random.choice(chars) for x in range(size)) + if self.identifier: + return ''.join([self.identifier, '-', randomstr]) + return randomstr def createUserApiClient(self, UserName, DomainName, acctType=0): if not self.isAdminContext(): @@ -153,6 +165,7 @@ class cloudstackTestClient(object): return self.dbConnection.executeSqlFromFile(sqlFile) def getApiClient(self): + self.apiClient.id = self.identifier return self.apiClient def getUserApiClient(self, account, domain, type=0): @@ -189,4 +202,4 @@ class cloudstackTestClient(object): if self.asyncJobMgr is None: self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, self.dbConnection) - self.asyncJobMgr.submitJobs(jobs, nums_threads, interval) + self.asyncJobMgr.submitJobs(jobs, nums_threads, interval) \ No newline at end of file diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py index 632b8c670b1..e37dbcc81b1 100644 --- a/tools/marvin/marvin/codegenerator.py +++ b/tools/marvin/marvin/codegenerator.py @@ -48,7 +48,8 @@ class codeGenerator(object): returned by API discovery or from the xml spec of commands generated by the ApiDocWriter. This class provides helper methods for these uses. """ - space = " " + space = ' ' + newline = '\n' cmdsName = [] def __init__(self, outputFolder): @@ -86,11 +87,11 @@ class codeGenerator(object): if desc is not None: self.code += self.space self.code += "''' " + pro.desc + " '''" - self.code += "\n" + self.code += self.newline self.code += self.space self.code += attr + " = " + str(value) - self.code += "\n" + self.code += self.newline def generateSubClass(self, name, properties): '''generate code for sub list''' @@ -114,7 +115,7 @@ class codeGenerator(object): self.cmd = cmd self.cmdsName.append(self.cmd.name) self.code = self.license - self.code += "\n" + self.code += self.newline self.code += '"""%s"""\n' % self.cmd.desc self.code += 'from baseCmd import *\n' self.code += 'from baseResponse import *\n' @@ -147,7 +148,7 @@ class codeGenerator(object): """generate response code""" subItems = {} - self.code += "\n" + self.code += self.newline self.code += 'class %sResponse (baseResponse):\n' % self.cmd.name self.code += self.space + "def __init__(self):\n" if len(self.cmd.response) == 0: @@ -165,7 +166,7 @@ class codeGenerator(object): else: self.code += self.space + self.space self.code += 'self.%s = None\n' % res.name - self.code += '\n' + self.code += self.newline for subclass in self.subclass: self.code += subclass + "\n" @@ -187,12 +188,33 @@ class codeGenerator(object): body += "class CloudStackAPIClient(object):\n" body += self.space + 'def __init__(self, connection):\n' body += self.space + self.space + 'self.connection = connection\n' - body += "\n" + body += self.space + self.space + 'self._id = None\n' + body += self.newline body += self.space + 'def __copy__(self):\n' body += self.space + self.space body += 'return CloudStackAPIClient(copy.copy(self.connection))\n' - body += "\n" + body += self.newline + +# The `id` property will be used to link the test with the cloud resource being created # +# @property +# def id(self): +# return self._id +# +# @id.setter +# def id(self, identifier): +# self._id = identifier + + + body += self.space + '@property' + self.newline + body += self.space + 'def id(self):' + self.newline + body += self.space*2 + 'return self._id' + self.newline + body += self.newline + + body += self.space + '@id.setter' + self.newline + body += self.space + 'def id(self, identifier):' + self.newline + body += self.space*2 + 'self._id = identifier' + self.newline + body += self.newline for cmdName in self.cmdsName: body += self.space @@ -203,7 +225,7 @@ class codeGenerator(object): body += 'response = self.connection.marvin_request(command,' body += ' response_type=response, method=method)\n' body += self.space + self.space + 'return response\n' - body += '\n' + body += self.newline imports += 'from %s import %sResponse\n' % (cmdName, cmdName) initCmdsList += '"%s",' % cmdName diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py index 13507bc8ac4..6e49ae5e70a 100755 --- a/tools/marvin/marvin/integration/lib/base.py +++ b/tools/marvin/marvin/integration/lib/base.py @@ -98,7 +98,7 @@ class Account: cmd.lastname = services["lastname"] cmd.password = services["password"] - cmd.username = "-".join([services["username"], random_gen()]) + cmd.username = "-".join([services["username"], random_gen(id=apiclient.id)]) if "accountUUID" in services: cmd.accountid = "-".join([services["accountUUID"],random_gen()]) @@ -148,10 +148,7 @@ class User: if "userUUID" in services: cmd.userid = "-".join([services["userUUID"],random_gen()]) - # Password Encoding - mdf = hashlib.md5() - mdf.update(services["password"]) - cmd.password = mdf.hexdigest() + cmd.password = services["password"] cmd.username = "-".join([services["username"], random_gen()]) user = apiclient.createUser(cmd) @@ -201,14 +198,11 @@ class User: cmd = login.loginCmd() cmd.username = username - # MD5 hashcoded password - mdf = hashlib.md5() - mdf.update(password) - cmd.password = mdf.hexdigest() + cmd.password = password if domain: cmd.domain = domain if domainid: - cmd.domainid = domainid + cmd.domainId = domainid return apiclient.login(cmd) @@ -233,12 +227,83 @@ class VirtualMachine: # extract out the ipaddress self.ipaddress = self.nic[0].ipaddress + @classmethod + def ssh_access_group(cls, apiclient, cmd): + """ + Programs the security group with SSH access before deploying virtualmachine + @return: + """ + zone_list = Zone.list( + apiclient, + id=cmd.zoneid if cmd.zoneid else None, + domainid=cmd.domainid if cmd.domainid else None + ) + zone = zone_list[0] + #check if security groups settings is enabled for the zone + if zone.securitygroupsenabled: + list_security_groups = SecurityGroup.list( + apiclient, + securitygroupname="basic_sec_grp" + ) + + if not isinstance(list_security_groups, list): + basic_mode_security_group = SecurityGroup.create( + apiclient, + {"name": "basic_sec_grp"} + ) + sec_grp_services = { + "protocol": "TCP", + "startport": 22, + "endport": 22, + "cidrlist": "0.0.0.0/0" + } + #Authorize security group for above ingress rule + basic_mode_security_group.authorize(apiclient, sec_grp_services, account=cmd.account, + domainid=cmd.domainid) + else: + basic_mode_security_group = list_security_groups[0] + + if isinstance(cmd.securitygroupids, list): + cmd.securitygroupids.append(basic_mode_security_group.id) + else: + cmd.securitygroupids = [basic_mode_security_group.id] + + @classmethod + def access_ssh_over_nat(cls, apiclient, services, virtual_machine): + """ + Program NAT and PF rules to open up ssh access to deployed guest + @return: + """ + public_ip = PublicIPAddress.create( + apiclient, + virtual_machine.account, + virtual_machine.zoneid, + virtual_machine.domainid, + services + ) + FireWallRule.create( + apiclient, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=['0.0.0.0/0'], + startport=22, + endport=22 + ) + nat_rule = NATRule.create( + apiclient, + virtual_machine, + services, + ipaddressid=public_ip.ipaddress.id + ) + virtual_machine.ssh_ip = nat_rule.ipaddress + virtual_machine.public_ip = nat_rule.ipaddress + @classmethod def create(cls, apiclient, services, templateid=None, accountid=None, domainid=None, zoneid=None, networkids=None, serviceofferingid=None, securitygroupids=None, projectid=None, startvm=None, diskofferingid=None, affinitygroupnames=None, affinitygroupids=None, group=None, - hostid=None, keypair=None, mode='basic', method='GET'): + hostid=None, keypair=None, mode='default', method='GET'): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() @@ -293,42 +358,6 @@ class VirtualMachine: if securitygroupids: cmd.securitygroupids = [str(sg_id) for sg_id in securitygroupids] - if mode.lower() == 'basic': - list_security_groups = SecurityGroup.list( - apiclient, - securitygroupname="basic_sec_grp" - ) - - if not isinstance(list_security_groups, list): - basic_mode_security_group = SecurityGroup.create( - apiclient, - {"name":"basic_sec_grp"} - ) - sec_grp_services = {"protocol": "TCP", - "startport": 22, - "endport":22, - "cidrlist": "0.0.0.0/0" - } - - #Authorize security group for above ingress rule - cmd_auth = authorizeSecurityGroupIngress.authorizeSecurityGroupIngressCmd() - cmd_auth.domainid = cmd.domainid - cmd_auth.account = cmd.account - cmd_auth.securitygroupid = basic_mode_security_group.id - cmd_auth.protocol = sec_grp_services["protocol"] - cmd_auth.startport = sec_grp_services["startport"] - cmd_auth.endport = sec_grp_services["endport"] - cmd_auth.cidrlist = sec_grp_services["cidrlist"] - apiclient.authorizeSecurityGroupIngress(cmd_auth) - - else: - basic_mode_security_group = list_security_groups[0] - - if isinstance(cmd.securitygroupids, list): - cmd.securitygroupids.append(basic_mode_security_group.id) - else: - cmd.securitygroupids = [basic_mode_security_group.id] - if "affinitygroupnames" in services: cmd.affinitygroupnames = services["affinitygroupnames"] elif affinitygroupnames: @@ -352,59 +381,23 @@ class VirtualMachine: if group: cmd.group = group + #program default access to ssh + if mode.lower() == 'basic': + cls.ssh_access_group(apiclient, cmd) + virtual_machine = apiclient.deployVirtualMachine(cmd, method=method) + virtual_machine.ssh_ip = virtual_machine.nic[0].ipaddress if startvm == False: - virtual_machine.ssh_ip = virtual_machine.nic[0].ipaddress virtual_machine.public_ip = virtual_machine.nic[0].ipaddress return VirtualMachine(virtual_machine.__dict__, services) - # VM should be in Running state after deploy - timeout = 10 - while True: - vm_status = VirtualMachine.list( - apiclient, - id=virtual_machine.id - ) - if isinstance(vm_status, list): - if vm_status[0].state == 'Running': - break - elif timeout == 0: - raise Exception( - "TimeOutException: Failed to start VM (ID: %s)" % - virtual_machine.id) - - time.sleep(10) - timeout = timeout - 1 - + #program ssh access over NAT via PF if mode.lower() == 'advanced': - public_ip = PublicIPAddress.create( - apiclient, - virtual_machine.account, - virtual_machine.zoneid, - virtual_machine.domainid, - services - ) - FireWallRule.create( - apiclient, - ipaddressid=public_ip.ipaddress.id, - protocol='TCP', - cidrlist=['0.0.0.0/0'], - startport=22, - endport=22 - ) - nat_rule = NATRule.create( - apiclient, - virtual_machine, - services, - ipaddressid=public_ip.ipaddress.id - ) - virtual_machine.ssh_ip = nat_rule.ipaddress - virtual_machine.public_ip = nat_rule.ipaddress - else: + cls.access_ssh_over_nat(apiclient, services, virtual_machine) + elif mode.lower() == 'basic': virtual_machine.ssh_ip = virtual_machine.nic[0].ipaddress virtual_machine.public_ip = virtual_machine.nic[0].ipaddress - return VirtualMachine(virtual_machine.__dict__, services) def start(self, apiclient): @@ -2100,13 +2093,16 @@ class VpnUser: cmd.projectid = projectid return VpnUser(apiclient.addVpnUser(cmd).__dict__) - def delete(self, apiclient): + def delete(self, apiclient, projectid=None): """Remove VPN user""" cmd = removeVpnUser.removeVpnUserCmd() cmd.username = self.username - cmd.account = self.account - cmd.domainid = self.domainid + if projectid: + cmd.projectid = projectid + else: + cmd.account = self.account + cmd.domainid = self.domainid apiclient.removeVpnUser(cmd) @classmethod diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index 4eca8baab20..f7f39c93006 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -95,9 +95,12 @@ def get_first_text_block(email_message_instance): return email_message_instance.get_payload() -def random_gen(size=6, chars=string.ascii_uppercase + string.digits): +def random_gen(id=None, size=6, chars=string.ascii_uppercase + string.digits): """Generate Random Strings of variable length""" - return ''.join(random.choice(chars) for x in range(size)) + randomstr = ''.join(random.choice(chars) for x in range(size)) + if id: + return ''.join([id, '-', randomstr]) + return randomstr def cleanup_resources(api_client, resources): diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py index 5014a2c921e..8a548cd63de 100644 --- a/tools/marvin/marvin/marvinPlugin.py +++ b/tools/marvin/marvin/marvinPlugin.py @@ -104,18 +104,23 @@ class MarvinPlugin(Plugin): Plugin.options(self, parser, env) def __init__(self): + self.identifier = None Plugin.__init__(self) def prepareTestRunner(self, runner): return self.testrunner def wantClass(self, cls): + if cls.__name__ == 'cloudstackTestCase': + return False if issubclass(cls, cloudstackTestCase): return True return None def loadTestsFromTestCase(self, cls): - self._injectClients(cls) + if cls.__name__ != 'cloudstackTestCase': + self.identifier = cls.__name__ + self._injectClients(cls) def setClient(self, client): if client is not None: @@ -125,19 +130,28 @@ class MarvinPlugin(Plugin): if config is not None: self.config = config + def beforeTest(self, test): + testname = test.__str__().split()[0] + self.testclient.identifier = '-'.join([self.identifier, testname]) + def _injectClients(self, test): testcaselogger = logging.getLogger("testclient.testcase.%s" % test.__name__) + + self.debug_stream. \ setFormatter(logging. Formatter("%(asctime)s - %(levelname)s - %(name)s" + " - %(message)s")) + testcaselogger.addHandler(self.debug_stream) testcaselogger.setLevel(logging.DEBUG) setattr(test, "testClient", self.testclient) setattr(test, "config", self.config) setattr(test, "debug", partial(testCaseLogger, logger=testcaselogger)) + if self.testclient.identifier is None: + self.testclient.identifier = self.identifier setattr(test, "clstestclient", self.testclient) if hasattr(test, "user"): # when the class-level attr applied. all test runs as 'user' diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css index 4545e96d100..50cfbd483ce 100644 --- a/ui/css/cloudstack3.css +++ b/ui/css/cloudstack3.css @@ -2108,6 +2108,7 @@ div.detail-group.actions td { display: block; width: 99%; border-bottom: 1px solid #AAAAAA; + float: left; } .detail-group table td.detail-actions .action.text { @@ -11820,11 +11821,13 @@ div.ui-dialog div.autoscaler div.field-group div.form-container form div.form-it background-position: -169px -583px; } -.stop .icon { +.stop .icon, +.removeVmwareDc .icon { background-position: 0px -31px; } -.stop:hover .icon { +.stop:hover .icon, +.removeVmwareDc:hover .icon { background-position: 0px -613px; } @@ -12055,11 +12058,13 @@ div.ui-dialog div.autoscaler div.field-group div.form-container form div.form-it background-position: -100px -614px; } -.addVlanRange .icon { +.addVlanRange .icon, +.addVmwareDc .icon { background-position: -37px -62px; } -.addVlanRange:hover .icon { +.addVlanRange:hover .icon, +.addVmwareDc:hover .icon { background-position: -37px -62px; } diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index d30ace89458..b2aa56b05ff 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -1341,6 +1341,7 @@ array1.push("&interval=" + args.data.interval); array1.push("&scaleuppolicyids=" + args.scaleUpPolicyResponse.id); array1.push("&scaledownpolicyids=" + args.scaleDownPolicyResponse.id); + $.ajax({ url: createURL('createAutoScaleVmGroup' + array1.join("")), dataType: 'json', @@ -1414,8 +1415,35 @@ } }; - //*** API calls start!!! ******** - scaleUp(args); + // Get hypervisor; + // if VMware, show notification to user about additional configuration required + $.ajax({ + url: createURL('listTemplates'), + data: { + id: args.data.templateNames, + templatefilter: 'all' + }, + async: false, + success: function(json) { + var template = json.listtemplatesresponse.template; + + if (template && template[0].hypervisor === 'VMware') { + cloudStack.dialog.confirm({ + message: 'For VMware-based VMs, please read the dynamic scaling section in the admin guide before scaling. Would you like to continue?,', + action: function() { + //*** API calls start!!! ******** + scaleUp(args); + }, + cancelAction: function() { + $('.loading-overlay').remove(); + } + }); + } else { + //*** API calls start!!! ******** + scaleUp(args); + } + } + }); }, destroy: function(args) { diff --git a/ui/scripts/instances.js b/ui/scripts/instances.js index c53223c3f68..12adfbb66c3 100644 --- a/ui/scripts/instances.js +++ b/ui/scripts/instances.js @@ -1831,10 +1831,10 @@ cpuused: jsonObj.cpuused, networkkbsread: (jsonObj.networkkbsread == null) ? "N/A" : cloudStack.converters.convertBytes(jsonObj.networkkbsread * 1024), networkkbswrite: (jsonObj.networkkbswrite == null) ? "N/A" : cloudStack.converters.convertBytes(jsonObj.networkkbswrite * 1024), - diskkbsread: (jsonObj.diskkbsread == null) ? "N/A" : cloudStack.converters.convertBytes(jsonObj.diskkbsread * 1024), - diskkbswrite: (jsonObj.diskkbswrite == null) ? "N/A" : cloudStack.converters.convertBytes(jsonObj.diskkbswrite * 1024), - diskioread: (jsonObj.diskioread == null) ? "N/A" : jsonObj.diskioread, - diskiowrite: (jsonObj.diskiowrite == null) ? "N/A" : jsonObj.diskiowrite + diskkbsread: (jsonObj.diskkbsread == null) ? "N/A" : ((jsonObj.hypervisor == "KVM") ? cloudStack.converters.convertBytes(jsonObj.diskkbsread * 1024) : ((jsonObj.hypervisor == "XenServer") ? cloudStack.converters.convertBytes(jsonObj.diskkbsread * 1024) + "/s" : "N/A")), + diskkbswrite: (jsonObj.diskkbswrite == null) ? "N/A" : ((jsonObj.hypervisor == "KVM") ? cloudStack.converters.convertBytes(jsonObj.diskkbswrite * 1024) : ((jsonObj.hypervisor == "XenServer") ? cloudStack.converters.convertBytes(jsonObj.diskkbswrite * 1024) + "/s" : "N/A")), + diskioread: (jsonObj.diskioread == null) ? "N/A" : ((jsonObj.hypervisor == "KVM") ? jsonObj.diskioread : "N/A"), + diskiowrite: (jsonObj.diskiowrite == null) ? "N/A" : ((jsonObj.hypervisor == "KVM") ? jsonObj.diskiowrite : "N/A") } }); } diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index 348ba7b79e4..5e1c225891d 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -1075,6 +1075,10 @@ isFeatured: { label: "label.featured", isBoolean: true + }, + isdynamicallyscalable: { + label: "Dynamically Scalable", + isBoolean: true } } }, @@ -1085,7 +1089,9 @@ displayText: args.data.displayText, osTypeId: args.data.osTypeId, isPublic: (args.data.isPublic == "on"), - passwordEnabled: (args.data.isPasswordEnabled == "on") + passwordEnabled: (args.data.isPasswordEnabled == "on"), + isdynamicallyscalable: (args.data.isdynamicallyscalable == "on") + }; if (args.$form.find('.form-item[rel=isFeatured]').css("display") != "none") { @@ -1660,6 +1666,10 @@ isPasswordEnabled: { label: 'label.password.enabled', isBoolean: true + }, + isdynamicallyscalable: { + label: "Dynamically Scalable", + isBoolean: true } } }, @@ -1670,7 +1680,8 @@ displayText: args.data.displayText, osTypeId: args.data.osTypeId, isPublic: (args.data.isPublic == "on"), - passwordEnabled: (args.data.isPasswordEnabled == "on") + passwordEnabled: (args.data.isPasswordEnabled == "on"), + isdynamicallyscalable: (args.data.isdynamicallyscalable == "on") }; $.ajax({ diff --git a/ui/scripts/system.js b/ui/scripts/system.js index c2fca60b000..e3392303bd7 100644 --- a/ui/scripts/system.js +++ b/ui/scripts/system.js @@ -6473,7 +6473,7 @@ }); $.ajax({ - url: createURL('listVmwareDcs'), + url: createURL('listVmwareDcs'), //listVmwareDcs API exists in only non-oss bild data: { zoneid: args.context.physicalResources[0].id }, @@ -6485,15 +6485,21 @@ selectedZoneObj.vmwaredcVcenter = vmwaredcs[0].vcenter; selectedZoneObj.vmwaredcId = vmwaredcs[0].id; } + }, + error: function(XMLHttpResponse) { //override default error handling: cloudStack.dialog.notice({ message: parseXMLHttpResponse(XMLHttpResponse)}); + if(parseXMLHttpResponse(XMLHttpResponse) == 'The given command does not exist or it is not available for user') + return; //do nothing + else + cloudStack.dialog.notice({ message: parseXMLHttpResponse(XMLHttpResponse)}); //pop up error dialog box if the error is not 'The given command does not exist or it is not available for user' } }); // for testing only (begin) /* - selectedZoneObj.vmwaredcName = "datacenter"; - selectedZoneObj.vmwaredcVcenter = "10.10.20.20"; - selectedZoneObj.vmwaredcId = "c3c2562d-65e9-4fc7-92e2-773c2efe8f37"; - */ + selectedZoneObj.vmwaredcName = "datacenter"; + selectedZoneObj.vmwaredcVcenter = "10.10.20.20"; + selectedZoneObj.vmwaredcId = "c3c2562d-65e9-4fc7-92e2-773c2efe8f37"; + */ // for testing only (end) args.response.success({ @@ -7414,34 +7420,29 @@ listAll: true }, success: function(json) { - var items = json.listsystemvmsresponse.systemvm; - if (items != null) { + var systemvmObjs = json.listsystemvmsresponse.systemvm; + if (systemvmObjs != null) { $.ajax({ - url: createURL("listHosts&listAll=true"), - async: false, + url: createURL("listHosts&listAll=true"), success: function(json) { - - var hostObj = json.listhostsresponse.host; - - $(hostObj).each(function(index) { - - $.extend(items[index], { - agentstate: hostObj[index].state - }); - - }); + var hostObjs = json.listhostsresponse.host; + for (var i = 0; i < systemvmObjs.length; i++) { + for (var k = 0; k < hostObjs.length; k++) { + if (hostObjs[k].name == systemvmObjs[i].name) { + systemvmObjs[i].agentstate = hostObjs[k].state; + break; + } + } + } args.response.success({ - data: items + data: systemvmObjs }); }, error: function(json) { args.response.error(parseXMLHttpResponse(json)); - } }); } - - // args.response.success({ data: json.listsystemvmsresponse.systemvm }); }, error: function(json) { args.response.error(parseXMLHttpResponse(json)); @@ -10120,7 +10121,9 @@ jobId: jid }, notification: { - poll: pollAsyncJobResult + poll: pollAsyncJobResult, + interval: 4500, + desc: "Dedicate Pod" }, data: item @@ -10135,12 +10138,10 @@ }); } - } else { - args.response.success({ - data: item - }); } - + args.response.success({ + data: item + }); }, error: function(XMLHttpResponse) { var errorMsg = parseXMLHttpResponse(XMLHttpResponse); @@ -11220,7 +11221,9 @@ jobId: jid }, notification: { - poll: pollAsyncJobResult + poll: pollAsyncJobResult, + interval: 4500, + desc: "Dedicate Cluster" }, data: $.extend(item, { @@ -11234,11 +11237,10 @@ } }); } - } else { - args.response.success({ - data: item - }); } + args.response.success({ + data: item + }); }, error: function(XMLHttpResponse) { var errorMsg = parseXMLHttpResponse(XMLHttpResponse); @@ -11293,21 +11295,12 @@ action: function(args) { var array1 = []; - if (args.data.cpuovercommitratio != "" && args.data.cpuovercommitratio > 0) - array1.push("&cpuovercommitratio=" + args.data.cpuovercommitratio); - - if (args.data.memoryovercommitratio != "" && args.data.memoryovercommitratio > 0) - array1.push("&memoryovercommitratio=" + args.data.memoryovercommitratio); - $.ajax({ - url: createURL("updateCluster&id=" + args.context.clusters[0].id + array1.join("")), dataType: "json", async: true, success: function(json) { var item = json.updateclusterresponse.cluster; - args.context.clusters[0].cpuovercommitratio = item.cpuovercommitratio; - args.context.clusters[0].memoryovercommitratio = item.memoryovercommitratio; addExtraPropertiesToClusterObject(item); args.response.success({ actionFilter: clusterActionfilter, @@ -12452,7 +12445,9 @@ jobId: jid }, notification: { - poll: pollAsyncJobResult + poll: pollAsyncJobResult, + interval: 4500, + desc: "Dedicate Host" }, data: item @@ -12466,12 +12461,10 @@ } }); } - } else { - args.response.success({ - data: item - }); } - + args.response.success({ + data: item + }); }, error: function(XMLHttpResponse) { @@ -14121,30 +14114,33 @@ label: 'label.url' } }, - dataProvider: function(args) { - /* - $.ajax({ - url: createURL('listUcsManager'), - data: { - zoneid: args.context.physicalResources[0].id - }, - success: function(json) { - - } - }); - */ - - args.response.success({ - data: [{ - id: '11', - name: 'UCS Manager 1', - url: '10.196.72.1' - }, { - id: '11', - name: 'UCS Manager 2', - url: '10.196.72.2' - }] - }); + dataProvider: function(args) { + $.ajax({ + url: createURL('listUcsManager'), + data: { + zoneid: args.context.physicalResources[0].id + }, + success: function(json) { + /* + json = //override json (for testing only) + { + "listucsmanagerreponse": { + "count": 1, + "ucsmanager": [ + { + "id": "07b5b813-83ed-4859-952c-c95cafb63ac4", + "name": "ucsmanager", + "url": "10.223.184.2", + "zoneid": "54c9a65c-ba89-4380-96e9-1d429c5372e3" + } + ] + } + }; + */ + var items = json.listucsmanagerreponse.ucsmanager; + args.response.success({ data: items }); + } + }); }, actions: { add: { @@ -14355,7 +14351,17 @@ bladeid: args.context.blades[0].id }, success: function(json) { - //json.associateucsprofiletobladeresponse.ucsblade + /* + { + "associateucsprofiletobladeresponse": { + "ucsblade": { + "id": "8f63030a-033c-458e-890f-b2c8863d9542", + "ucsmanagerid": "9d8566c0-f870-4e89-9864-7a3e0b332558", + "bladedn": "sys/chassis-1/blade-2" + } + } + } + */ args.response.success({ data: { associatedProfileDn: args.data.profiledn @@ -16299,12 +16305,12 @@ if (jsonObj.state == "Enabled") { //managed, allocation enabled allowedActions.push("unmanage"); allowedActions.push("disable"); - allowedActions.push("edit"); + //allowedActions.push("edit"); // No fields to edit } else if (jsonObj.state == "Disabled") { //managed, allocation disabled allowedActions.push("unmanage"); allowedActions.push("enable"); - allowedActions.push("edit"); + //allowedActions.push("edit"); // No fields to edit } else { //Unmanaged, PrepareUnmanaged , PrepareUnmanagedError allowedActions.push("manage"); diff --git a/ui/scripts/ui-custom/installWizard.js b/ui/scripts/ui-custom/installWizard.js index 99db57e0cd2..f7ed074e774 100644 --- a/ui/scripts/ui-custom/installWizard.js +++ b/ui/scripts/ui-custom/installWizard.js @@ -763,6 +763,16 @@ required: true } }, + provider: { + label: 'label.provider', + select: function(args) { + args.response.success({ + data: [ + { id: 'NFS', description: 'NFS' } + ] + }); + } + }, path: { label: 'label.path', validation: { diff --git a/ui/scripts/ui/widgets/listView.js b/ui/scripts/ui/widgets/listView.js index 4fd0b7ff3f1..a2d9063e5b7 100644 --- a/ui/scripts/ui/widgets/listView.js +++ b/ui/scripts/ui/widgets/listView.js @@ -185,6 +185,8 @@ return false; }); + if(args.notification) notification = args.notification; + notification._custom = args._custom; if (additional && additional.success) additional.success(args); @@ -250,25 +252,27 @@ // Error - function(args) { + function(errorArgs) { if (!isHeader) { if ($instanceRow.data('list-view-new-item')) { // For create forms $instanceRow.remove(); } else { // For standard actions - replaceItem( - $instanceRow, - $.extend($instanceRow.data('json-obj'), args.data), - args.actionFilter ? - args.actionFilter : - $instanceRow.data('list-view-action-filter') - ); + if(!args.notification) { + replaceItem( + $instanceRow, + $.extend($instanceRow.data('json-obj'), errorArgs.data), + errorArgs.actionFilter ? + errorArgs.actionFilter : + $instanceRow.data('list-view-action-filter') + ); + } } } if (options.error) { - options.error(args); + options.error(errorArgs); } } ); diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java index db32dd42869..21c7220259e 100644 --- a/utils/src/com/cloud/utils/StringUtils.java +++ b/utils/src/com/cloud/utils/StringUtils.java @@ -91,10 +91,10 @@ public class StringUtils { tags += ","; } } - } + } return tags; - } + } public static String getExceptionStackInfo(Throwable e) { StringBuffer sb = new StringBuffer(); @@ -131,22 +131,24 @@ public class StringUtils { } public static String getMaskedPasswordForDisplay(String password) { - if(password == null || password.isEmpty()) + if(password == null || password.isEmpty()) { return "*"; + } StringBuffer sb = new StringBuffer(); sb.append(password.charAt(0)); - for(int i = 1; i < password.length(); i++) + for(int i = 1; i < password.length(); i++) { sb.append("*"); + } return sb.toString(); } // removes a password request param and it's value - private static final Pattern REGEX_PASSWORD_QUERYSTRING = Pattern.compile("&?password=.*?(?=[&'\"])"); + private static final Pattern REGEX_PASSWORD_QUERYSTRING = Pattern.compile("&?(password|accesskey|secretkey)=.*?(?=[&'\"])"); - // removes a password property from a response json object - private static final Pattern REGEX_PASSWORD_JSON = Pattern.compile("\"password\":\".*?\",?"); + // removes a password/accesskey/ property from a response json object + private static final Pattern REGEX_PASSWORD_JSON = Pattern.compile("\"(password|accesskey|secretkey)\":\".*?\",?"); // Responsible for stripping sensitive content from request and response strings public static String cleanString(String stringToClean){ diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java index 796efbaacd7..ae37c24f991 100644 --- a/utils/test/com/cloud/utils/StringUtilsTest.java +++ b/utils/test/com/cloud/utils/StringUtilsTest.java @@ -24,7 +24,7 @@ public class StringUtilsTest { @Test public void testCleanPasswordFromJsonObjectAtEnd() { String input = "{\"foo\":\"bar\",\"password\":\"test\"}"; - //TODO: It would be nice to clean up the regex in question to not + //TODO: It would be nice to clean up the regex in question to not //have to return the trailing comma in the expected string below String expected = "{\"foo\":\"bar\",}"; String result = StringUtils.cleanString(input); @@ -78,7 +78,7 @@ public class StringUtilsTest { String result = StringUtils.cleanString(input); assertEquals(result, expected); } - + @Test public void testCleanPasswordFromRequestStringMatchedAtEndSingleQuote() { String input = "'username=foo&password=bar'"; @@ -108,4 +108,104 @@ public class StringUtilsTest { assertEquals("a-b-c", StringUtils.join("-", "a", "b", "c")); assertEquals("", StringUtils.join("-")); } + + @Test + public void testCleanSecretkeyFromJsonObjectAtEnd() { + String input = "{\"foo\":\"bar\",\"secretkey\":\"test\"}"; + // TODO: It would be nice to clean up the regex in question to not + // have to return the trailing comma in the expected string below + String expected = "{\"foo\":\"bar\",}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanSecretkeyFromJsonObjectInMiddle() { + String input = "{\"foo\":\"bar\",\"secretkey\":\"test\",\"test\":\"blah\"}"; + String expected = "{\"foo\":\"bar\",\"test\":\"blah\"}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanSecretkeyFromJsonObjectAlone() { + String input = "{\"secretkey\":\"test\"}"; + String expected = "{}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanSecretkeyFromJsonObjectAtStart() { + String input = "{\"secretkey\":\"test\",\"test\":\"blah\"}"; + String expected = "{\"test\":\"blah\"}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanSecretkeyFromJsonObjectWithMultiplePasswords() { + String input = "{\"description\":\"foo\"}],\"secretkey\":\"bar\",\"nic\":[{\"secretkey\":\"bar2\",\"id\":\"1\"}]}"; + String expected = "{\"description\":\"foo\"}],\"nic\":[{\"id\":\"1\"}]}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanAccesskeyFromJsonObjectAtEnd() { + String input = "{\"foo\":\"bar\",\"accesskey\":\"test\"}"; + // TODO: It would be nice to clean up the regex in question to not + // have to return the trailing comma in the expected string below + String expected = "{\"foo\":\"bar\",}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanAccesskeyFromJsonObjectInMiddle() { + String input = "{\"foo\":\"bar\",\"accesskey\":\"test\",\"test\":\"blah\"}"; + String expected = "{\"foo\":\"bar\",\"test\":\"blah\"}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanAccesskeyFromJsonObjectAlone() { + String input = "{\"accesskey\":\"test\"}"; + String expected = "{}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanAccesskeyFromJsonObjectAtStart() { + String input = "{\"accesskey\":\"test\",\"test\":\"blah\"}"; + String expected = "{\"test\":\"blah\"}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanAccesskeyFromJsonObjectWithMultiplePasswords() { + String input = "{\"description\":\"foo\"}],\"accesskey\":\"bar\",\"nic\":[{\"accesskey\":\"bar2\",\"id\":\"1\"}]}"; + String expected = "{\"description\":\"foo\"}],\"nic\":[{\"id\":\"1\"}]}"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanAccesskeyFromRequestString() { + String input = "username=foo&accesskey=bar&url=foobar"; + String expected = "username=foo&url=foobar"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } + + @Test + public void testCleanSecretkeyFromRequestString() { + String input = "username=foo&secretkey=bar&url=foobar"; + String expected = "username=foo&url=foobar"; + String result = StringUtils.cleanString(input); + assertEquals(result, expected); + } }