diff --git a/agent/conf/agent.properties b/agent/conf/agent.properties index 27572b53653..74cfd1c21d6 100644 --- a/agent/conf/agent.properties +++ b/agent/conf/agent.properties @@ -69,3 +69,14 @@ domr.scripts.dir=scripts/network/domr/kvm # set the vm migrate speed, by default, it will try to guess the speed of the guest network # In MegaBytes per second #vm.migrate.speed=0 + +# set the type of bridge used on the hypervisor, this defines what commands the resource +# will use to setup networking. Currently supported NATIVE, OPENVSWITCH +#network.bridge.type=native + +# set the driver used to plug and unplug nics from the bridges +# a sensible default will be selected based on the network.bridge.type but can +# be overridden here. +# native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver +# openvswitch = com.cloud.hypervisor.kvm.resource.OvsBridgeDriver +#libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.BridgeVifDriver \ No newline at end of file diff --git a/api/src/com/cloud/dao/EntityManager.java b/api/src/com/cloud/dao/EntityManager.java index 4e4b9c293b5..b8fdaa7e9a7 100644 --- a/api/src/com/cloud/dao/EntityManager.java +++ b/api/src/com/cloud/dao/EntityManager.java @@ -47,6 +47,15 @@ public interface EntityManager { */ public T findByUuid(Class entityType, String uuid); + /** + * Finds a unique entity by uuid string + * @param entity class + * @param entityType type of entity you're looking for. + * @param uuid the unique id + * @return T if found, null if not. + */ + public T findByUuidIncludingRemoved(Class entityType, String uuid); + /** * Finds an entity by external id which is always String * @param entity class diff --git a/api/src/com/cloud/exception/RequestLimitException.java b/api/src/com/cloud/exception/RequestLimitException.java new file mode 100644 index 00000000000..0142f8e8726 --- /dev/null +++ b/api/src/com/cloud/exception/RequestLimitException.java @@ -0,0 +1,43 @@ +// 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.exception; + +import com.cloud.utils.SerialVersionUID; +import com.cloud.utils.exception.CloudRuntimeException; + +/** + * Exception thrown if number of requests is over api rate limit set. + * @author minc + * + */ +public class RequestLimitException extends CloudRuntimeException { + + private static final long serialVersionUID = SerialVersionUID.AccountLimitException; + + protected RequestLimitException() { + super(); + } + + public RequestLimitException(String msg) { + super(msg); + } + + public RequestLimitException(String msg, Throwable cause) { + super(msg, cause); + } + +} diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java index 9dece01d86e..1e77cc8a4e2 100755 --- a/api/src/com/cloud/resource/ResourceService.java +++ b/api/src/com/cloud/resource/ResourceService.java @@ -40,6 +40,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.org.Cluster; import com.cloud.storage.S3; import com.cloud.storage.Swift; +import com.cloud.utils.Pair; import com.cloud.utils.fsm.NoTransitionException; public interface ResourceService { @@ -102,7 +103,7 @@ public interface ResourceService { List getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId); - List listSwifts(ListSwiftsCmd cmd); + Pair, Integer> listSwifts(ListSwiftsCmd cmd); List listS3s(ListS3sCmd cmd); diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index a169f3fd168..1736da3778c 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -91,16 +91,6 @@ import com.cloud.vm.VirtualMachine.Type; public interface ManagementService { static final String Name = "management-server"; - /** - * Retrieves the list of data centers with search criteria. Currently the only search criteria is "available" zones - * for the - * account that invokes the API. By specifying available=true all zones which the account can access. By specifying - * available=false the zones where the account has virtual machine instances will be returned. - * - * @return a list of DataCenters - */ - List listDataCenters(ListZonesByCmd cmd); - /** * returns the a map of the names/values in the configuraton table * @@ -108,13 +98,6 @@ public interface ManagementService { */ Pair, Integer> searchForConfigurations(ListCfgsByCmd c); - /** - * Searches for Service Offerings by the specified search criteria Can search by: "name" - * - * @param cmd - * @return List of ServiceOfferings - */ - List searchForServiceOfferings(ListServiceOfferingsCmd cmd); /** * Searches for Clusters by the specified search criteria @@ -241,15 +224,6 @@ public interface ManagementService { */ Set> listTemplates(ListTemplatesCmd cmd); - /** - * Search for disk offerings based on search criteria - * - * @param cmd - * the command containing the criteria to use for searching for disk offerings - * @return a list of disk offerings that match the given criteria - */ - List searchForDiskOfferings(ListDiskOfferingsCmd cmd); - /** * List system VMs by the given search criteria diff --git a/api/src/com/cloud/storage/snapshot/SnapshotService.java b/api/src/com/cloud/storage/snapshot/SnapshotService.java index fd2e9442a38..b5325f52080 100644 --- a/api/src/com/cloud/storage/snapshot/SnapshotService.java +++ b/api/src/com/cloud/storage/snapshot/SnapshotService.java @@ -83,7 +83,7 @@ public interface SnapshotService { * the command that specifies the volume criteria * @return list of snapshot policies */ - List listPoliciesforVolume(ListSnapshotPoliciesCmd cmd); + Pair, Integer> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd); boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd); diff --git a/api/src/org/apache/cloudstack/acl/APIChecker.java b/api/src/org/apache/cloudstack/acl/APIChecker.java index 0d0dfd1be4e..2e2b73ba782 100644 --- a/api/src/org/apache/cloudstack/acl/APIChecker.java +++ b/api/src/org/apache/cloudstack/acl/APIChecker.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.acl; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.RequestLimitException; import com.cloud.user.User; import com.cloud.utils.component.Adapter; @@ -26,5 +27,5 @@ public interface APIChecker extends Adapter { // If true, apiChecker has checked the operation // If false, apiChecker is unable to handle the operation or not implemented // On exception, checkAccess failed don't allow - boolean checkAccess(User user, String apiCommandName) throws PermissionDeniedException; + boolean checkAccess(User user, String apiCommandName) throws PermissionDeniedException, RequestLimitException; } diff --git a/api/src/org/apache/cloudstack/acl/APILimitChecker.java b/api/src/org/apache/cloudstack/acl/APILimitChecker.java new file mode 100644 index 00000000000..110742c059d --- /dev/null +++ b/api/src/org/apache/cloudstack/acl/APILimitChecker.java @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.acl; + +import org.apache.cloudstack.api.ServerApiException; + +import com.cloud.user.Account; +import com.cloud.utils.component.Adapter; + +/** + * APILimitChecker checks if we should block an API request based on pre-set account based api limit. + */ +public interface APILimitChecker extends Adapter { + // Interface for checking if the account is over its api limit + void checkLimit(Account account) throws ServerApiException; +} diff --git a/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java b/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java index 038da63ec4c..0586117f0c6 100644 --- a/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseListAccountResourcesCmd.java @@ -18,7 +18,7 @@ package org.apache.cloudstack.api; public abstract class BaseListAccountResourcesCmd extends BaseListDomainResourcesCmd { - @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "List resources by account. Must be used with the domainId parameter.") + @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "list resources by account. Must be used with the domainId parameter.") private String accountName; public String getAccountName() { diff --git a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index 2309053bea0..07de5a2401a 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -29,8 +29,9 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.NetworkOfferingResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; + import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; @@ -73,7 +74,7 @@ public class CreateNetworkOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, description="true if the network offering is IP conserve mode enabled") private Boolean conserveMode; - @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=DiskOfferingResponse.class, + @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.UUID, entityType=ServiceOfferingResponse.class, description="the service offering ID used by virtual router provider") private Long serviceOfferingId; diff --git a/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java index e9c6f9b7c39..7cfe6e1ab7f 100644 --- a/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java @@ -30,6 +30,7 @@ import org.apache.log4j.Logger; import com.cloud.storage.Swift; import com.cloud.user.Account; +import com.cloud.utils.Pair; @APICommand(name = "listSwifts", description = "List Swift.", responseObject = HostResponse.class, since="3.0.0") public class ListSwiftsCmd extends BaseListCmd { @@ -64,20 +65,19 @@ public class ListSwiftsCmd extends BaseListCmd { @Override public void execute(){ - List result = _resourceService.listSwifts(this); + Pair, Integer> result = _resourceService.listSwifts(this); ListResponse response = new ListResponse(); List swiftResponses = new ArrayList(); if (result != null) { - SwiftResponse swiftResponse = null; - for (Swift swift : result) { - swiftResponse = _responseGenerator.createSwiftResponse(swift); + for (Swift swift : result.first()) { + SwiftResponse swiftResponse = _responseGenerator.createSwiftResponse(swift); swiftResponse.setResponseName(getCommandName()); swiftResponse.setObjectName("swift"); swiftResponses.add(swiftResponse); } } - response.setResponses(swiftResponses); + response.setResponses(swiftResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java index 5c418ffe19f..933ee8bde53 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java @@ -46,7 +46,7 @@ public class AttachIsoCmd extends BaseAsyncCmd { required=true, description="the ID of the ISO file") private Long id; - @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = TemplateResponse.class, + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class, required=true, description="the ID of the virtual machine") private Long virtualMachineId; diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java index dc8f8d2e2c7..c04fba50295 100644 --- a/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java @@ -41,7 +41,7 @@ public class DetachIsoCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = TemplateResponse.class, + @Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.UUID, entityType = UserVmResponse.class, required=true, description="The ID of the virtual machine") private Long virtualMachineId; diff --git a/api/src/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java b/api/src/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java index dc435a55f11..eb48d814290 100644 --- a/api/src/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java @@ -23,6 +23,7 @@ import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.AsyncJobResponse; import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; @@ -78,16 +79,8 @@ public class ListDiskOfferingsCmd extends BaseListCmd { @Override public void execute(){ - List result = _mgr.searchForDiskOfferings(this); - ListResponse response = new ListResponse(); - List diskOfferingResponses = new ArrayList(); - for (DiskOffering offering : result) { - DiskOfferingResponse diskOffResp = _responseGenerator.createDiskOfferingResponse(offering); - diskOffResp.setObjectName("diskoffering"); - diskOfferingResponses.add(diskOffResp); - } - response.setResponses(diskOfferingResponses); + ListResponse response = _queryService.searchForDiskOfferings(this); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java b/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java index 6a4cf89c176..ca16cdc7efe 100644 --- a/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java @@ -16,9 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import java.util.ArrayList; -import java.util.List; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; @@ -27,9 +24,8 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; -import com.cloud.offering.ServiceOffering; +import org.apache.log4j.Logger; @APICommand(name = "listServiceOfferings", description="Lists all available service offerings.", responseObject=ServiceOfferingResponse.class) public class ListServiceOfferingsCmd extends BaseListCmd { @@ -102,17 +98,10 @@ public class ListServiceOfferingsCmd extends BaseListCmd { @Override public void execute(){ - List offerings = _mgr.searchForServiceOfferings(this); - ListResponse response = new ListResponse(); - List offeringResponses = new ArrayList(); - for (ServiceOffering offering : offerings) { - ServiceOfferingResponse offeringResponse = _responseGenerator.createServiceOfferingResponse(offering); - offeringResponse.setObjectName("serviceoffering"); - offeringResponses.add(offeringResponse); - } - response.setResponses(offeringResponses); + ListResponse response = _queryService.searchForServiceOfferings(this); response.setResponseName(getCommandName()); this.setResponseObject(response); + } } diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java index b568a765b2a..f1c60105961 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java @@ -29,6 +29,7 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.log4j.Logger; import com.cloud.storage.snapshot.SnapshotPolicy; +import com.cloud.utils.Pair; @APICommand(name = "listSnapshotPolicies", description="Lists snapshot policies.", responseObject=SnapshotPolicyResponse.class) public class ListSnapshotPoliciesCmd extends BaseListCmd { @@ -63,15 +64,15 @@ public class ListSnapshotPoliciesCmd extends BaseListCmd { @Override public void execute(){ - List result = _snapshotService.listPoliciesforVolume(this); + Pair, Integer> result = _snapshotService.listPoliciesforVolume(this); ListResponse response = new ListResponse(); List policyResponses = new ArrayList(); - for (SnapshotPolicy policy : result) { + for (SnapshotPolicy policy : result.first()) { SnapshotPolicyResponse policyResponse = _responseGenerator.createSnapshotPolicyResponse(policy); policyResponse.setObjectName("snapshotpolicy"); policyResponses.add(policyResponse); } - response.setResponses(policyResponses); + response.setResponses(policyResponses, result.second()); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java index f38ee700e4d..a4f05821244 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java @@ -50,7 +50,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd { required=true, description="ID of the zone the template is being copied to.") private Long destZoneId; - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class, + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class, required=true, description="Template ID.") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java index 33634439f38..1f030a56591 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java @@ -23,8 +23,9 @@ import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; + import org.apache.log4j.Logger; import com.cloud.async.AsyncJob; @@ -42,7 +43,7 @@ public class DeleteTemplateCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class, + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class, required=true, description="the ID of the template") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java index e84aa9a1506..9a2dee30bcb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java @@ -23,8 +23,9 @@ import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ExtractResponse; -import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; + import org.apache.log4j.Logger; import com.cloud.async.AsyncJob; @@ -44,7 +45,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd { //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = UserVmResponse.class, + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = TemplateResponse.class, required=true, description="the ID of the template") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java index 79c7efadb2e..b6bc68f9f4e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java @@ -64,15 +64,6 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{ , description="list by ID of the VPC offering") private Long VpcOffId; - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " + - "Must be used with the domainId parameter.") - private String accountName; - - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class, - description="list by domain ID associated with the VPC. " + - "If used with the account parameter returns the VPC associated with the account for the specified domain.") - private Long domainId; - @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING, description="list VPC supporting certain services") private List supportedServices; @@ -87,14 +78,6 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{ /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - public Long getZoneId() { return zoneId; } diff --git a/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java b/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java index df5e2acdbfc..97fe2ffeb90 100644 --- a/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; @@ -86,16 +87,8 @@ public class ListZonesByCmd extends BaseListCmd { @Override public void execute(){ - List dataCenters = _mgr.listDataCenters(this); - ListResponse response = new ListResponse(); - List zoneResponses = new ArrayList(); - for (DataCenter dataCenter : dataCenters) { - ZoneResponse zoneResponse = _responseGenerator.createZoneResponse(dataCenter, showCapacities); - zoneResponse.setObjectName("zone"); - zoneResponses.add(zoneResponse); - } - response.setResponses(zoneResponses); + ListResponse response = _queryService.listDataCenters(this); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/org/apache/cloudstack/api/response/ZoneResponse.java b/api/src/org/apache/cloudstack/api/response/ZoneResponse.java index 4ce4816b788..ab99e2d1e5f 100644 --- a/api/src/org/apache/cloudstack/api/response/ZoneResponse.java +++ b/api/src/org/apache/cloudstack/api/response/ZoneResponse.java @@ -66,8 +66,8 @@ public class ZoneResponse extends BaseResponse { @SerializedName(ApiConstants.DOMAIN) @Param(description="Network domain name for the networks in the zone") private String domain; - @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the containing domain, null for public zones") - private Long domainId; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the UUID of the containing domain, null for public zones") + private String domainId; @SerializedName("domainname") @Param(description="the name of the containing domain, null for public zones") private String domainName; @@ -141,7 +141,7 @@ public class ZoneResponse extends BaseResponse { this.domain = domain; } - public void setDomainId(Long domainId) { + public void setDomainId(String domainId) { this.domainId = domainId; } diff --git a/api/src/org/apache/cloudstack/query/QueryService.java b/api/src/org/apache/cloudstack/query/QueryService.java index 65c816bd6f3..bfe7b855c81 100644 --- a/api/src/org/apache/cloudstack/query/QueryService.java +++ b/api/src/org/apache/cloudstack/query/QueryService.java @@ -24,6 +24,8 @@ import org.apache.cloudstack.api.command.user.account.ListAccountsCmd; import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd; import org.apache.cloudstack.api.command.user.event.ListEventsCmd; import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd; +import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd; +import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd; import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd; import org.apache.cloudstack.api.command.user.project.ListProjectsCmd; import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd; @@ -31,8 +33,10 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd; import org.apache.cloudstack.api.command.user.vm.ListVMsCmd; import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; +import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; +import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.DomainRouterResponse; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.HostResponse; @@ -43,10 +47,12 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceTagResponse; import org.apache.cloudstack.api.response.SecurityGroupResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; import com.cloud.exception.PermissionDeniedException; @@ -86,4 +92,10 @@ public interface QueryService { public ListResponse searchForAccounts(ListAccountsCmd cmd); public ListResponse searchForAsyncJobs(ListAsyncJobsCmd cmd); + + public ListResponse searchForDiskOfferings(ListDiskOfferingsCmd cmd); + + public ListResponse searchForServiceOfferings(ListServiceOfferingsCmd cmd); + + public ListResponse listDataCenters(ListZonesByCmd cmd); } diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index 3dc01aa2008..390738fd4cf 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -1359,8 +1359,8 @@ label.type=Type label.unavailable=Unavailable label.unlimited=Unlimited label.untagged=Untagged -label.update.ssl.cert=Update SSL Certificate -label.update.ssl=Update SSL Certificate +label.update.ssl.cert= SSL Certificate +label.update.ssl= SSL Certificate label.updating=Updating label.url=URL label.usage.interface=Usage Interface diff --git a/client/pom.xml b/client/pom.xml index 00b425efda6..e57a5ab2ae5 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -30,6 +30,11 @@ cloud-plugin-acl-static-role-based ${project.version} + + org.apache.cloudstack + cloud-plugin-api-limit-account-based + ${project.version} + org.apache.cloudstack cloud-plugin-api-discovery diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 182cbd8cf3b..3740fb00633 100644 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -509,3 +509,8 @@ configureSimulator=1 #### api discovery commands listApis=15 + +#### API Rate Limit service command + +getApiLimit=15 +resetApiLimit=1 diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in index 07ae89d5886..46523d25aad 100644 --- a/client/tomcatconf/componentContext.xml.in +++ b/client/tomcatconf/componentContext.xml.in @@ -103,6 +103,8 @@ + + diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 958757a3563..c41d4f4f18f 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -54,6 +54,11 @@ under the License. true + + 1 + 25 + 50000 + @@ -233,6 +238,7 @@ under the License. + diff --git a/docs/en-US/host-add-xenserver-kvm-ovm.xml b/docs/en-US/host-add-xenserver-kvm-ovm.xml index 4bbeefcbed4..1f13e72d4c3 100644 --- a/docs/en-US/host-add-xenserver-kvm-ovm.xml +++ b/docs/en-US/host-add-xenserver-kvm-ovm.xml @@ -83,6 +83,11 @@ Make sure the new host has the same network configuration (guest, private, and public network) as other hosts in the cluster. + + If you are using OpenVswitch bridges edit the file agent.properties on the KVM host + and set the parameter network.bridge.type to + openvswitch before adding the host to &PRODUCT; + + +
+ Configure the network using OpenVswitch + This is a very important section, please make sure you read this thoroughly. + In order to forward traffic to your instances you will need at least two bridges: public and private. + By default these bridges are called cloudbr0 and cloudbr1, but you do have to make sure they are available on each hypervisor. + The most important factor is that you keep the configuration consistent on all your hypervisors. +
+ Preparing + To make sure that the native bridge module will not interfere with openvswitch the bridge module should be added to the blacklist. See the modprobe documentation for your distribution on where to find the blacklist. Make sure the module is not loaded either by rebooting or executing rmmod bridge before executing next steps. + The network configurations below depend on the ifup-ovs and ifdown-ovs scripts which are part of the openvswitch installation. They should be installed in /etc/sysconfig/network-scripts/ +
+
+ Network example + There are many ways to configure your network. In the Basic networking mode you should have two (V)LAN's, one for your private network and one for the public network. + We assume that the hypervisor has one NIC (eth0) with three tagged VLAN's: + + VLAN 100 for management of the hypervisor + VLAN 200 for public network of the instances (cloudbr0) + VLAN 300 for private network of the instances (cloudbr1) + + On VLAN 100 we give the Hypervisor the IP-Address 192.168.42.11/24 with the gateway 192.168.42.1 + The Hypervisor and Management server don't have to be in the same subnet! +
+
+ Configuring the network bridges + It depends on the distribution you are using how to configure these, below you'll find + examples for RHEL/CentOS. + The goal is to have three bridges called 'mgmt0', 'cloudbr0' and 'cloudbr1' after this + section. This should be used as a guideline only. The exact configuration will + depend on your network layout. +
+ Configure OpenVswitch + The network interfaces using OpenVswitch are created using the ovs-vsctl command. This command will configure the interfaces and persist them to the OpenVswitch database. + First we create a main bridge connected to the eth0 interface. Next we create three fake bridges, each connected to a specific vlan tag. + +
+
+ Configure in RHEL or CentOS + The required packages were installed when openvswitch and libvirt were installed, + we can proceed to configuring the network. + First we configure eth0 + vi /etc/sysconfig/network-scripts/ifcfg-eth0 + Make sure it looks similair to: + + We have to configure the base bridge with the trunk. + vi /etc/sysconfig/network-scripts/ifcfg-cloudbr + + We now have to configure the three VLAN bridges: + vi /etc/sysconfig/network-scripts/ifcfg-mgmt0 + + vi /etc/sysconfig/network-scripts/ifcfg-cloudbr0 + + vi /etc/sysconfig/network-scripts/ifcfg-cloudbr1 + + With this configuration you should be able to restart the network, although a reboot is recommended to see if everything works properly. + Make sure you have an alternative way like IPMI or ILO to reach the machine in case you made a configuration error and the network stops functioning! +
+
+
diff --git a/docs/en-US/hypervisor-host-install-network.xml b/docs/en-US/hypervisor-host-install-network.xml index 8f6a10cdd69..3a6dfac48bd 100644 --- a/docs/en-US/hypervisor-host-install-network.xml +++ b/docs/en-US/hypervisor-host-install-network.xml @@ -25,6 +25,7 @@
Configure the network bridges This is a very important section, please make sure you read this thoroughly. + This section details how to configure bridges using the native implementation in Linux. Please refer to the next section if you intend to use OpenVswitch In order to forward traffic to your instances you will need at least two bridges: public and private. By default these bridges are called cloudbr0 and cloudbr1, but you do have to make sure they are available on each hypervisor. The most important factor is that you keep the configuration consistent on all your hypervisors. @@ -146,4 +147,4 @@ iface cloudbr1 inet manual Make sure you have an alternative way like IPMI or ILO to reach the machine in case you made a configuration error and the network stops functioning!
- \ No newline at end of file + diff --git a/docs/en-US/hypervisor-kvm-install-flow.xml b/docs/en-US/hypervisor-kvm-install-flow.xml index 76e03ef7919..6cc73e4fdfa 100644 --- a/docs/en-US/hypervisor-kvm-install-flow.xml +++ b/docs/en-US/hypervisor-kvm-install-flow.xml @@ -1,5 +1,5 @@ - %BOOK_ENTITIES; ]> @@ -31,6 +31,7 @@ + diff --git a/docs/en-US/hypervisor-kvm-requirements.xml b/docs/en-US/hypervisor-kvm-requirements.xml index c42db86a2b8..cdfc808e490 100644 --- a/docs/en-US/hypervisor-kvm-requirements.xml +++ b/docs/en-US/hypervisor-kvm-requirements.xml @@ -1,5 +1,5 @@ - %BOOK_ENTITIES; ]> @@ -35,6 +35,11 @@ libvirt: 0.9.4 or higher Qemu/KVM: 1.0 or higher + The default bridge in &PRODUCT; is the Linux native bridge implementation (bridge module). &PRODUCT; includes an option to work with OpenVswitch, the requirements are listed below + + libvirt: 0.9.11 or higher + openvswitch: 1.7.1 or higher + In addition, the following hardware requirements apply: Within a single cluster, the hosts must be of the same distribution version. diff --git a/docs/en-US/plugin-niciranvp-features.xml b/docs/en-US/plugin-niciranvp-features.xml index b67323d56d2..b71e67f4199 100644 --- a/docs/en-US/plugin-niciranvp-features.xml +++ b/docs/en-US/plugin-niciranvp-features.xml @@ -24,6 +24,10 @@ Features of the Nicira NVP Plugin In CloudStack release 4.0.0-incubating this plugin supports the Connectivity service. This service is responsible for creating Layer 2 networks supporting the networks created by Guests. In other words when an tennant creates a new network, instead of the traditional VLAN a logical network will be created by sending the appropriate calls to the Nicira NVP Controller. The plugin has been tested with Nicira NVP versions 2.1.0, 2.2.0 and 2.2.1 - In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in combination with Nicira NVP - In CloudStack 4.0.0-incubating the UI components for this plugin are not complete, configuration is done by sending commands to the API + In CloudStack 4.0.0-incubating only the XenServer hypervisor is supported for use in + combination with Nicira NVP. + In CloudStack 4.1.0-incubating both KVM and XenServer hypervisors are + supported. + In CloudStack 4.0.0-incubating the UI components for this plugin are not complete, + configuration is done by sending commands to the API. diff --git a/docs/en-US/plugin-niciranvp-preparations.xml b/docs/en-US/plugin-niciranvp-preparations.xml index 95a25bdca26..86b795ccd0b 100644 --- a/docs/en-US/plugin-niciranvp-preparations.xml +++ b/docs/en-US/plugin-niciranvp-preparations.xml @@ -24,7 +24,9 @@ Prerequisites Before enabling the Nicira NVP plugin the NVP Controller needs to be configured. Please review the NVP User Guide on how to do that. CloudStack needs to have at least one physical network with the isolation method set to "STT". This network should be enabled for the Guest traffic type. - The Guest traffic type should be configured with the traffic label that matches the name of the Integration Bridge on XenServer. See the Nicira NVP User Guide for more details on how to set this up in XenServer. + The Guest traffic type should be configured with the traffic label that matches the name of + the Integration Bridge on the hypervisor. See the Nicira NVP User Guide for more details + on how to set this up in XenServer or KVM. Make sure you have the following information ready: The IP address of the NVP Controller diff --git a/docs/en-US/plugin-niciranvp-ui.xml b/docs/en-US/plugin-niciranvp-ui.xml new file mode 100644 index 00000000000..8b1bbad8395 --- /dev/null +++ b/docs/en-US/plugin-niciranvp-ui.xml @@ -0,0 +1,26 @@ + + +%BOOK_ENTITIES; + +%xinclude; +]> + +
+ Configuring the Nicira NVP plugin from the UI + In CloudStack 4.1.0-incubating the Nicira NVP plugin and its resources can be configured in the infrastructure tab of the UI. Navigate to the physical network with STT isolation and configure the network elements. The NiciraNvp is listed here. +
diff --git a/docs/en-US/plugin-niciranvp-usage.xml b/docs/en-US/plugin-niciranvp-usage.xml index 17413387ea4..76f9a0b5b05 100644 --- a/docs/en-US/plugin-niciranvp-usage.xml +++ b/docs/en-US/plugin-niciranvp-usage.xml @@ -24,6 +24,7 @@ Using the Nicira NVP Plugin + diff --git a/patches/systemvm/debian/config/opt/cloud/bin/checkbatchs2svpn.sh b/patches/systemvm/debian/config/opt/cloud/bin/checkbatchs2svpn.sh new file mode 100755 index 00000000000..80e3213753b --- /dev/null +++ b/patches/systemvm/debian/config/opt/cloud/bin/checkbatchs2svpn.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# 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. + +for i in $* +do + info=`/opt/cloud/bin/checks2svpn.sh $i` + ret=$? + echo -n "$i:$ret:$info&" +done + diff --git a/plugins/api/discovery/pom.xml b/plugins/api/discovery/pom.xml index a61b275addc..1cfc5c2eaf2 100644 --- a/plugins/api/discovery/pom.xml +++ b/plugins/api/discovery/pom.xml @@ -20,25 +20,47 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - 4.0.0 - cloud-plugin-api-discovery - Apache CloudStack Plugin - API Discovery - - org.apache.cloudstack - cloudstack-plugins - 4.1.0-SNAPSHOT - ../../pom.xml - - - - org.apache.cloudstack - cloud-api - ${project.version} - - - org.apache.cloudstack - cloud-utils - ${project.version} - - + 4.0.0 + cloud-plugin-api-discovery + Apache CloudStack Plugin - API Discovery + + org.apache.cloudstack + cloudstack-plugins + 4.1.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-api + ${project.version} + + + org.apache.cloudstack + cloud-utils + ${project.version} + + + + install + src + test + + + test/resources + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Xmx1024m + + org/apache/cloudstack/discovery/integration/* + + + + + diff --git a/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java b/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java index de6a9f93965..77484f0f7e7 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/api/response/ApiDiscoveryResponse.java @@ -57,18 +57,34 @@ public class ApiDiscoveryResponse extends BaseResponse { this.name = name; } + public String getName() { + return name; + } + public void setDescription(String description) { this.description = description; } + public String getDescription() { + return description; + } + public void setSince(String since) { this.since = since; } + public String getSince() { + return since; + } + public void setAsync(Boolean isAsync) { this.isAsync = isAsync; } + public boolean getAsync() { + return isAsync; + } + public String getRelated() { return related; } diff --git a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java index d10d9599c99..7689ba4b3d8 100644 --- a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java +++ b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java @@ -54,28 +54,26 @@ import com.google.gson.annotations.SerializedName; public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class); - @Inject List _apiAccessCheckers = null; - private Map _apiNameDiscoveryResponseMap = null; + @Inject protected List s_apiAccessCheckers = null; + private static Map s_apiNameDiscoveryResponseMap = null; @Inject List _services; protected ApiDiscoveryServiceImpl() { super(); - if (_apiNameDiscoveryResponseMap == null) { + if (s_apiNameDiscoveryResponseMap == null) { long startTime = System.nanoTime(); - _apiNameDiscoveryResponseMap = new HashMap(); - cacheResponseMap(); + s_apiNameDiscoveryResponseMap = new HashMap(); + //TODO: Fix and use PluggableService to get the classes + Set> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class, + new String[]{"org.apache.cloudstack.api", "com.cloud.api"}); + cacheResponseMap(cmdClasses); long endTime = System.nanoTime(); s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); } } - private void cacheResponseMap() { - Set> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class, - new String[]{"org.apache.cloudstack.api", "com.cloud.api"}); - - //TODO: Fix and use PluggableService to get the classes - + protected void cacheResponseMap(Set> cmdClasses) { Map> responseApiNameListMap = new HashMap>(); for(Class cmdClass: cmdClasses) { @@ -115,8 +113,8 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } } - Field[] fields = ReflectUtil.getAllFieldsForClass(cmdClass, - new Class[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); + Set fields = ReflectUtil.getAllFieldsForClass(cmdClass, + new Class[]{BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); boolean isAsync = ReflectUtil.isCmdClassAsync(cmdClass, new Class[] {BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); @@ -142,11 +140,11 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } } response.setObjectName("api"); - _apiNameDiscoveryResponseMap.put(apiName, response); + s_apiNameDiscoveryResponseMap.put(apiName, response); } - for (String apiName : _apiNameDiscoveryResponseMap.keySet()) { - ApiDiscoveryResponse response = _apiNameDiscoveryResponseMap.get(apiName); + for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) { + ApiDiscoveryResponse response = s_apiNameDiscoveryResponseMap.get(apiName); Set processedParams = new HashSet(); for (ApiParameterResponse param: response.getParams()) { if (responseApiNameListMap.containsKey(param.getRelated())) { @@ -166,7 +164,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } else { response.setRelated(null); } - _apiNameDiscoveryResponseMap.put(apiName, response); + s_apiNameDiscoveryResponseMap.put(apiName, response); } } @@ -179,22 +177,22 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { return null; if (name != null) { - if (!_apiNameDiscoveryResponseMap.containsKey(name)) + if (!s_apiNameDiscoveryResponseMap.containsKey(name)) return null; - for (APIChecker apiChecker : _apiAccessCheckers) { + for (APIChecker apiChecker : s_apiAccessCheckers) { try { apiChecker.checkAccess(user, name); } catch (Exception ex) { return null; } } - responseList.add(_apiNameDiscoveryResponseMap.get(name)); + responseList.add(s_apiNameDiscoveryResponseMap.get(name)); } else { - for (String apiName : _apiNameDiscoveryResponseMap.keySet()) { + for (String apiName : s_apiNameDiscoveryResponseMap.keySet()) { boolean isAllowed = true; - for (APIChecker apiChecker : _apiAccessCheckers) { + for (APIChecker apiChecker : s_apiAccessCheckers) { try { apiChecker.checkAccess(user, apiName); } catch (Exception ex) { @@ -202,7 +200,7 @@ public class ApiDiscoveryServiceImpl implements ApiDiscoveryService { } } if (isAllowed) - responseList.add(_apiNameDiscoveryResponseMap.get(apiName)); + responseList.add(s_apiNameDiscoveryResponseMap.get(apiName)); } } response.setResponses(responseList); diff --git a/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java new file mode 100644 index 00000000000..3b526dd485d --- /dev/null +++ b/plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java @@ -0,0 +1,86 @@ +// 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 org.apache.cloudstack.discovery; + +import com.cloud.user.User; +import com.cloud.user.UserVO; + +import java.util.*; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.acl.APIChecker; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.command.user.discovery.ListApisCmd; +import org.apache.cloudstack.api.response.ApiDiscoveryResponse; +import org.apache.cloudstack.api.response.ListResponse; + +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class ApiDiscoveryTest { + + private static ApiDiscoveryServiceImpl _discoveryService = new ApiDiscoveryServiceImpl(); + private static APIChecker _apiChecker = mock(APIChecker.class); + + private static Class testCmdClass = ListApisCmd.class; + private static User testUser; + private static String testApiName; + private static String testApiDescription; + private static String testApiSince; + private static boolean testApiAsync; + + @BeforeClass + public static void setUp() throws ConfigurationException { + testApiName = testCmdClass.getAnnotation(APICommand.class).name(); + testApiDescription = testCmdClass.getAnnotation(APICommand.class).description(); + testApiSince = testCmdClass.getAnnotation(APICommand.class).since(); + testApiAsync = false; + testUser = new UserVO(); + + Set> cmdClasses = new HashSet>(); + cmdClasses.add(ListApisCmd.class); + _discoveryService.cacheResponseMap(cmdClasses); + _discoveryService.s_apiAccessCheckers = (List) mock(List.class); + + when(_apiChecker.checkAccess(any(User.class), anyString())).thenReturn(true); + when(_discoveryService.s_apiAccessCheckers.iterator()).thenReturn(Arrays.asList(_apiChecker).iterator()); + } + + @Test + public void verifyListSingleApi() throws Exception { + ListResponse responses = (ListResponse) _discoveryService.listApis(testUser, testApiName); + ApiDiscoveryResponse response = responses.getResponses().get(0); + assertTrue("No. of response items should be one", responses.getCount() == 1); + assertEquals("Error in api name", testApiName, response.getName()); + assertEquals("Error in api description", testApiDescription, response.getDescription()); + assertEquals("Error in api since", testApiSince, response.getSince()); + assertEquals("Error in api isAsync", testApiAsync, response.getAsync()); + } + + @Test + public void verifyListApis() throws Exception { + ListResponse responses = (ListResponse) _discoveryService.listApis(testUser, null); + assertTrue("No. of response items > 1", responses.getCount() > 1); + for (ApiDiscoveryResponse response: responses.getResponses()) { + assertFalse("API name is empty", response.getName().isEmpty()); + assertFalse("API description is empty", response.getDescription().isEmpty()); + } + } +} diff --git a/plugins/api/rate-limit/pom.xml b/plugins/api/rate-limit/pom.xml new file mode 100644 index 00000000000..1f0330916a9 --- /dev/null +++ b/plugins/api/rate-limit/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + cloud-plugin-api-limit-account-based + Apache CloudStack Plugin - API Rate Limit + + org.apache.cloudstack + cloudstack-plugins + 4.1.0-SNAPSHOT + ../../pom.xml + + + install + src + test + + + test/resources + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Xmx1024m + + org/apache/cloudstack/ratelimit/integration/* + + + + + + diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java new file mode 100644 index 00000000000..5a7ac863abc --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java @@ -0,0 +1,100 @@ +// 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 org.apache.cloudstack.api.command.admin.ratelimit; + +import org.apache.cloudstack.api.ACL; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.ApiLimitResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.cloudstack.ratelimit.ApiRateLimitService; +import org.apache.log4j.Logger; + +import com.cloud.user.Account; +import com.cloud.user.UserContext; + +import javax.inject.Inject; + +@APICommand(name = "resetApiLimit", responseObject=ApiLimitResponse.class, description="Reset api count") +public class ResetApiLimitCmd extends BaseCmd { + private static final Logger s_logger = Logger.getLogger(ResetApiLimitCmd.class.getName()); + + private static final String s_name = "resetapilimitresponse"; + + @Inject + ApiRateLimitService _apiLimitService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @ACL + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.UUID, entityType=AccountResponse.class, + description="the ID of the acount whose limit to be reset") + private Long accountId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public Long getAccountId() { + return accountId; + } + + + public void setAccountId(Long accountId) { + this.accountId = accountId; + } + + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if (account != null) { + return account.getId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute(){ + boolean result = _apiLimitService.resetApiLimit(this.accountId); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset api limit counter"); + } + } +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java new file mode 100644 index 00000000000..1afa9322d75 --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java @@ -0,0 +1,87 @@ +// 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 org.apache.cloudstack.api.command.user.ratelimit; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.api.ACL; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.BaseListCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.BaseCmd.CommandType; +import org.apache.cloudstack.api.command.admin.ratelimit.ResetApiLimitCmd; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.ApiLimitResponse; +import org.apache.cloudstack.api.response.PhysicalNetworkResponse; +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.ratelimit.ApiRateLimitService; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +import javax.inject.Inject; + +@APICommand(name = "getApiLimit", responseObject=ApiLimitResponse.class, description="Get API limit count for the caller") +public class GetApiLimitCmd extends BaseCmd { + private static final Logger s_logger = Logger.getLogger(GetApiLimitCmd.class.getName()); + + private static final String s_name = "getapilimitresponse"; + + @Inject + ApiRateLimitService _apiLimitService; + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Account account = UserContext.current().getCaller(); + if (account != null) { + return account.getId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public void execute(){ + Account caller = UserContext.current().getCaller(); + ApiLimitResponse response = _apiLimitService.searchApiLimit(caller); + response.setResponseName(getCommandName()); + response.setObjectName("apilimit"); + this.setResponseObject(response); + } +} + + diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/api/response/ApiLimitResponse.java b/plugins/api/rate-limit/src/org/apache/cloudstack/api/response/ApiLimitResponse.java new file mode 100644 index 00000000000..245e8f15d8a --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/api/response/ApiLimitResponse.java @@ -0,0 +1,82 @@ +// 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 org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.ApiConstants; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.BaseResponse; + + +public class ApiLimitResponse extends BaseResponse { + @SerializedName(ApiConstants.ACCOUNT_ID) @Param(description="the account uuid of the api remaining count") + private String accountId; + + @SerializedName(ApiConstants.ACCOUNT) @Param(description="the account name of the api remaining count") + private String accountName; + + @SerializedName("apiIssued") @Param(description="number of api already issued") + private int apiIssued; + + @SerializedName("apiAllowed") @Param(description="currently allowed number of apis") + private int apiAllowed; + + @SerializedName("expireAfter") @Param(description="seconds left to reset counters") + private long expireAfter; + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public void setApiIssued(int apiIssued) { + this.apiIssued = apiIssued; + } + + public void setApiAllowed(int apiAllowed) { + this.apiAllowed = apiAllowed; + } + + public void setExpireAfter(long duration) { + this.expireAfter = duration; + } + + public String getAccountId() { + return accountId; + } + + public String getAccountName() { + return accountName; + } + + public int getApiIssued() { + return apiIssued; + } + + public int getApiAllowed() { + return apiAllowed; + } + + public long getExpireAfter() { + return expireAfter; + } + + +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/ApiRateLimitService.java b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/ApiRateLimitService.java new file mode 100644 index 00000000000..c5b715019b6 --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/ApiRateLimitService.java @@ -0,0 +1,37 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.ratelimit; + +import org.apache.cloudstack.api.response.ApiLimitResponse; +import com.cloud.user.Account; +import com.cloud.utils.component.PluggableService; + +/** + * Provide API rate limit service + * @author minc + * + */ +public interface ApiRateLimitService extends PluggableService{ + + public ApiLimitResponse searchApiLimit(Account caller); + + public boolean resetApiLimit(Long accountId); + + public void setTimeToLive(int timeToLive); + + public void setMaxAllowed(int max); +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java new file mode 100644 index 00000000000..a5726e1d2ac --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java @@ -0,0 +1,193 @@ +// 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 org.apache.cloudstack.ratelimit; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import javax.ejb.Local; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheManager; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.acl.APIChecker; +import org.apache.cloudstack.api.command.admin.ratelimit.ResetApiLimitCmd; +import org.apache.cloudstack.api.command.user.ratelimit.GetApiLimitCmd; +import org.apache.cloudstack.api.response.ApiLimitResponse; + +import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.RequestLimitException; +import com.cloud.user.Account; +import com.cloud.user.AccountService; +import com.cloud.user.User; +import com.cloud.utils.component.AdapterBase; +import org.springframework.stereotype.Component; + +@Component +@Local(value = APIChecker.class) +public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, ApiRateLimitService { + private static final Logger s_logger = Logger.getLogger(ApiRateLimitServiceImpl.class); + + /** + * Fixed time duration where api rate limit is set, in seconds + */ + private int timeToLive = 1; + + /** + * Max number of api requests during timeToLive duration. + */ + private int maxAllowed = 30; + + private LimitStore _store = null; + + @Inject + AccountService _accountService; + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + + if (_store == null) { + // not configured yet, note that since this class is both adapter + // and pluggableService, so this method + // may be invoked twice in ComponentLocator. + // get global configured duration and max values + Object duration = params.get("api.throttling.interval"); + if (duration != null) { + timeToLive = Integer.parseInt((String) duration); + } + Object maxReqs = params.get("api.throttling.max"); + if (maxReqs != null) { + maxAllowed = Integer.parseInt((String) maxReqs); + } + // create limit store + EhcacheLimitStore cacheStore = new EhcacheLimitStore(); + int maxElements = 10000; + Object cachesize = params.get("api.throttling.cachesize"); + if ( cachesize != null ){ + maxElements = Integer.parseInt((String)cachesize); + } + CacheManager cm = CacheManager.create(); + Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive); + cm.addCache(cache); + s_logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements ); + cacheStore.setCache(cache); + _store = cacheStore; + + } + + return true; + } + + @Override + public ApiLimitResponse searchApiLimit(Account caller) { + ApiLimitResponse response = new ApiLimitResponse(); + response.setAccountId(caller.getUuid()); + response.setAccountName(caller.getAccountName()); + StoreEntry entry = _store.get(caller.getId()); + if (entry == null) { + + /* Populate the entry, thus unlocking any underlying mutex */ + entry = _store.create(caller.getId(), timeToLive); + response.setApiIssued(0); + response.setApiAllowed(maxAllowed); + response.setExpireAfter(timeToLive); + } + else{ + response.setApiIssued(entry.getCounter()); + response.setApiAllowed(maxAllowed - entry.getCounter()); + response.setExpireAfter(entry.getExpireDuration()); + } + + return response; + } + + + + @Override + public boolean resetApiLimit(Long accountId) { + if ( accountId != null ){ + _store.create(accountId, timeToLive); + } + else{ + _store.resetCounters(); + } + return true; + } + + + + @Override + public boolean checkAccess(User user, String apiCommandName) throws PermissionDeniedException, RequestLimitException { + Long accountId = user.getAccountId(); + Account account = _accountService.getAccount(accountId); + if ( _accountService.isRootAdmin(account.getType())){ + // no API throttling on root admin + return true; + } + StoreEntry entry = _store.get(accountId); + + if (entry == null) { + + /* Populate the entry, thus unlocking any underlying mutex */ + entry = _store.create(accountId, timeToLive); + } + + /* Increment the client count and see whether we have hit the maximum allowed clients yet. */ + int current = entry.incrementAndGet(); + + if (current <= maxAllowed) { + s_logger.trace("account (" + account.getAccountId() + "," + account.getAccountName() + ") has current count = " + current); + return true; + } else { + long expireAfter = entry.getExpireDuration(); + // for this exception, we can just show the same message to user and admin users. + String msg = "The given user has reached his/her account api limit, please retry after " + expireAfter + " ms."; + s_logger.warn(msg); + throw new RequestLimitException(msg); + } + } + + + @Override + public List> getCommands() { + List> cmdList = new ArrayList>(); + cmdList.add(ResetApiLimitCmd.class); + cmdList.add(GetApiLimitCmd.class); + return cmdList; + } + + + @Override + public void setTimeToLive(int timeToLive) { + this.timeToLive = timeToLive; + } + + + + @Override + public void setMaxAllowed(int max) { + this.maxAllowed = max; + + } + + +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/EhcacheLimitStore.java b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/EhcacheLimitStore.java new file mode 100644 index 00000000000..659cf81b0e6 --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/EhcacheLimitStore.java @@ -0,0 +1,99 @@ +// 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 org.apache.cloudstack.ratelimit; + +import net.sf.ehcache.Ehcache; +import net.sf.ehcache.Element; +import net.sf.ehcache.constructs.blocking.BlockingCache; +import net.sf.ehcache.constructs.blocking.LockTimeoutException; + +/** + * A Limit store implementation using Ehcache. + * @author minc + * + */ +public class EhcacheLimitStore implements LimitStore { + + + private BlockingCache cache; + + + public void setCache(Ehcache cache) { + BlockingCache ref; + + if (!(cache instanceof BlockingCache)) { + ref = new BlockingCache(cache); + cache.getCacheManager().replaceCacheWithDecoratedCache(cache, new BlockingCache(cache)); + } else { + ref = (BlockingCache) cache; + } + + this.cache = ref; + } + + + @Override + public StoreEntry create(Long key, int timeToLive) { + StoreEntryImpl result = new StoreEntryImpl(timeToLive); + Element element = new Element(key, result); + element.setTimeToLive(timeToLive); + cache.put(element); + return result; + } + + @Override + public StoreEntry get(Long key) { + + Element entry = null; + + try { + + /* This may block. */ + entry = cache.get(key); + } catch (LockTimeoutException e) { + throw new RuntimeException(); + } catch (RuntimeException e) { + + /* Release the lock that may have been acquired. */ + cache.put(new Element(key, null)); + } + + StoreEntry result = null; + + if (entry != null) { + + /* + * We don't need to check isExpired() on the result, since ehcache takes care of expiring entries for us. + * c.f. the get(Key) implementation in this class. + */ + result = (StoreEntry) entry.getObjectValue(); + } + + return result; + } + + + + @Override + public void resetCounters() { + cache.removeAll(); + + } + + + +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/LimitStore.java b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/LimitStore.java new file mode 100644 index 00000000000..a5e086b3029 --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/LimitStore.java @@ -0,0 +1,51 @@ +// 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 org.apache.cloudstack.ratelimit; + +import com.cloud.user.Account; + +/** + * Interface to define how an api limit store should work. + * @author minc + * + */ +public interface LimitStore { + + /** + * Returns a store entry for the given account. A value of null means that there is no + * such entry and the calling client must call create to avoid + * other clients potentially being blocked without any hope of progressing. A non-null + * entry means that it has not expired and can be used to determine whether the current client should be allowed to + * proceed with the rate-limited action or not. + * + */ + StoreEntry get(Long account); + + /** + * Creates a new store entry + * + * @param account + * the user account, key to the store + * @param timeToLiveInSecs + * the positive time-to-live in seconds + * @return a non-null entry + */ + StoreEntry create(Long account, int timeToLiveInSecs); + + void resetCounters(); + +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/StoreEntry.java b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/StoreEntry.java new file mode 100644 index 00000000000..76e8a2d9281 --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/StoreEntry.java @@ -0,0 +1,33 @@ +// 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 org.apache.cloudstack.ratelimit; + +/** + * Interface for each entry in LimitStore. + * @author minc + * + */ +public interface StoreEntry { + + int getCounter(); + + int incrementAndGet(); + + boolean isExpired(); + + long getExpireDuration(); /* seconds to reset counter */ +} diff --git a/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/StoreEntryImpl.java b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/StoreEntryImpl.java new file mode 100644 index 00000000000..e8143e52370 --- /dev/null +++ b/plugins/api/rate-limit/src/org/apache/cloudstack/ratelimit/StoreEntryImpl.java @@ -0,0 +1,64 @@ +// 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 org.apache.cloudstack.ratelimit; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Implementation of limit store entry. + * @author minc + * + */ +public class StoreEntryImpl implements StoreEntry { + + private final long expiry; + + private final AtomicInteger counter; + + StoreEntryImpl(int timeToLive) { + this.expiry = System.currentTimeMillis() + timeToLive * 1000; + this.counter = new AtomicInteger(0); + } + + + @Override + public boolean isExpired() { + return System.currentTimeMillis() > expiry; + } + + + + @Override + public long getExpireDuration() { + if ( isExpired() ) + return 0; // already expired + else { + return expiry - System.currentTimeMillis(); + } + } + + + @Override + public int incrementAndGet() { + return this.counter.incrementAndGet(); + } + + @Override + public int getCounter(){ + return this.counter.get(); + } +} diff --git a/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java new file mode 100644 index 00000000000..85eeaaf4223 --- /dev/null +++ b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/ApiRateLimitTest.java @@ -0,0 +1,226 @@ +// 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 org.apache.cloudstack.ratelimit; + +import java.util.Collections; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.api.response.ApiLimitResponse; +import org.apache.cloudstack.ratelimit.ApiRateLimitServiceImpl; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.cloud.exception.RequestLimitException; +import com.cloud.user.Account; +import com.cloud.user.AccountService; +import com.cloud.user.AccountVO; +import com.cloud.user.User; +import com.cloud.user.UserVO; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class ApiRateLimitTest { + + static ApiRateLimitServiceImpl _limitService = new ApiRateLimitServiceImpl(); + static AccountService _accountService = mock(AccountService.class); + private static long acctIdSeq = 5L; + private static Account testAccount; + + @BeforeClass + public static void setUp() throws ConfigurationException { + + _limitService.configure("ApiRateLimitTest", Collections. emptyMap()); + + _limitService._accountService = _accountService; + + // Standard responses + AccountVO acct = new AccountVO(acctIdSeq); + acct.setType(Account.ACCOUNT_TYPE_NORMAL); + acct.setAccountName("demo"); + testAccount = acct; + + when(_accountService.getAccount(5L)).thenReturn(testAccount); + when(_accountService.isRootAdmin(Account.ACCOUNT_TYPE_NORMAL)).thenReturn(false); + } + + @Before + public void testSetUp() { + // reset counter for each test + _limitService.resetApiLimit(null); + } + + private User createFakeUser(){ + UserVO user = new UserVO(); + user.setAccountId(acctIdSeq); + return user; + } + + private boolean isUnderLimit(User key){ + try{ + _limitService.checkAccess(key, null); + return true; + } + catch (RequestLimitException ex){ + return false; + } + } + + @Test + public void sequentialApiAccess() { + int allowedRequests = 1; + _limitService.setMaxAllowed(allowedRequests); + _limitService.setTimeToLive(1); + + User key = createFakeUser(); + assertTrue("Allow for the first request", isUnderLimit(key)); + + assertFalse("Second request should be blocked, since we assume that the two api " + + " accesses take less than a second to perform", isUnderLimit(key)); + } + + @Test + public void canDoReasonableNumberOfApiAccessPerSecond() throws Exception { + int allowedRequests = 200; + _limitService.setMaxAllowed(allowedRequests); + _limitService.setTimeToLive(1); + + User key = createFakeUser(); + + for (int i = 0; i < allowedRequests; i++) { + assertTrue("We should allow " + allowedRequests + " requests per second, but failed at request " + i, isUnderLimit(key)); + } + + + assertFalse("We should block >" + allowedRequests + " requests per second", isUnderLimit(key)); + } + + @Test + public void multipleClientsCanAccessWithoutBlocking() throws Exception { + int allowedRequests = 200; + _limitService.setMaxAllowed(allowedRequests); + _limitService.setTimeToLive(1); + + + final User key = createFakeUser(); + + int clientCount = allowedRequests; + Runnable[] clients = new Runnable[clientCount]; + final boolean[] isUsable = new boolean[clientCount]; + + final CountDownLatch startGate = new CountDownLatch(1); + + final CountDownLatch endGate = new CountDownLatch(clientCount); + + + for (int i = 0; i < isUsable.length; ++i) { + final int j = i; + clients[j] = new Runnable() { + + /** + * {@inheritDoc} + */ + @Override + public void run() { + try { + startGate.await(); + + isUsable[j] = isUnderLimit(key); + + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + endGate.countDown(); + } + } + }; + } + + ExecutorService executor = Executors.newFixedThreadPool(clientCount); + + for (Runnable runnable : clients) { + executor.execute(runnable); + } + + startGate.countDown(); + + endGate.await(); + + for (boolean b : isUsable) { + assertTrue("Concurrent client request should be allowed within limit", b); + } + } + + @Test + public void expiryOfCounterIsSupported() throws Exception { + int allowedRequests = 1; + _limitService.setMaxAllowed(allowedRequests); + _limitService.setTimeToLive(1); + + User key = this.createFakeUser(); + + assertTrue("The first request should be allowed", isUnderLimit(key)); + + // Allow the token to expire + Thread.sleep(1001); + + assertTrue("Another request after interval should be allowed as well", isUnderLimit(key)); + } + + @Test + public void verifyResetCounters() throws Exception { + int allowedRequests = 1; + _limitService.setMaxAllowed(allowedRequests); + _limitService.setTimeToLive(1); + + User key = this.createFakeUser(); + + assertTrue("The first request should be allowed", isUnderLimit(key)); + + assertFalse("Another request should be blocked", isUnderLimit(key)); + + _limitService.resetApiLimit(key.getAccountId()); + + assertTrue("Another request should be allowed after reset counter", isUnderLimit(key)); + } + + + @Test + public void verifySearchCounter() throws Exception { + int allowedRequests = 10; + _limitService.setMaxAllowed(allowedRequests); + _limitService.setTimeToLive(1); + + User key = this.createFakeUser(); + + for ( int i = 0; i < 5; i++ ){ + assertTrue("Issued 5 requests", isUnderLimit(key)); + } + + ApiLimitResponse response = _limitService.searchApiLimit(testAccount); + assertEquals("apiIssued is incorrect", 5, response.getApiIssued()); + assertEquals("apiAllowed is incorrect", 5, response.getApiAllowed()); + assertTrue("expiredAfter is incorrect", response.getExpireAfter() < 1000); + + } + +} diff --git a/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/APITest.java b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/APITest.java new file mode 100644 index 00000000000..7701b1515b0 --- /dev/null +++ b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/APITest.java @@ -0,0 +1,211 @@ +// 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 +// 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 org.apache.cloudstack.ratelimit.integration; + +import java.io.BufferedReader; +import java.io.EOFException; +import java.io.InputStreamReader; +import java.math.BigInteger; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Iterator; + +import org.apache.cloudstack.api.response.SuccessResponse; + +import com.cloud.api.ApiGsonHelper; +import com.cloud.utils.exception.CloudRuntimeException; +import com.google.gson.Gson; + +/** + * Base class for API Test + * + * @author Min Chen + * + */ +public abstract class APITest { + + protected String rootUrl = "http://localhost:8080/client/api"; + protected String sessionKey = null; + protected String cookieToSent = null; + + + /** + * Sending an api request through Http GET + * @param command command name + * @param params command query parameters in a HashMap + * @return http request response string + */ + protected String sendRequest(String command, HashMap params){ + try { + // Construct query string + StringBuilder sBuilder = new StringBuilder(); + sBuilder.append("command="); + sBuilder.append(command); + if ( params != null && params.size() > 0){ + Iterator keys = params.keySet().iterator(); + while (keys.hasNext()){ + String key = keys.next(); + sBuilder.append("&"); + sBuilder.append(key); + sBuilder.append("="); + sBuilder.append(URLEncoder.encode(params.get(key), "UTF-8")); + } + } + + // Construct request url + String reqUrl = rootUrl + "?" + sBuilder.toString(); + + // Send Http GET request + URL url = new URL(reqUrl); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + + if ( !command.equals("login") && cookieToSent != null){ + // add the cookie to a request + conn.setRequestProperty("Cookie", cookieToSent); + } + conn.connect(); + + + if ( command.equals("login")){ + // if it is login call, store cookie + String headerName=null; + for (int i=1; (headerName = conn.getHeaderFieldKey(i))!=null; i++) { + if (headerName.equals("Set-Cookie")) { + String cookie = conn.getHeaderField(i); + cookie = cookie.substring(0, cookie.indexOf(";")); + String cookieName = cookie.substring(0, cookie.indexOf("=")); + String cookieValue = cookie.substring(cookie.indexOf("=") + 1, cookie.length()); + cookieToSent = cookieName + "=" + cookieValue; + } + } + } + + // Get the response + StringBuilder response = new StringBuilder(); + BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String line; + try { + while ((line = rd.readLine()) != null) { + response.append(line); + } + } catch (EOFException ex) { + // ignore this exception + System.out.println("EOF exception due to java bug"); + } + rd.close(); + + + + return response.toString(); + + } catch (Exception e) { + throw new CloudRuntimeException("Problem with sending api request", e); + } + } + + protected String createMD5String(String password) { + MessageDigest md5; + try { + md5 = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new CloudRuntimeException("Error", e); + } + + md5.reset(); + BigInteger pwInt = new BigInteger(1, md5.digest(password.getBytes())); + + // make sure our MD5 hash value is 32 digits long... + StringBuffer sb = new StringBuffer(); + String pwStr = pwInt.toString(16); + int padding = 32 - pwStr.length(); + for (int i = 0; i < padding; i++) { + sb.append('0'); + } + sb.append(pwStr); + return sb.toString(); + } + + + protected Object fromSerializedString(String result, Class repCls) { + try { + if (result != null && !result.isEmpty()) { + // get real content + int start; + int end; + if (repCls == LoginResponse.class || repCls == SuccessResponse.class) { + + start = result.indexOf('{', result.indexOf('{') + 1); // find + // the + // second + // { + + end = result.lastIndexOf('}', result.lastIndexOf('}') - 1); // find + // the + // second + // } + // backwards + + } else { + // get real content + start = result.indexOf('{', result.indexOf('{', result.indexOf('{') + 1) + 1); // find + // the + // third + // { + end = result.lastIndexOf('}', result.lastIndexOf('}', result.lastIndexOf('}') - 1) - 1); // find + // the + // third + // } + // backwards + } + if (start < 0 || end < 0) { + throw new CloudRuntimeException("Response format is wrong: " + result); + } + String content = result.substring(start, end + 1); + Gson gson = ApiGsonHelper.getBuilder().create(); + return gson.fromJson(content, repCls); + } + return null; + } catch (RuntimeException e) { + throw new CloudRuntimeException("Caught runtime exception when doing GSON deserialization on: " + result, e); + } + } + + /** + * Login call + * @param username user name + * @param password password (plain password, we will do MD5 hash here for you) + * @return login response string + */ + protected void login(String username, String password) + { + //String md5Psw = createMD5String(password); + // send login request + HashMap params = new HashMap(); + params.put("response", "json"); + params.put("username", username); + params.put("password", password); + String result = this.sendRequest("login", params); + LoginResponse loginResp = (LoginResponse)fromSerializedString(result, LoginResponse.class); + sessionKey = loginResp.getSessionkey(); + + } +} diff --git a/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/LoginResponse.java b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/LoginResponse.java new file mode 100644 index 00000000000..719f39c0a5e --- /dev/null +++ b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/LoginResponse.java @@ -0,0 +1,142 @@ +// 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 +// 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 org.apache.cloudstack.ratelimit.integration; + +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +/** + * Login Response object + * + * @author Min Chen + * + */ +public class LoginResponse extends BaseResponse { + + @SerializedName("timeout") + @Param(description = "session timeout period") + private String timeout; + + @SerializedName("sessionkey") + @Param(description = "login session key") + private String sessionkey; + + @SerializedName("username") + @Param(description = "login username") + private String username; + + @SerializedName("userid") + @Param(description = "login user internal uuid") + private String userid; + + @SerializedName("firstname") + @Param(description = "login user firstname") + private String firstname; + + @SerializedName("lastname") + @Param(description = "login user lastname") + private String lastname; + + @SerializedName("account") + @Param(description = "login user account type") + private String account; + + @SerializedName("domainid") + @Param(description = "login user domain id") + private String domainid; + + @SerializedName("type") + @Param(description = "login user type") + private int type; + + public String getTimeout() { + return timeout; + } + + public void setTimeout(String timeout) { + this.timeout = timeout; + } + + public String getSessionkey() { + return sessionkey; + } + + public void setSessionkey(String sessionkey) { + this.sessionkey = sessionkey; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUserid() { + return userid; + } + + public void setUserid(String userid) { + this.userid = userid; + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getDomainid() { + return domainid; + } + + public void setDomainid(String domainid) { + this.domainid = domainid; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } + + + +} diff --git a/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/RateLimitIntegrationTest.java b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/RateLimitIntegrationTest.java new file mode 100644 index 00000000000..72d354c6c77 --- /dev/null +++ b/plugins/api/rate-limit/test/org/apache/cloudstack/ratelimit/integration/RateLimitIntegrationTest.java @@ -0,0 +1,214 @@ +// 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 +// 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 org.apache.cloudstack.ratelimit.integration; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.apache.cloudstack.api.response.ApiLimitResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.junit.Before; +import org.junit.Test; + +import com.cloud.utils.exception.CloudRuntimeException; + + +/** + * Test fixture to do integration rate limit test. + * Currently we commented out this test suite since it requires a real MS and Db running. + * + * @author Min Chen + * + */ +public class RateLimitIntegrationTest extends APITest { + + private static int apiMax = 25; // assuming ApiRateLimitService set api.throttling.max = 25 + + @Before + public void setup(){ + // always reset count for each testcase + login("admin", "password"); + + // issue reset api limit calls + final HashMap params = new HashMap(); + params.put("response", "json"); + params.put("sessionkey", sessionKey); + String resetResult = sendRequest("resetApiLimit", params); + assertNotNull("Reset count failed!", fromSerializedString(resetResult, SuccessResponse.class)); + + } + + + @Test + public void testNoApiLimitOnRootAdmin() throws Exception { + // issue list Accounts calls + final HashMap params = new HashMap(); + params.put("response", "json"); + params.put("listAll", "true"); + params.put("sessionkey", sessionKey); + // assuming ApiRateLimitService set api.throttling.max = 25 + int clientCount = 26; + Runnable[] clients = new Runnable[clientCount]; + final boolean[] isUsable = new boolean[clientCount]; + + final CountDownLatch startGate = new CountDownLatch(1); + + final CountDownLatch endGate = new CountDownLatch(clientCount); + + + for (int i = 0; i < isUsable.length; ++i) { + final int j = i; + clients[j] = new Runnable() { + + /** + * {@inheritDoc} + */ + @Override + public void run() { + try { + startGate.await(); + + sendRequest("listAccounts", params); + + isUsable[j] = true; + + } catch (CloudRuntimeException e){ + isUsable[j] = false; + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + endGate.countDown(); + } + } + }; + } + + ExecutorService executor = Executors.newFixedThreadPool(clientCount); + + for (Runnable runnable : clients) { + executor.execute(runnable); + } + + startGate.countDown(); + + endGate.await(); + + int rejectCount = 0; + for ( int i = 0; i < isUsable.length; ++i){ + if ( !isUsable[i]) + rejectCount++; + } + + assertEquals("No request should be rejected!", 0, rejectCount); + + } + + + @Test + public void testApiLimitOnUser() throws Exception { + // log in using normal user + login("demo", "password"); + // issue list Accounts calls + final HashMap params = new HashMap(); + params.put("response", "json"); + params.put("listAll", "true"); + params.put("sessionkey", sessionKey); + + int clientCount = apiMax + 1; + Runnable[] clients = new Runnable[clientCount]; + final boolean[] isUsable = new boolean[clientCount]; + + final CountDownLatch startGate = new CountDownLatch(1); + + final CountDownLatch endGate = new CountDownLatch(clientCount); + + + for (int i = 0; i < isUsable.length; ++i) { + final int j = i; + clients[j] = new Runnable() { + + /** + * {@inheritDoc} + */ + @Override + public void run() { + try { + startGate.await(); + + sendRequest("listAccounts", params); + + isUsable[j] = true; + + } catch (CloudRuntimeException e){ + isUsable[j] = false; + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + endGate.countDown(); + } + } + }; + } + + ExecutorService executor = Executors.newFixedThreadPool(clientCount); + + for (Runnable runnable : clients) { + executor.execute(runnable); + } + + startGate.countDown(); + + endGate.await(); + + int rejectCount = 0; + for ( int i = 0; i < isUsable.length; ++i){ + if ( !isUsable[i]) + rejectCount++; + } + + assertEquals("Only one request should be rejected!", 1, rejectCount); + + } + + @Test + public void testGetApiLimitOnUser() throws Exception { + // log in using normal user + login("demo", "password"); + + // issue an api call + HashMap params = new HashMap(); + params.put("response", "json"); + params.put("listAll", "true"); + params.put("sessionkey", sessionKey); + sendRequest("listAccounts", params); + + // issue get api limit calls + final HashMap params2 = new HashMap(); + params2.put("response", "json"); + params2.put("sessionkey", sessionKey); + String getResult = sendRequest("getApiLimit", params2); + ApiLimitResponse getLimitResp = (ApiLimitResponse)fromSerializedString(getResult, ApiLimitResponse.class); + assertEquals("Issued api count is incorrect!", 2, getLimitResp.getApiIssued() ); // should be 2 apis issues plus this getlimit api + assertEquals("Allowed api count is incorrect!", apiMax -2, getLimitResp.getApiAllowed()); + } +} diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java index e6f2f7f376a..b897df2ecf3 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java @@ -33,6 +33,7 @@ import org.libvirt.LibvirtException; import javax.naming.ConfigurationException; import java.net.URI; import java.util.Map; +import java.io.File; public class BridgeVifDriver extends VifDriverBase { @@ -85,6 +86,9 @@ public class BridgeVifDriver extends VifDriverBase { URI broadcastUri = nic.getBroadcastUri(); vlanId = broadcastUri.getHost(); } + else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { + throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver"); + } String trafficLabel = nic.getName(); if (nic.getType() == Networks.TrafficType.Guest) { if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan @@ -172,7 +176,7 @@ public class BridgeVifDriver extends VifDriverBase { createControlNetwork(_bridges.get("linklocal")); } - private void deletExitingLinkLocalRoutTable(String linkLocalBr) { + private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { Script command = new Script("/bin/bash", _timeout); command.add("-c"); command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); @@ -197,7 +201,7 @@ public class BridgeVifDriver extends VifDriverBase { } private void createControlNetwork(String privBrName) { - deletExitingLinkLocalRoutTable(privBrName); + deleteExitingLinkLocalRouteTable(privBrName); if (!isBridgeExists(privBrName)) { Script.runSimpleBashScript("brctl addbr " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " + privBrName + " 169.254.0.1", _timeout); @@ -206,15 +210,11 @@ public class BridgeVifDriver extends VifDriverBase { } private boolean isBridgeExists(String bridgeName) { - Script command = new Script("/bin/sh", _timeout); - command.add("-c"); - command.add("brctl show|grep " + bridgeName); - final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); - String result = command.execute(parser); - if (result != null || parser.getLine() == null) { - return false; - } else { + File f = new File("/sys/devices/virtual/net/" + bridgeName); + if (f.exists()) { return true; + } else { + return false; } } } diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 232806debda..b6d8050bf0d 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -363,10 +363,16 @@ ServerResource { private int _dom0MinMem; + protected enum BridgeType { + NATIVE, OPENVSWITCH + } + protected enum defineOps { UNDEFINE_VM, DEFINE_VM } + protected BridgeType _bridgeType; + private String getEndIpFromStartIp(String startIp, int numIps) { String[] tokens = startIp.split("[.]"); assert (tokens.length == 4); @@ -467,6 +473,14 @@ ServerResource { storageScriptsDir = getDefaultStorageScriptsDir(); } + String bridgeType = (String) params.get("network.bridge.type"); + if (bridgeType == null) { + _bridgeType = BridgeType.NATIVE; + } + else { + _bridgeType = BridgeType.valueOf(bridgeType.toUpperCase()); + } + params.put("domr.scripts.dir", domrScriptsDir); _virtRouterResource = new VirtualRoutingResource(); @@ -650,6 +664,13 @@ ServerResource { Connect conn = null; try { conn = LibvirtConnection.getConnection(); + + if (_bridgeType == BridgeType.OPENVSWITCH) { + if (conn.getLibVirVersion() < (9 * 1000 + 11)) { + throw new ConfigurationException("LibVirt version 0.9.11 required for openvswitch support, but version " + + conn.getLibVirVersion() + " detected"); + } + } } catch (LibvirtException e) { throw new CloudRuntimeException(e.getMessage()); } @@ -695,7 +716,16 @@ ServerResource { } } + switch (_bridgeType) { + case OPENVSWITCH: + getOvsPifs(); + break; + case NATIVE: + default: getPifs(); + break; + } + if (_pifs.get("private") == null) { s_logger.debug("Failed to get private nic name"); throw new ConfigurationException("Failed to get private nic name"); @@ -754,9 +784,14 @@ ServerResource { // Load the vif driver String vifDriverName = (String) params.get("libvirt.vif.driver"); if (vifDriverName == null) { + if (_bridgeType == BridgeType.OPENVSWITCH) { + s_logger.info("No libvirt.vif.driver specififed. Defaults to OvsVifDriver."); + vifDriverName = "com.cloud.hypervisor.kvm.resource.OvsVifDriver"; + } else { s_logger.info("No libvirt.vif.driver specififed. Defaults to BridgeVifDriver."); vifDriverName = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; } + } params.put("libvirt.computing.resource", this); @@ -772,15 +807,23 @@ ServerResource { throw new ConfigurationException("Failed to initialize libvirt.vif.driver " + e); } - return true; } private void getPifs() { - /* gather all available bridges and find their pifs, so that we can match them against traffic labels later */ - String cmdout = Script.runSimpleBashScript("brctl show | tail -n +2 | grep -v \"^\\s\"|awk '{print $1}'|sed '{:q;N;s/\\n/%/g;t q}'"); - s_logger.debug("cmdout was " + cmdout); - List bridges = Arrays.asList(cmdout.split("%")); + File dir = new File("/sys/devices/virtual/net"); + File[] netdevs = dir.listFiles(); + List bridges = new ArrayList(); + for (int i = 0; i < netdevs.length; i++) { + File isbridge = new File(netdevs[i].getAbsolutePath() + "/bridge"); + String netdevName = netdevs[i].getName(); + s_logger.debug("looking in file " + netdevs[i].getAbsolutePath() + "/bridge"); + if (isbridge.exists()) { + s_logger.debug("Found bridge " + netdevName); + bridges.add(netdevName); + } + } + for (String bridge : bridges) { s_logger.debug("looking for pif for bridge " + bridge); String pif = getPif(bridge); @@ -795,31 +838,115 @@ ServerResource { s_logger.debug("done looking for pifs, no more bridges"); } - private String getPif(String bridge) { - String pif = Script.runSimpleBashScript("brctl show | grep " + bridge + " | awk '{print $4}'"); - String vlan = Script.runSimpleBashScript("ls /proc/net/vlan/" + pif); + private void getOvsPifs() { + String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'"); + s_logger.debug("cmdout was " + cmdout); + List bridges = Arrays.asList(cmdout.split("%")); + for (String bridge : bridges) { + s_logger.debug("looking for pif for bridge " + bridge); + // String pif = getOvsPif(bridge); + // Not really interested in the pif name at this point for ovs + // bridges + String pif = bridge; + if (_publicBridgeName != null && bridge.equals(_publicBridgeName)) { + _pifs.put("public", pif); + } + if (_guestBridgeName != null && bridge.equals(_guestBridgeName)) { + _pifs.put("private", pif); + } + _pifs.put(bridge, pif); + } + s_logger.debug("done looking for pifs, no more bridges"); + } - if (vlan != null && !vlan.isEmpty()) { - pif = Script.runSimpleBashScript("grep ^Device\\: /proc/net/vlan/" + pif + " | awk {'print $2'}"); + private String getPif(String bridge) { + String pif = matchPifFileInDirectory(bridge); + File vlanfile = new File("/proc/net/vlan" + pif); + + if (vlanfile.isFile()) { + pif = Script.runSimpleBashScript("grep ^Device\\: /proc/net/vlan/" + + pif + " | awk {'print $2'}"); } return pif; } + private String getOvsPif(String bridge) { + String pif = Script.runSimpleBashScript("ovs-vsctl list-ports " + bridge); + return pif; + } + + private String matchPifFileInDirectory(String bridgeName){ + File f = new File("/sys/devices/virtual/net/" + bridgeName + "/brif"); + + if (! f.isDirectory()){ + s_logger.debug("failing to get physical interface from bridge" + + bridgeName + ", does " + f.getAbsolutePath() + + "exist?"); + return ""; + } + + File[] interfaces = f.listFiles(); + + for (int i = 0; i < interfaces.length; i++) { + String fname = interfaces[i].getName(); + s_logger.debug("matchPifFileInDirectory: file name '"+fname+"'"); + if (fname.startsWith("eth") || fname.startsWith("bond") + || fname.startsWith("vlan")) { + return fname; + } + } + + s_logger.debug("failing to get physical interface from bridge" + + bridgeName + ", did not find an eth*, bond*, or vlan* in " + + f.getAbsolutePath()); + return ""; + } + + private boolean checkNetwork(String networkName) { if (networkName == null) { return true; } - String name = Script.runSimpleBashScript("brctl show | grep " - + networkName + " | awk '{print $4}'"); - if (name == null) { + if (_bridgeType == BridgeType.OPENVSWITCH) { + return checkOvsNetwork(networkName); + } else { + return checkBridgeNetwork(networkName); + } + } + + private boolean checkBridgeNetwork(String networkName) { + if (networkName == null) { + return true; + } + + String name = matchPifFileInDirectory(networkName); + + if (name == null || name.isEmpty()) { return false; } else { return true; } } + private boolean checkOvsNetwork(String networkName) { + s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge"); + if (networkName == null) { + return true; + } + + Script command = new Script("/bin/sh", _timeout); + command.add("-c"); + command.add("ovs-vsctl br-exists " + networkName); + String result = command.execute(null); + if ("Ok".equals(result)) { + return true; + } else { + return false; + } + } + private String getVnetId(String vnetId) { return vnetId; } @@ -1370,20 +1497,15 @@ ServerResource { } private String getVlanIdFromBridge(String brName) { - OutputInterpreter.OneLineParser vlanIdParser = new OutputInterpreter.OneLineParser(); - final Script cmd = new Script("/bin/bash", s_logger); - cmd.add("-c"); - cmd.add("vlanid=$(brctl show |grep " + brName - + " |awk '{print $4}' | cut -s -d. -f 2);echo $vlanid"); - String result = cmd.execute(vlanIdParser); - if (result != null) { - return null; - } - String vlanId = vlanIdParser.getLine(); - if (vlanId.equalsIgnoreCase("")) { - return null; + String pif= matchPifFileInDirectory(brName); + String[] pifparts = pif.split("\\."); + + if(pifparts.length == 2) { + return pifparts[1]; } else { - return vlanId; + s_logger.debug("failed to get vlan id from bridge " + brName + + "attached to physical interface" + pif); + return ""; } } @@ -1608,20 +1730,17 @@ ServerResource { String pluggedVlan = pluggedNic.getBrName(); if (pluggedVlan.equalsIgnoreCase(_linkLocalBridgeName)) { vlanToNicNum.put("LinkLocal",devNum); - } - else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName) + } else if (pluggedVlan.equalsIgnoreCase(_publicBridgeName) || pluggedVlan.equalsIgnoreCase(_privBridgeName) || pluggedVlan.equalsIgnoreCase(_guestBridgeName)) { vlanToNicNum.put(Vlan.UNTAGGED,devNum); - } - else { + } else { vlanToNicNum.put(getVlanIdFromBridge(pluggedVlan),devNum); } devNum++; } for (IpAddressTO ip : ips) { - String ipVlan = ip.getVlanId(); String nicName = "eth" + vlanToNicNum.get(ip.getVlanId()); String netmask = Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask())); String subnet = NetUtils.getSubNet(ip.getPublicIp(), ip.getVlanNetmask()); diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index ba6c715e455..acfd9cf1fe8 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -646,6 +646,9 @@ public class LibvirtVMDef { private String _ipAddr; private String _scriptPath; private nicModel _model; + private String _virtualPortType; + private String _virtualPortInterfaceId; + private int _vlanTag = -1; public void defBridgeNet(String brName, String targetBrName, String macAddr, nicModel model) { @@ -695,7 +698,31 @@ public class LibvirtVMDef { public String getMacAddress() { return _macAddr; } + + public void setVirtualPortType(String virtualPortType) { + _virtualPortType = virtualPortType; + } + public String getVirtualPortType() { + return _virtualPortType; + } + + public void setVirtualPortInterfaceId(String virtualPortInterfaceId) { + _virtualPortInterfaceId = virtualPortInterfaceId; + } + + public String getVirtualPortInterfaceId() { + return _virtualPortInterfaceId; + } + + public void setVlanTag(int vlanTag) { + _vlanTag = vlanTag; + } + + public int getVlanTag() { + return _vlanTag; + } + @Override public String toString() { StringBuilder netBuilder = new StringBuilder(); @@ -714,6 +741,16 @@ public class LibvirtVMDef { if (_model != null) { netBuilder.append("\n"); } + if (_virtualPortType != null) { + netBuilder.append("\n"); + if (_virtualPortInterfaceId != null) { + netBuilder.append("\n"); + } + netBuilder.append("\n"); + } + if (_vlanTag > 0 && _vlanTag < 4095) { + netBuilder.append("\n\n"); + } netBuilder.append("\n"); return netBuilder.toString(); } diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java new file mode 100644 index 00000000000..37761aa5555 --- /dev/null +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.cloud.hypervisor.kvm.resource; + +import java.net.URI; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; +import org.libvirt.LibvirtException; + +import com.cloud.agent.api.to.NicTO; +import com.cloud.exception.InternalErrorException; +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef; +import com.cloud.network.Networks; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.net.NetUtils; +import com.cloud.utils.script.OutputInterpreter; +import com.cloud.utils.script.Script; + +public class OvsVifDriver extends VifDriverBase { + private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class); + private int _timeout; + private String _modifyVlanPath; + + @Override + public void configure(Map params) throws ConfigurationException { + super.configure(params); + + String networkScriptsDir = (String) params.get("network.scripts.dir"); + if (networkScriptsDir == null) { + networkScriptsDir = "scripts/vm/network/vnet"; + } + + String value = (String) params.get("scripts.timeout"); + _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000; + + _modifyVlanPath = Script.findScript(networkScriptsDir, "modifyvlan.sh"); + if (_modifyVlanPath == null) { + throw new ConfigurationException("Unable to find modifyvlan.sh"); + } + + createControlNetwork(_bridges.get("linklocal")); + } + + @Override + public InterfaceDef plug(NicTO nic, String guestOsType) + throws InternalErrorException, LibvirtException { + s_logger.debug("plugging nic=" + nic); + + LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef(); + intf.setVirtualPortType("openvswitch"); + + String vlanId = null; + String logicalSwitchUuid = null; + if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) { + URI broadcastUri = nic.getBroadcastUri(); + vlanId = broadcastUri.getHost(); + } + else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { + logicalSwitchUuid = nic.getBroadcastUri().getSchemeSpecificPart(); + } + String trafficLabel = nic.getName(); + if (nic.getType() == Networks.TrafficType.Guest) { + if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan + && !vlanId.equalsIgnoreCase("untagged")) { + if(trafficLabel != null && !trafficLabel.isEmpty()) { + s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); + intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } else { + intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } + } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { + s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid); + intf.setVirtualPortInterfaceId(nic.getUuid()); + String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); + intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType)); + } + else { + intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } + } else if (nic.getType() == Networks.TrafficType.Control) { + /* Make sure the network is still there */ + createControlNetwork(_bridges.get("linklocal")); + intf.defBridgeNet(_bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } else if (nic.getType() == Networks.TrafficType.Public) { + if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan + && !vlanId.equalsIgnoreCase("untagged")) { + if(trafficLabel != null && !trafficLabel.isEmpty()){ + s_logger.debug("creating a vlan dev and bridge for public traffic per traffic label " + trafficLabel); + intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } else { + intf.defBridgeNet(_pifs.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType)); + intf.setVlanTag(Integer.parseInt(vlanId)); + } + } else { + intf.defBridgeNet(_bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } + } else if (nic.getType() == Networks.TrafficType.Management) { + intf.defBridgeNet(_bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType)); + } else if (nic.getType() == Networks.TrafficType.Storage) { + String storageBrName = nic.getName() == null ? _bridges.get("private") + : nic.getName(); + intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType)); + } + return intf; + } + + @Override + public void unplug(InterfaceDef iface) { + // Libvirt apparently takes care of this, see BridgeVifDriver unplug + } + + private String setVnetBrName(String pifName, String vnetId) { + String brName = "br" + pifName + "-"+ vnetId; + String oldStyleBrName = "cloudVirBr" + vnetId; + + if (isBridgeExists(oldStyleBrName)) { + s_logger.info("Using old style bridge name for vlan " + vnetId + " because existing bridge " + oldStyleBrName + " was found"); + brName = oldStyleBrName; + } + + return brName; + } + + private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { + Script command = new Script("/bin/bash", _timeout); + command.add("-c"); + command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); + OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); + String result = command.execute(parser); + boolean foundLinkLocalBr = false; + if (result == null && parser.getLines() != null) { + String[] lines = parser.getLines().split("\\n"); + for (String line : lines) { + String[] tokens = line.split(" "); + if (!tokens[2].equalsIgnoreCase(linkLocalBr)) { + Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR()); + } else { + foundLinkLocalBr = true; + } + } + } + if (!foundLinkLocalBr) { + Script.runSimpleBashScript("ifconfig " + linkLocalBr + " 169.254.0.1;" + "ip route add " + + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway()); + } + } + + private void createControlNetwork(String privBrName) { + deleteExitingLinkLocalRouteTable(privBrName); + if (!isBridgeExists(privBrName)) { + Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ifconfig " + privBrName + " up; ifconfig " + + privBrName + " 169.254.0.1", _timeout); + } + } + + private boolean isBridgeExists(String bridgeName) { + Script command = new Script("/bin/sh", _timeout); + command.add("-c"); + command.add("ovs-vsctl br-exists " + bridgeName); + String result = command.execute(null); + if ("Ok".equals(result)) { + return true; + } else { + return false; + } + } +} diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java index ac611275e5a..c2bfad9feef 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java @@ -38,6 +38,10 @@ public class KVMStoragePoolManager { private final Map _storageMapper = new HashMap(); private StorageAdaptor getStorageAdaptor(StoragePoolType type) { + // type can be null: LibVirtComputingResource:3238 + if (type == null) { + return _storageMapper.get("libvirt"); + } StorageAdaptor adaptor = _storageMapper.get(type.toString()); if (adaptor == null) { // LibvirtStorageAdaptor is selected by default diff --git a/plugins/pom.xml b/plugins/pom.xml index 61c43bdebc4..63839a2e2b5 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -32,6 +32,7 @@ test + api/rate-limit api/discovery acl/static-role-based deployment-planners/user-concentrated-pod diff --git a/scripts/vm/hypervisor/kvm/rundomrpre.sh b/scripts/vm/hypervisor/kvm/rundomrpre.sh index f3019dc2d0a..dc783749815 100755 --- a/scripts/vm/hypervisor/kvm/rundomrpre.sh +++ b/scripts/vm/hypervisor/kvm/rundomrpre.sh @@ -71,7 +71,7 @@ umount_raw_disk() { sync while [ $retry -gt 0 ] do - umount $path &>/dev/null + umount -d $path &>/dev/null if [ $? -gt 0 ] then sleep 5 diff --git a/server/pom.xml b/server/pom.xml index 8592f27e4b7..5160a8d09af 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -120,6 +120,7 @@ com/cloud/vm/dao/* com/cloud/vpc/* com/cloud/api/ListPerfTest.java + com/cloud/network/vpn/RemoteAccessVpnTest.java diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index cb6dc6fae0c..a464b936b88 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -29,6 +29,7 @@ import org.apache.cloudstack.api.ApiConstants.HostDetails; import org.apache.cloudstack.api.ApiConstants.VMDetails; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; +import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.DomainRouterResponse; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.HostResponse; @@ -38,14 +39,19 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceTagResponse; import org.apache.cloudstack.api.response.SecurityGroupResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; + import org.springframework.stereotype.Component; import com.cloud.api.query.dao.AccountJoinDao; import com.cloud.api.query.dao.AsyncJobJoinDao; +import com.cloud.api.query.dao.DataCenterJoinDao; +import com.cloud.api.query.dao.DiskOfferingJoinDao; import com.cloud.api.query.dao.DomainRouterJoinDao; import com.cloud.api.query.dao.HostJoinDao; import com.cloud.api.query.dao.InstanceGroupJoinDao; @@ -54,12 +60,15 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDao; import com.cloud.api.query.dao.ProjectJoinDao; import com.cloud.api.query.dao.ResourceTagJoinDao; import com.cloud.api.query.dao.SecurityGroupJoinDao; +import com.cloud.api.query.dao.ServiceOfferingJoinDao; import com.cloud.api.query.dao.StoragePoolJoinDao; import com.cloud.api.query.dao.UserAccountJoinDao; import com.cloud.api.query.dao.UserVmJoinDao; import com.cloud.api.query.dao.VolumeJoinDao; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; import com.cloud.api.query.vo.HostJoinVO; @@ -69,6 +78,7 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO; import com.cloud.api.query.vo.ProjectJoinVO; import com.cloud.api.query.vo.ResourceTagJoinVO; import com.cloud.api.query.vo.SecurityGroupJoinVO; +import com.cloud.api.query.vo.ServiceOfferingJoinVO; import com.cloud.api.query.vo.StoragePoolJoinVO; import com.cloud.api.query.vo.UserAccountJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; @@ -86,6 +96,7 @@ import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.Vlan; @@ -168,6 +179,7 @@ import com.cloud.network.vpc.dao.StaticRouteDao; import com.cloud.network.vpc.dao.VpcDao; import com.cloud.network.vpc.dao.VpcGatewayDao; import com.cloud.network.vpc.dao.VpcOfferingDao; +import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; import com.cloud.offerings.NetworkOfferingVO; @@ -268,6 +280,8 @@ public class ApiDBUtils { static ClusterDao _clusterDao; static CapacityDao _capacityDao; static DiskOfferingDao _diskOfferingDao; + static DiskOfferingJoinDao _diskOfferingJoinDao; + static DataCenterJoinDao _dcJoinDao; static DomainDao _domainDao; static DomainRouterDao _domainRouterDao; static DomainRouterJoinDao _domainRouterJoinDao; @@ -278,6 +292,7 @@ public class ApiDBUtils { static LoadBalancerDao _loadBalancerDao; static SecurityGroupDao _securityGroupDao; static SecurityGroupJoinDao _securityGroupJoinDao; + static ServiceOfferingJoinDao _serviceOfferingJoinDao; static NetworkRuleConfigDao _networkRuleConfigDao; static HostPodDao _podDao; static ServiceOfferingDao _serviceOfferingDao; @@ -361,7 +376,9 @@ public class ApiDBUtils { @Inject private AccountVlanMapDao accountVlanMapDao; @Inject private ClusterDao clusterDao; @Inject private CapacityDao capacityDao; + @Inject private DataCenterJoinDao dcJoinDao; @Inject private DiskOfferingDao diskOfferingDao; + @Inject private DiskOfferingJoinDao diskOfferingJoinDao; @Inject private DomainDao domainDao; @Inject private DomainRouterDao domainRouterDao; @Inject private DomainRouterJoinDao domainRouterJoinDao; @@ -372,6 +389,7 @@ public class ApiDBUtils { @Inject private LoadBalancerDao loadBalancerDao; @Inject private SecurityGroupDao securityGroupDao; @Inject private SecurityGroupJoinDao securityGroupJoinDao; + @Inject private ServiceOfferingJoinDao serviceOfferingJoinDao; @Inject private NetworkRuleConfigDao networkRuleConfigDao; @Inject private HostPodDao podDao; @Inject private ServiceOfferingDao serviceOfferingDao; @@ -457,7 +475,9 @@ public class ApiDBUtils { _accountVlanMapDao = accountVlanMapDao; _clusterDao = clusterDao; _capacityDao = capacityDao; + _dcJoinDao = dcJoinDao; _diskOfferingDao = diskOfferingDao; + _diskOfferingJoinDao = diskOfferingJoinDao; _domainDao = domainDao; _domainRouterDao = domainRouterDao; _domainRouterJoinDao = domainRouterJoinDao; @@ -469,6 +489,7 @@ public class ApiDBUtils { _networkRuleConfigDao = networkRuleConfigDao; _podDao = podDao; _serviceOfferingDao = serviceOfferingDao; + _serviceOfferingJoinDao = serviceOfferingJoinDao; _snapshotDao = snapshotDao; _storagePoolDao = storagePoolDao; _templateDao = templateDao; @@ -1497,4 +1518,28 @@ public class ApiDBUtils { public static AsyncJobJoinVO newAsyncJobView(AsyncJob e){ return _jobJoinDao.newAsyncJobView(e); } + + public static DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering) { + return _diskOfferingJoinDao.newDiskOfferingResponse(offering); + } + + public static DiskOfferingJoinVO newDiskOfferingView(DiskOffering offering){ + return _diskOfferingJoinDao.newDiskOfferingView(offering); + } + + public static ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering) { + return _serviceOfferingJoinDao.newServiceOfferingResponse(offering); + } + + public static ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering){ + return _serviceOfferingJoinDao.newServiceOfferingView(offering); + } + + public static ZoneResponse newDataCenterResponse(DataCenterJoinVO dc, Boolean showCapacities) { + return _dcJoinDao.newDataCenterResponse(dc, showCapacities); + } + + public static DataCenterJoinVO newDataCenterView(DataCenter dc){ + return _dcJoinDao.newDataCenterView(dc); + } } diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index eae07bae1db..8e3c5e01bfd 100755 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -26,6 +26,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Matcher; @@ -148,8 +149,7 @@ public class ApiDispatcher { } if (queueSizeLimit != null) { - _asyncMgr - .syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit); + _asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit); } else { s_logger.trace("The queue size is unlimited, skipping the synchronizing"); } @@ -183,8 +183,7 @@ public class ApiDispatcher { } } - Field[] fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), - new Class[] {BaseCmd.class}); + List fields = ReflectUtil.getAllFieldsForClass(cmd.getClass(), BaseCmd.class); for (Field field : fields) { Parameter parameterAnnotation = field.getAnnotation(Parameter.class); @@ -349,8 +348,9 @@ public class ApiDispatcher { // Go through each entity which is an interface to a VO class and get a VO object // Try to getId() for the object using reflection, break on first non-null value for (Class entity: entities) { - // findByUuid returns one VO object using uuid, use reflect to get the Id - Object objVO = s_instance._entityMgr.findByUuid(entity, uuid); + // For backward compatibility, we search within removed entities and let service layer deal + // with removed ones, return empty response or error + Object objVO = s_instance._entityMgr.findByUuidIncludingRemoved(entity, uuid); if (objVO == null) { continue; } @@ -366,11 +366,10 @@ public class ApiDispatcher { break; } if (internalId == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Object entity with uuid=" + uuid + " does not exist in the database."); - } + if (s_logger.isDebugEnabled()) + s_logger.debug("Object entity uuid = " + uuid + " does not exist in the database."); throw new InvalidParameterValueException("Invalid parameter value=" + uuid - + " due to incorrect long value, entity not found, or an annotation bug."); + + " due to incorrect long value format, or entity was not found as it may have been deleted, or due to incorrect parameter annotation for the field in api cmd."); } return internalId; } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index f4c4a4274a6..61f906bc0c5 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -44,6 +44,8 @@ import com.cloud.api.query.ViewResponseHelper; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; import com.cloud.api.query.vo.ControlledViewEntity; +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; import com.cloud.api.query.vo.HostJoinVO; @@ -53,6 +55,7 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO; import com.cloud.api.query.vo.ProjectJoinVO; import com.cloud.api.query.vo.ResourceTagJoinVO; import com.cloud.api.query.vo.SecurityGroupJoinVO; +import com.cloud.api.query.vo.ServiceOfferingJoinVO; import com.cloud.api.query.vo.StoragePoolJoinVO; import com.cloud.api.query.vo.UserAccountJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; @@ -301,24 +304,8 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public DiskOfferingResponse createDiskOfferingResponse(DiskOffering offering) { - DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse(); - diskOfferingResponse.setId(offering.getUuid()); - diskOfferingResponse.setName(offering.getName()); - diskOfferingResponse.setDisplayText(offering.getDisplayText()); - diskOfferingResponse.setCreated(offering.getCreated()); - diskOfferingResponse.setDiskSize(offering.getDiskSize() / (1024 * 1024 * 1024)); - if (offering.getDomainId() != null) { - Domain domain = ApiDBUtils.findDomainById(offering.getDomainId()); - if (domain != null) { - diskOfferingResponse.setDomain(domain.getName()); - diskOfferingResponse.setDomainId(domain.getUuid()); - } - } - diskOfferingResponse.setTags(offering.getTags()); - diskOfferingResponse.setCustomized(offering.isCustomized()); - diskOfferingResponse.setStorageType(offering.getUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString()); - diskOfferingResponse.setObjectName("diskoffering"); - return diskOfferingResponse; + DiskOfferingJoinVO vOffering = ApiDBUtils.newDiskOfferingView(offering); + return ApiDBUtils.newDiskOfferingResponse(vOffering); } @Override @@ -360,33 +347,8 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public ServiceOfferingResponse createServiceOfferingResponse(ServiceOffering offering) { - ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse(); - offeringResponse.setId(offering.getUuid()); - offeringResponse.setName(offering.getName()); - offeringResponse.setIsSystemOffering(offering.getSystemUse()); - offeringResponse.setDefaultUse(offering.getDefaultUse()); - offeringResponse.setSystemVmType(offering.getSystemVmType()); - offeringResponse.setDisplayText(offering.getDisplayText()); - offeringResponse.setCpuNumber(offering.getCpu()); - offeringResponse.setCpuSpeed(offering.getSpeed()); - offeringResponse.setMemory(offering.getRamSize()); - offeringResponse.setCreated(offering.getCreated()); - offeringResponse.setStorageType(offering.getUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString()); - offeringResponse.setOfferHa(offering.getOfferHA()); - offeringResponse.setLimitCpuUse(offering.getLimitCpuUse()); - offeringResponse.setTags(offering.getTags()); - if (offering.getDomainId() != null) { - Domain domain = ApiDBUtils.findDomainById(offering.getDomainId()); - if (domain != null) { - offeringResponse.setDomain(domain.getName()); - offeringResponse.setDomainId(domain.getUuid()); - } - } - offeringResponse.setNetworkRate(offering.getRateMbps()); - offeringResponse.setHostTag(offering.getHostTag()); - offeringResponse.setObjectName("serviceoffering"); - - return offeringResponse; + ServiceOfferingJoinVO vOffering = ApiDBUtils.newServiceOfferingView(offering); + return ApiDBUtils.newServiceOfferingResponse(vOffering); } @Override @@ -759,28 +721,12 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities) { - Account account = UserContext.current().getCaller(); - ZoneResponse zoneResponse = new ZoneResponse(); - zoneResponse.setId(dataCenter.getUuid()); - zoneResponse.setName(dataCenter.getName()); - zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId())); - zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled()); - - if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) { - zoneResponse.setDescription(dataCenter.getDescription()); + DataCenterJoinVO vOffering = ApiDBUtils.newDataCenterView(dataCenter); + return ApiDBUtils.newDataCenterResponse(vOffering, showCapacities); } - if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { - zoneResponse.setDns1(dataCenter.getDns1()); - zoneResponse.setDns2(dataCenter.getDns2()); - zoneResponse.setInternalDns1(dataCenter.getInternalDns1()); - zoneResponse.setInternalDns2(dataCenter.getInternalDns2()); - // FIXME zoneResponse.setVlan(dataCenter.get.getVnet()); - zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr()); - } - - if (showCapacities != null && showCapacities) { - List capacities = ApiDBUtils.getCapacityByClusterPodZone(dataCenter.getId(), null, null); + public static List getDataCenterCapacityResponse(Long zoneId){ + List capacities = ApiDBUtils.getCapacityByClusterPodZone(zoneId, null, null); Set capacityResponses = new HashSet(); float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(); @@ -791,7 +737,7 @@ public class ApiResponseHelper implements ResponseGenerator { if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) { capacityResponse.setCapacityTotal(new Long((long) (capacity.getTotalCapacity() * cpuOverprovisioningFactor))); } else if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) { - List c = ApiDBUtils.findNonSharedStorageForClusterPodZone(dataCenter.getId(), null, null); + List c = ApiDBUtils.findNonSharedStorageForClusterPodZone(zoneId, null, null); capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity()); capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity()); } else { @@ -805,31 +751,12 @@ public class ApiResponseHelper implements ResponseGenerator { capacityResponses.add(capacityResponse); } // Do it for stats as well. - capacityResponses.addAll(getStatsCapacityresponse(null, null, null, dataCenter.getId())); + capacityResponses.addAll(getStatsCapacityresponse(null, null, null, zoneId)); - zoneResponse.setCapacitites(new ArrayList(capacityResponses)); - } - - // set network domain info - zoneResponse.setDomain(dataCenter.getDomain()); - - // set domain info - Long domainId = dataCenter.getDomainId(); - if (domainId != null) { - Domain domain = ApiDBUtils.findDomainById(domainId); - zoneResponse.setDomainId(domain.getId()); - zoneResponse.setDomainName(domain.getName()); - } - - zoneResponse.setType(dataCenter.getNetworkType().toString()); - zoneResponse.setAllocationState(dataCenter.getAllocationState().toString()); - zoneResponse.setZoneToken(dataCenter.getZoneToken()); - zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider()); - zoneResponse.setObjectName("zone"); - return zoneResponse; + return new ArrayList(capacityResponses); } - private List getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) { + private static List getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId) { List capacities = new ArrayList(); capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId)); if (clusterId == null && podId == null) { diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index f103e30929a..80fffd3d8fd 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -77,6 +77,7 @@ import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; import org.apache.cloudstack.api.response.ExceptionResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; import org.apache.commons.codec.binary.Base64; import org.apache.http.ConnectionClosedException; import org.apache.http.HttpException; @@ -108,6 +109,8 @@ import org.apache.http.protocol.ResponseServer; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; +import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd; +import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd; import com.cloud.api.response.ApiResponseSerializer; import com.cloud.async.AsyncCommandQueued; import com.cloud.async.AsyncJob; @@ -124,6 +127,7 @@ import com.cloud.exception.CloudAuthenticationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; +import com.cloud.exception.RequestLimitException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; @@ -394,6 +398,7 @@ public class ApiServer implements HttpRequestHandler { if (UserContext.current().getCaller().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); } @@ -510,19 +515,22 @@ public class ApiServer implements HttpRequestHandler { // if the command is of the listXXXCommand, we will need to also return the // the job id and status if possible // For those listXXXCommand which we have already created DB views, this step is not needed since async job is joined in their db views. - if (realCmdObj instanceof BaseListCmd && !(realCmdObj instanceof ListVMsCmd) && !(realCmdObj instanceof ListRoutersCmd) - && !(realCmdObj instanceof ListSecurityGroupsCmd) - && !(realCmdObj instanceof ListTagsCmd) - && !(realCmdObj instanceof ListEventsCmd) - && !(realCmdObj instanceof ListVMGroupsCmd) - && !(realCmdObj instanceof ListProjectsCmd) - && !(realCmdObj instanceof ListProjectAccountsCmd) - && !(realCmdObj instanceof ListProjectInvitationsCmd) - && !(realCmdObj instanceof ListHostsCmd) - && !(realCmdObj instanceof ListVolumesCmd) - && !(realCmdObj instanceof ListUsersCmd) - && !(realCmdObj instanceof ListAccountsCmd) - && !(realCmdObj instanceof ListStoragePoolsCmd) + if (cmdObj instanceof BaseListCmd && !(cmdObj instanceof ListVMsCmd) && !(cmdObj instanceof ListRoutersCmd) + && !(cmdObj instanceof ListSecurityGroupsCmd) + && !(cmdObj instanceof ListTagsCmd) + && !(cmdObj instanceof ListEventsCmd) + && !(cmdObj instanceof ListVMGroupsCmd) + && !(cmdObj instanceof ListProjectsCmd) + && !(cmdObj instanceof ListProjectAccountsCmd) + && !(cmdObj instanceof ListProjectInvitationsCmd) + && !(cmdObj instanceof ListHostsCmd) + && !(cmdObj instanceof ListVolumesCmd) + && !(cmdObj instanceof ListUsersCmd) + && !(cmdObj instanceof ListAccountsCmd) + && !(cmdObj instanceof ListStoragePoolsCmd) + && !(cmdObj instanceof ListDiskOfferingsCmd) + && !(cmdObj instanceof ListServiceOfferingsCmd) + && !(cmdObj instanceof ListZonesByCmd) ) { buildAsyncListResponse((BaseListCmd) cmdObj, caller); } @@ -599,6 +607,7 @@ public class ApiServer implements HttpRequestHandler { // if userId not null, that mean that user is logged in if (userId != null) { User user = ApiDBUtils.findUserById(userId); + try{ checkCommandAvailable(user, commandName); } @@ -606,6 +615,10 @@ public class ApiServer implements HttpRequestHandler { s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId); throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user"); } + catch (RequestLimitException ex){ + s_logger.debug(ex.getMessage()); + throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage()); + } return true; } else { // check against every available command to see if the command exists or not @@ -835,6 +848,7 @@ public class ApiServer implements HttpRequestHandler { return true; } + private void checkCommandAvailable(User user, String commandName) throws PermissionDeniedException { if (user == null) { throw new PermissionDeniedException("User is null for role based API access check for command" + commandName); diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java index c816404d3c4..fcf12a6c996 100755 --- a/server/src/com/cloud/api/ApiServlet.java +++ b/server/src/com/cloud/api/ApiServlet.java @@ -296,13 +296,11 @@ public class ApiServlet extends HttpServlet { * key mechanism updateUserContext(params, session != null ? session.getId() : null); */ - auditTrailSb.insert(0, - "(userId=" + UserContext.current().getCallerUserId() + " accountId=" + UserContext.current().getCaller().getId() + " sessionId=" + (session != null ? session.getId() : null) - + ")"); + auditTrailSb.insert(0, "(userId=" + UserContext.current().getCallerUserId() + " accountId=" + + UserContext.current().getCaller().getId() + " sessionId=" + (session != null ? session.getId() : null) + ")"); String response = _apiServer.handleRequest(params, false, responseType, auditTrailSb); writeResponse(resp, response != null ? response : "", HttpServletResponse.SC_OK, responseType); - } else { if (session != null) { try { diff --git a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java index 84851c389ad..c3c0cabdf17 100644 --- a/server/src/com/cloud/api/doc/ApiXmlDocWriter.java +++ b/server/src/com/cloud/api/doc/ApiXmlDocWriter.java @@ -28,6 +28,7 @@ import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import com.cloud.utils.IteratorUtil; import com.cloud.utils.ReflectUtil; import org.apache.cloudstack.api.*; import org.apache.log4j.Logger; @@ -135,7 +136,7 @@ public class ApiXmlDocWriter { String commandRoleMask = preProcessedCommand.substring(splitIndex + 1); Class cmdClass = _apiNameCmdClassMap.get(key); if (cmdClass == null) { - System.out.println("Check, Null Value for key: " + key + " preProcessedCommand=" + preProcessedCommand); + System.out.println("Check, is this api part of another build profile? Null value for key: " + key + " preProcessedCommand=" + preProcessedCommand); continue; } String commandName = cmdClass.getName(); @@ -349,7 +350,7 @@ public class ApiXmlDocWriter { apiCommand.setAsync(isAsync); - Field[] fields = ReflectUtil.getAllFieldsForClass(clas, + Set fields = ReflectUtil.getAllFieldsForClass(clas, new Class[] {BaseCmd.class, BaseAsyncCmd.class, BaseAsyncCreateCmd.class}); request = setRequestFields(fields); @@ -422,10 +423,10 @@ public class ApiXmlDocWriter { out.writeObject(apiCommand); } - private static ArrayList setRequestFields(Field[] fields) { + private static ArrayList setRequestFields(Set fields) { ArrayList arguments = new ArrayList(); - ArrayList requiredArguments = new ArrayList(); - ArrayList optionalArguments = new ArrayList(); + Set requiredArguments = new HashSet(); + Set optionalArguments = new HashSet(); Argument id = null; for (Field f : fields) { Parameter parameterAnnotation = f.getAnnotation(Parameter.class); @@ -444,7 +445,7 @@ public class ApiXmlDocWriter { reqArg.setSinceVersion(parameterAnnotation.since()); } - if (reqArg.isRequired() == true) { + if (reqArg.isRequired()) { if (parameterAnnotation.name().equals("id")) { id = reqArg; } else { @@ -456,15 +457,12 @@ public class ApiXmlDocWriter { } } - Collections.sort(requiredArguments); - Collections.sort(optionalArguments); - // sort required and optional arguments here if (id != null) { arguments.add(id); } - arguments.addAll(requiredArguments); - arguments.addAll(optionalArguments); + arguments.addAll(IteratorUtil.asSortedList(requiredArguments)); + arguments.addAll(IteratorUtil.asSortedList(optionalArguments)); return arguments; } diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 6760dec2f44..97fd350c7e4 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -18,8 +18,10 @@ package com.cloud.api.query; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import javax.ejb.Local; import javax.inject.Inject; @@ -33,6 +35,8 @@ import org.apache.cloudstack.api.command.user.account.ListAccountsCmd; import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd; import org.apache.cloudstack.api.command.user.event.ListEventsCmd; import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd; +import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd; +import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd; import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd; import org.apache.cloudstack.api.command.user.project.ListProjectsCmd; import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd; @@ -40,8 +44,10 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd; import org.apache.cloudstack.api.command.user.vm.ListVMsCmd; import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd; import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd; +import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; +import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.DomainRouterResponse; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.HostResponse; @@ -52,16 +58,20 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceTagResponse; import org.apache.cloudstack.api.response.SecurityGroupResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.query.QueryService; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.api.query.dao.AccountJoinDao; import com.cloud.api.query.dao.AsyncJobJoinDao; +import com.cloud.api.query.dao.DataCenterJoinDao; +import com.cloud.api.query.dao.DiskOfferingJoinDao; import com.cloud.api.query.dao.DomainRouterJoinDao; import com.cloud.api.query.dao.HostJoinDao; import com.cloud.api.query.dao.InstanceGroupJoinDao; @@ -70,12 +80,15 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDao; import com.cloud.api.query.dao.ProjectJoinDao; import com.cloud.api.query.dao.ResourceTagJoinDao; import com.cloud.api.query.dao.SecurityGroupJoinDao; +import com.cloud.api.query.dao.ServiceOfferingJoinDao; import com.cloud.api.query.dao.StoragePoolJoinDao; import com.cloud.api.query.dao.UserAccountJoinDao; import com.cloud.api.query.dao.UserVmJoinDao; import com.cloud.api.query.dao.VolumeJoinDao; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; import com.cloud.api.query.vo.HostJoinVO; @@ -85,27 +98,34 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO; import com.cloud.api.query.vo.ProjectJoinVO; import com.cloud.api.query.vo.ResourceTagJoinVO; import com.cloud.api.query.vo.SecurityGroupJoinVO; +import com.cloud.api.query.vo.ServiceOfferingJoinVO; import com.cloud.api.query.vo.StoragePoolJoinVO; import com.cloud.api.query.vo.UserAccountJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; import com.cloud.api.query.vo.VolumeJoinVO; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenterVO; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.dao.EventJoinDao; +import com.cloud.exception.CloudAuthenticationException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.security.SecurityGroupVMMapVO; import com.cloud.network.security.dao.SecurityGroupVMMapDao; -import com.cloud.projects.Project; -import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.org.Grouping; import com.cloud.projects.ProjectInvitation; +import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.projects.Project; import com.cloud.projects.ProjectManager; import com.cloud.projects.dao.ProjectAccountDao; import com.cloud.projects.dao.ProjectDao; import com.cloud.server.Criteria; +import com.cloud.service.ServiceOfferingVO; +import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.Volume; import com.cloud.user.Account; import com.cloud.user.AccountManager; @@ -121,14 +141,12 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.vm.DomainRouterVO; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.UserVmDao; -/** - * @author minc - * - */ @Component @Local(value = {QueryService.class }) public class QueryManagerImpl implements QueryService, Manager { @@ -199,6 +217,9 @@ public class QueryManagerImpl implements QueryService, Manager { @Inject private AccountDao _accountDao; + @Inject + private ConfigurationDao _configDao; + @Inject private AccountJoinDao _accountJoinDao; @@ -208,6 +229,21 @@ public class QueryManagerImpl implements QueryService, Manager { @Inject private StoragePoolJoinDao _poolJoinDao; + @Inject + private DiskOfferingJoinDao _diskOfferingJoinDao; + + @Inject + private ServiceOfferingJoinDao _srvOfferingJoinDao; + + @Inject + private ServiceOfferingDao _srvOfferingDao; + + @Inject + private DataCenterJoinDao _dcJoinDao; + + @Inject + private DomainRouterDao _routerDao; + @Inject private HighAvailabilityManager _haMgr; @@ -1602,7 +1638,7 @@ public class QueryManagerImpl implements QueryService, Manager { } - public Pair, Integer> searchForAccountsInternal(ListAccountsCmd cmd) { + private Pair, Integer> searchForAccountsInternal(ListAccountsCmd cmd) { Account caller = UserContext.current().getCaller(); Long domainId = cmd.getDomainId(); Long accountId = cmd.getId(); @@ -1728,7 +1764,7 @@ public class QueryManagerImpl implements QueryService, Manager { } - public Pair, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) { + private Pair, Integer> searchForAsyncJobsInternal(ListAsyncJobsCmd cmd) { Account caller = UserContext.current().getCaller(); @@ -1807,7 +1843,7 @@ public class QueryManagerImpl implements QueryService, Manager { return response; } - public Pair, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) { + private Pair, Integer> searchForStoragePoolsInternal(ListStoragePoolsCmd cmd) { Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), cmd.getZoneId()); Object id = cmd.getId(); @@ -1887,5 +1923,426 @@ public class QueryManagerImpl implements QueryService, Manager { } + @Override + public ListResponse searchForDiskOfferings(ListDiskOfferingsCmd cmd) { + Pair, Integer> result = searchForDiskOfferingsInternal(cmd); + ListResponse response = new ListResponse(); + List offeringResponses = ViewResponseHelper.createDiskOfferingResponse(result.first().toArray(new DiskOfferingJoinVO[result.first().size()])); + response.setResponses(offeringResponses, result.second()); + return response; + } + + private Pair, Integer> searchForDiskOfferingsInternal(ListDiskOfferingsCmd cmd) { + // Note + // The list method for offerings is being modified in accordance with + // discussion with Will/Kevin + // For now, we will be listing the following based on the usertype + // 1. For root, we will list all offerings + // 2. For domainAdmin and regular users, we will list everything in + // their domains+parent domains ... all the way + // till + // root + + Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); + isAscending = (isAscending == null ? true : isAscending); + Filter searchFilter = new Filter(DiskOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchBuilder sb = _diskOfferingJoinDao.createSearchBuilder(); + + + Account account = UserContext.current().getCaller(); + Object name = cmd.getDiskOfferingName(); + Object id = cmd.getId(); + Object keyword = cmd.getKeyword(); + Long domainId = cmd.getDomainId(); + // Keeping this logic consistent with domain specific zones + // if a domainId is provided, we just return the disk offering + // associated with this domain + if (domainId != null) { + if (account.getType() == Account.ACCOUNT_TYPE_ADMIN || isPermissible(account.getDomainId(), domainId) ) { + // check if the user's domain == do's domain || user's domain is + // a child of so's domain for non-root users + sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ); + SearchCriteria sc = sb.create(); + sc.setParameters("domainId", domainId); + return _diskOfferingJoinDao.searchAndCount(sc, searchFilter); + } else { + throw new PermissionDeniedException("The account:" + account.getAccountName() + + " does not fall in the same domain hierarchy as the disk offering"); + } + } + + sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + + + boolean includePublicOfferings = false; + List domainIds = null; + // For non-root users, only return all offerings for the user's domain, and everything above till root + if ((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) + || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { + // find all domain Id up to root domain for this account + domainIds = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + if ( domainRecord == null ){ + s_logger.error("Could not find the domainId for account:" + account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); + } + domainIds.add(domainRecord.getId()); + while (domainRecord.getParent() != null ){ + domainRecord = _domainDao.findById(domainRecord.getParent()); + domainIds.add(domainRecord.getId()); + } + sb.and("domainIdIn", sb.entity().getDomainId(), SearchCriteria.Op.IN); + + // include also public offering if no keyword, name and id specified + if ( keyword == null && name == null && id == null ){ + includePublicOfferings = true; + } + } + + SearchCriteria sc = sb.create(); + if (keyword != null) { + SearchCriteria ssc = _diskOfferingJoinDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (name != null) { + sc.setParameters("name", "%" + name + "%"); + } + + if (id != null) { + sc.setParameters("id", id); + } + + if (domainIds != null ){ + sc.setParameters("domainIdIn", domainIds); + } + + if (includePublicOfferings){ + SearchCriteria spc = _diskOfferingJoinDao.createSearchCriteria(); + spc.addAnd("domainId", SearchCriteria.Op.NULL); + spc.addAnd("systemUse", SearchCriteria.Op.EQ, false); + + sc.addOr("systemUse", SearchCriteria.Op.SC, spc); + } + + // FIXME: disk offerings should search back up the hierarchy for + // available disk offerings... + /* + * sb.addAnd("domainId", sb.entity().getDomainId(), + * SearchCriteria.Op.EQ); if (domainId != null) { + * SearchBuilder domainSearch = + * _domainDao.createSearchBuilder(); domainSearch.addAnd("path", + * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE); + * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), + * domainSearch.entity().getId()); } + */ + + // FIXME: disk offerings should search back up the hierarchy for + // available disk offerings... + /* + * if (domainId != null) { sc.setParameters("domainId", domainId); // + * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want + * to join on user_vm.domain_id = domain.id where domain.path like + * 'foo%' //sc.setJoinParameters("domainSearch", "path", + * domain.getPath() + "%"); // } + */ + + return _diskOfferingJoinDao.searchAndCount(sc, searchFilter); + } + + + + @Override + public ListResponse searchForServiceOfferings(ListServiceOfferingsCmd cmd) { + Pair, Integer> result = searchForServiceOfferingsInternal(cmd); + ListResponse response = new ListResponse(); + List offeringResponses = ViewResponseHelper.createServiceOfferingResponse(result.first().toArray(new ServiceOfferingJoinVO[result.first().size()])); + response.setResponses(offeringResponses, result.second()); + return response; + } + + private Pair, Integer> searchForServiceOfferingsInternal(ListServiceOfferingsCmd cmd) { + // Note + // The list method for offerings is being modified in accordance with + // discussion with Will/Kevin + // For now, we will be listing the following based on the usertype + // 1. For root, we will list all offerings + // 2. For domainAdmin and regular users, we will list everything in + // their domains+parent domains ... all the way + // till + // root + Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); + isAscending = (isAscending == null ? true : isAscending); + Filter searchFilter = new Filter(ServiceOfferingJoinVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _srvOfferingJoinDao.createSearchCriteria(); + + Account caller = UserContext.current().getCaller(); + Object name = cmd.getServiceOfferingName(); + Object id = cmd.getId(); + Object keyword = cmd.getKeyword(); + Long vmId = cmd.getVirtualMachineId(); + Long domainId = cmd.getDomainId(); + Boolean isSystem = cmd.getIsSystem(); + String vmTypeStr = cmd.getSystemVmType(); + + if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) { + throw new InvalidParameterValueException("Only ROOT admins can access system's offering"); + } + + // Keeping this logic consistent with domain specific zones + // if a domainId is provided, we just return the so associated with this + // domain + if (domainId != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { + // check if the user's domain == so's domain || user's domain is a + // child of so's domain + if (!isPermissible(caller.getDomainId(), domainId)) { + throw new PermissionDeniedException("The account:" + caller.getAccountName() + + " does not fall in the same domain hierarchy as the service offering"); + } + } + + boolean includePublicOfferings = false; + if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) + || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { + // For non-root users + if (isSystem) { + throw new InvalidParameterValueException("Only root admins can access system's offering"); + } + // find all domain Id up to root domain for this account + List domainIds = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(caller.getDomainId()); + if ( domainRecord == null ){ + s_logger.error("Could not find the domainId for account:" + caller.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + caller.getAccountName()); + } + domainIds.add(domainRecord.getId()); + while (domainRecord.getParent() != null ){ + domainRecord = _domainDao.findById(domainRecord.getParent()); + domainIds.add(domainRecord.getId()); + } + sc.addAnd("domainId", SearchCriteria.Op.IN, domainIds); + + // include also public offering if no keyword, name and id specified + if ( keyword == null && name == null && id == null ){ + includePublicOfferings = true; + } + } + else { + // for root users + if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin + throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering"); + } + if (domainId != null) { + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + } + } + + if (keyword != null) { + SearchCriteria ssc = _srvOfferingJoinDao.createSearchCriteria(); + ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } else if (vmId != null) { + UserVmVO vmInstance = _userVmDao.findById(vmId); + if ((vmInstance == null) || (vmInstance.getRemoved() != null)) { + InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id"); + ex.addProxyObject(vmInstance, vmId, "vmId"); + throw ex; + } + + _accountMgr.checkAccess(caller, null, true, vmInstance); + + ServiceOfferingVO offering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId()); + sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId()); + + // Only return offerings with the same Guest IP type and storage + // pool preference + // sc.addAnd("guestIpType", SearchCriteria.Op.EQ, + // offering.getGuestIpType()); + sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage()); + } + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } + + if (isSystem != null) { + sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem); + } + + if (name != null) { + sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); + } + + if (vmTypeStr != null) { + sc.addAnd("vm_type", SearchCriteria.Op.EQ, vmTypeStr); + } + + if (includePublicOfferings){ + SearchCriteria spc = _srvOfferingJoinDao.createSearchCriteria(); + spc.addAnd("domainId", SearchCriteria.Op.NULL); + spc.addAnd("systemUse", SearchCriteria.Op.EQ, false); + sc.addOr("systemUse", SearchCriteria.Op.SC, spc); + } + + return _srvOfferingJoinDao.searchAndCount(sc, searchFilter); + + } + + + + + @Override + public ListResponse listDataCenters(ListZonesByCmd cmd) { + Pair, Integer> result = listDataCentersInternal(cmd); + ListResponse response = new ListResponse(); + List dcResponses = ViewResponseHelper.createDataCenterResponse(cmd.getShowCapacities(), result.first().toArray(new DataCenterJoinVO[result.first().size()])); + response.setResponses(dcResponses, result.second()); + return response; + } + + + private Pair, Integer> listDataCentersInternal(ListZonesByCmd cmd) { + Account account = UserContext.current().getCaller(); + Long domainId = cmd.getDomainId(); + Long id = cmd.getId(); + String keyword = cmd.getKeyword(); + + Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(), cmd.getPageSizeVal()); + SearchCriteria sc = _dcJoinDao.createSearchCriteria(); + + if (id != null) { + sc.addAnd("id", SearchCriteria.Op.EQ, id); + } else { + if (keyword != null) { + SearchCriteria ssc = _dcJoinDao.createSearchCriteria(); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (domainId != null) { + // for domainId != null + // right now, we made the decision to only list zones associated + // with this domain, private zone + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + } else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) { + // it was decided to return all zones for the user's domain, and + // everything above till root + // list all zones belonging to this domain, and all of its + // parents + // check the parent, if not null, add zones for that parent to + // list + + + // find all domain Id up to root domain for this account + List domainIds = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + if ( domainRecord == null ){ + s_logger.error("Could not find the domainId for account:" + account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); + } + domainIds.add(domainRecord.getId()); + while (domainRecord.getParent() != null ){ + domainRecord = _domainDao.findById(domainRecord.getParent()); + domainIds.add(domainRecord.getId()); + } + // domainId == null (public zones) or domainId IN [all domain id up to root domain] + SearchCriteria sdc = _dcJoinDao.createSearchCriteria(); + sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds); + sdc.addOr("domainId", SearchCriteria.Op.NULL); + sc.addAnd("domain", SearchCriteria.Op.SC, sdc); + + // remove disabled zones + sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled); + + } else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { + // it was decided to return all zones for the domain admin, and + // everything above till root, as well as zones till the domain leaf + List domainIds = new ArrayList(); + DomainVO domainRecord = _domainDao.findById(account.getDomainId()); + if ( domainRecord == null ){ + s_logger.error("Could not find the domainId for account:" + account.getAccountName()); + throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); + } + domainIds.add(domainRecord.getId()); + // find all domain Ids till leaf + List allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId()); + for (DomainVO domain : allChildDomains) { + domainIds.add(domain.getId()); + } + // then find all domain Id up to root domain for this account + while (domainRecord.getParent() != null ){ + domainRecord = _domainDao.findById(domainRecord.getParent()); + domainIds.add(domainRecord.getId()); + } + + // domainId == null (public zones) or domainId IN [all domain id up to root domain] + SearchCriteria sdc = _dcJoinDao.createSearchCriteria(); + sdc.addOr("domainId", SearchCriteria.Op.IN, domainIds); + sdc.addOr("domainId", SearchCriteria.Op.NULL); + sc.addAnd("domain", SearchCriteria.Op.SC, sdc); + + // remove disabled zones + sc.addAnd("allocationState", SearchCriteria.Op.NEQ, Grouping.AllocationState.Disabled); + } + + // handle available=FALSE option, only return zones with at least one VM running there + Boolean available = cmd.isAvailable(); + if (account != null) { + if ((available != null) && Boolean.FALSE.equals(available)) { + Set dcIds = new HashSet(); //data centers with at least one VM running + List routers = _routerDao.listBy(account.getId()); + for (DomainRouterVO router : routers){ + dcIds.add(router.getDataCenterId()); + } + if ( dcIds.size() == 0) { + return new Pair, Integer>(new ArrayList(), 0); + } + else{ + sc.addAnd("idIn", SearchCriteria.Op.IN, dcIds); + } + + } + } + } + + return _dcJoinDao.searchAndCount(sc, searchFilter); + } + + + // This method is used for permissions check for both disk and service + // offerings + private boolean isPermissible(Long accountDomainId, Long offeringDomainId) { + + if (accountDomainId == offeringDomainId) { + return true; // account and service offering in same domain + } + + DomainVO domainRecord = _domainDao.findById(accountDomainId); + + if (domainRecord != null) { + while (true) { + if (domainRecord.getId() == offeringDomainId) { + return true; + } + + // try and move on to the next domain + if (domainRecord.getParent() != null) { + domainRecord = _domainDao.findById(domainRecord.getParent()); + } else { + break; + } + } + } + + return false; + } + } diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java index 39c108eb932..55d84bb5af4 100644 --- a/server/src/com/cloud/api/query/ViewResponseHelper.java +++ b/server/src/com/cloud/api/query/ViewResponseHelper.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ApiConstants.HostDetails; import org.apache.cloudstack.api.ApiConstants.VMDetails; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.AsyncJobResponse; +import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.DomainRouterResponse; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.HostResponse; @@ -34,15 +35,19 @@ import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceTagResponse; import org.apache.cloudstack.api.response.SecurityGroupResponse; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.log4j.Logger; import com.cloud.api.ApiDBUtils; import com.cloud.api.query.vo.AccountJoinVO; import com.cloud.api.query.vo.AsyncJobJoinVO; +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.api.query.vo.DiskOfferingJoinVO; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.EventJoinVO; import com.cloud.api.query.vo.HostJoinVO; @@ -52,6 +57,7 @@ import com.cloud.api.query.vo.ProjectInvitationJoinVO; import com.cloud.api.query.vo.ProjectJoinVO; import com.cloud.api.query.vo.ResourceTagJoinVO; import com.cloud.api.query.vo.SecurityGroupJoinVO; +import com.cloud.api.query.vo.ServiceOfferingJoinVO; import com.cloud.api.query.vo.StoragePoolJoinVO; import com.cloud.api.query.vo.UserAccountJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; @@ -274,4 +280,28 @@ public class ViewResponseHelper { } return respList; } + + public static List createDiskOfferingResponse(DiskOfferingJoinVO... offerings) { + List respList = new ArrayList(); + for (DiskOfferingJoinVO vt : offerings){ + respList.add(ApiDBUtils.newDiskOfferingResponse(vt)); + } + return respList; + } + + public static List createServiceOfferingResponse(ServiceOfferingJoinVO... offerings) { + List respList = new ArrayList(); + for (ServiceOfferingJoinVO vt : offerings){ + respList.add(ApiDBUtils.newServiceOfferingResponse(vt)); + } + return respList; + } + + public static List createDataCenterResponse(Boolean showCapacities, DataCenterJoinVO... dcs) { + List respList = new ArrayList(); + for (DataCenterJoinVO vt : dcs){ + respList.add(ApiDBUtils.newDataCenterResponse(vt, showCapacities)); + } + return respList; + } } diff --git a/server/src/com/cloud/api/query/dao/DataCenterJoinDao.java b/server/src/com/cloud/api/query/dao/DataCenterJoinDao.java new file mode 100644 index 00000000000..340f86f247d --- /dev/null +++ b/server/src/com/cloud/api/query/dao/DataCenterJoinDao.java @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.query.dao; + +import org.apache.cloudstack.api.response.ZoneResponse; + +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.dc.DataCenter; +import com.cloud.utils.db.GenericDao; + +public interface DataCenterJoinDao extends GenericDao { + + ZoneResponse newDataCenterResponse(DataCenterJoinVO dof, Boolean showCapacities); + + DataCenterJoinVO newDataCenterView(DataCenter dof); +} diff --git a/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java new file mode 100644 index 00000000000..667d8553eb1 --- /dev/null +++ b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java @@ -0,0 +1,110 @@ +// 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.api.query.dao; + +import java.util.List; +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiDBUtils; +import com.cloud.api.ApiResponseHelper; +import com.cloud.api.query.vo.DataCenterJoinVO; +import com.cloud.dc.DataCenter; +import org.apache.cloudstack.api.response.ZoneResponse; + +import com.cloud.user.Account; +import com.cloud.user.UserContext; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.springframework.stereotype.Component; + +@Component +@Local(value={DataCenterJoinDao.class}) +public class DataCenterJoinDaoImpl extends GenericDaoBase implements DataCenterJoinDao { + public static final Logger s_logger = Logger.getLogger(DataCenterJoinDaoImpl.class); + + + private SearchBuilder dofIdSearch; + + protected DataCenterJoinDaoImpl() { + + dofIdSearch = createSearchBuilder(); + dofIdSearch.and("id", dofIdSearch.entity().getId(), SearchCriteria.Op.EQ); + dofIdSearch.done(); + + this._count = "select count(distinct id) from data_center_view WHERE "; + } + + + + @Override + public ZoneResponse newDataCenterResponse(DataCenterJoinVO dataCenter, Boolean showCapacities) { + + Account account = UserContext.current().getCaller(); + ZoneResponse zoneResponse = new ZoneResponse(); + zoneResponse.setId(dataCenter.getUuid()); + zoneResponse.setName(dataCenter.getName()); + zoneResponse.setSecurityGroupsEnabled(ApiDBUtils.isSecurityGroupEnabledInZone(dataCenter.getId())); + zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled()); + + if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) { + zoneResponse.setDescription(dataCenter.getDescription()); + } + + if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { + zoneResponse.setDns1(dataCenter.getDns1()); + zoneResponse.setDns2(dataCenter.getDns2()); + zoneResponse.setInternalDns1(dataCenter.getInternalDns1()); + zoneResponse.setInternalDns2(dataCenter.getInternalDns2()); + // FIXME zoneResponse.setVlan(dataCenter.get.getVnet()); + zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr()); + } + + if (showCapacities != null && showCapacities) { + zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId())); + } + + // set network domain info + zoneResponse.setDomain(dataCenter.getDomain()); + + // set domain info + + zoneResponse.setDomainId(dataCenter.getDomainUuid()); + zoneResponse.setDomainName(dataCenter.getDomainName()); + + zoneResponse.setType(dataCenter.getNetworkType().toString()); + zoneResponse.setAllocationState(dataCenter.getAllocationState().toString()); + zoneResponse.setZoneToken(dataCenter.getZoneToken()); + zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider()); + zoneResponse.setObjectName("zone"); + return zoneResponse; + } + + + @Override + public DataCenterJoinVO newDataCenterView(DataCenter dataCenter) { + SearchCriteria sc = dofIdSearch.create(); + sc.setParameters("id", dataCenter.getId()); + List dcs = searchIncludingRemoved(sc, null, null, false); + assert dcs != null && dcs.size() == 1 : "No data center found for data center id " + dataCenter.getId(); + return dcs.get(0); + } + + +} diff --git a/server/src/com/cloud/api/query/dao/DiskOfferingJoinDao.java b/server/src/com/cloud/api/query/dao/DiskOfferingJoinDao.java new file mode 100644 index 00000000000..30758d12268 --- /dev/null +++ b/server/src/com/cloud/api/query/dao/DiskOfferingJoinDao.java @@ -0,0 +1,29 @@ +// 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.api.query.dao; + +import org.apache.cloudstack.api.response.DiskOfferingResponse; +import com.cloud.api.query.vo.DiskOfferingJoinVO; +import com.cloud.offering.DiskOffering; +import com.cloud.utils.db.GenericDao; + +public interface DiskOfferingJoinDao extends GenericDao { + + DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO dof); + + DiskOfferingJoinVO newDiskOfferingView(DiskOffering dof); +} diff --git a/server/src/com/cloud/api/query/dao/DiskOfferingJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/DiskOfferingJoinDaoImpl.java new file mode 100644 index 00000000000..43c9d005121 --- /dev/null +++ b/server/src/com/cloud/api/query/dao/DiskOfferingJoinDaoImpl.java @@ -0,0 +1,102 @@ +// 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.api.query.dao; + +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.api.query.vo.DiskOfferingJoinVO; +import org.apache.cloudstack.api.response.DiskOfferingResponse; +import com.cloud.offering.DiskOffering; +import com.cloud.offering.ServiceOffering; +import com.cloud.storage.DiskOfferingVO; +import com.cloud.storage.DiskOfferingVO.Type; +import com.cloud.utils.db.Attribute; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; +import org.springframework.stereotype.Component; + +@Component +@Local(value={DiskOfferingJoinDao.class}) +public class DiskOfferingJoinDaoImpl extends GenericDaoBase implements DiskOfferingJoinDao { + public static final Logger s_logger = Logger.getLogger(DiskOfferingJoinDaoImpl.class); + + + private SearchBuilder dofIdSearch; + private final Attribute _typeAttr; + + protected DiskOfferingJoinDaoImpl() { + + dofIdSearch = createSearchBuilder(); + dofIdSearch.and("id", dofIdSearch.entity().getId(), SearchCriteria.Op.EQ); + dofIdSearch.done(); + + _typeAttr = _allAttributes.get("type"); + + this._count = "select count(distinct id) from disk_offering_view WHERE "; + } + + + + @Override + public DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering) { + + DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse(); + diskOfferingResponse.setId(offering.getUuid()); + diskOfferingResponse.setName(offering.getName()); + diskOfferingResponse.setDisplayText(offering.getDisplayText()); + diskOfferingResponse.setCreated(offering.getCreated()); + diskOfferingResponse.setDiskSize(offering.getDiskSize() / (1024 * 1024 * 1024)); + + diskOfferingResponse.setDomain(offering.getDomainName()); + diskOfferingResponse.setDomainId(offering.getDomainUuid()); + + diskOfferingResponse.setTags(offering.getTags()); + diskOfferingResponse.setCustomized(offering.isCustomized()); + diskOfferingResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString()); + diskOfferingResponse.setObjectName("diskoffering"); + return diskOfferingResponse; + } + + + @Override + public DiskOfferingJoinVO newDiskOfferingView(DiskOffering offering) { + SearchCriteria sc = dofIdSearch.create(); + sc.setParameters("id", offering.getId()); + List offerings = searchIncludingRemoved(sc, null, null, false); + assert offerings != null && offerings.size() == 1 : "No disk offering found for offering id " + offering.getId(); + return offerings.get(0); + } + + @Override + public List searchIncludingRemoved(SearchCriteria sc, final Filter filter, final Boolean lock, final boolean cache) { + sc.addAnd(_typeAttr, Op.EQ, Type.Disk); + return super.searchIncludingRemoved(sc, filter, lock, cache); + } + + @Override + public List customSearchIncludingRemoved(SearchCriteria sc, final Filter filter) { + sc.addAnd(_typeAttr, Op.EQ, Type.Disk); + return super.customSearchIncludingRemoved(sc, filter); + } +} diff --git a/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDao.java b/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDao.java new file mode 100644 index 00000000000..a797125a18d --- /dev/null +++ b/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDao.java @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package com.cloud.api.query.dao; + +import org.apache.cloudstack.api.response.ServiceOfferingResponse; + +import com.cloud.api.query.vo.ServiceOfferingJoinVO; +import com.cloud.offering.ServiceOffering; +import com.cloud.utils.db.GenericDao; + +public interface ServiceOfferingJoinDao extends GenericDao { + + ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering); + + ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering); +} diff --git a/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java new file mode 100644 index 00000000000..9795fef66fd --- /dev/null +++ b/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java @@ -0,0 +1,92 @@ +// 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.api.query.dao; + +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.api.query.vo.ServiceOfferingJoinVO; +import org.apache.cloudstack.api.response.ServiceOfferingResponse; + +import com.cloud.offering.ServiceOffering; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.springframework.stereotype.Component; + +@Component +@Local(value={ServiceOfferingJoinDao.class}) +public class ServiceOfferingJoinDaoImpl extends GenericDaoBase implements ServiceOfferingJoinDao { + public static final Logger s_logger = Logger.getLogger(ServiceOfferingJoinDaoImpl.class); + + + private SearchBuilder sofIdSearch; + + protected ServiceOfferingJoinDaoImpl() { + + sofIdSearch = createSearchBuilder(); + sofIdSearch.and("id", sofIdSearch.entity().getId(), SearchCriteria.Op.EQ); + sofIdSearch.done(); + + this._count = "select count(distinct id) from service_offering_view WHERE "; + } + + + + @Override + public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering) { + + ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse(); + offeringResponse.setId(offering.getUuid()); + offeringResponse.setName(offering.getName()); + offeringResponse.setIsSystemOffering(offering.isSystemUse()); + offeringResponse.setDefaultUse(offering.isDefaultUse()); + offeringResponse.setSystemVmType(offering.getSystemVmType()); + offeringResponse.setDisplayText(offering.getDisplayText()); + offeringResponse.setCpuNumber(offering.getCpu()); + offeringResponse.setCpuSpeed(offering.getSpeed()); + offeringResponse.setMemory(offering.getRamSize()); + offeringResponse.setCreated(offering.getCreated()); + offeringResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() + : ServiceOffering.StorageType.shared.toString()); + offeringResponse.setOfferHa(offering.isOfferHA()); + offeringResponse.setLimitCpuUse(offering.isLimitCpuUse()); + offeringResponse.setTags(offering.getTags()); + offeringResponse.setDomain(offering.getDomainName()); + offeringResponse.setDomainId(offering.getDomainUuid()); + offeringResponse.setNetworkRate(offering.getRateMbps()); + offeringResponse.setHostTag(offering.getHostTag()); + offeringResponse.setObjectName("serviceoffering"); + + return offeringResponse; + } + + + @Override + public ServiceOfferingJoinVO newServiceOfferingView(ServiceOffering offering) { + SearchCriteria sc = sofIdSearch.create(); + sc.setParameters("id", offering.getId()); + List offerings = searchIncludingRemoved(sc, null, null, false); + assert offerings != null && offerings.size() == 1 : "No service offering found for offering id " + offering.getId(); + return offerings.get(0); + } + + +} diff --git a/server/src/com/cloud/api/query/vo/DataCenterJoinVO.java b/server/src/com/cloud/api/query/vo/DataCenterJoinVO.java new file mode 100644 index 00000000000..67a3f2715f0 --- /dev/null +++ b/server/src/com/cloud/api/query/vo/DataCenterJoinVO.java @@ -0,0 +1,284 @@ +// 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.api.query.vo; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.org.Grouping.AllocationState; +import com.cloud.utils.db.GenericDao; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name="data_center_view") +public class DataCenterJoinVO extends BaseViewVO implements InternalIdentity, Identity { + + @Id + @Column(name="id") + private long id; + + @Column(name="uuid") + private String uuid; + + @Column(name="name") + private String name; + + @Column(name="description") + private String description = null; + + @Column(name="dns1") + private String dns1 = null; + + @Column(name="dns2") + private String dns2 = null; + + @Column(name="internal_dns1") + private String internalDns1 = null; + + @Column(name="internal_dns2") + private String internalDns2 = null; + + @Column(name="guest_network_cidr") + private String guestNetworkCidr = null; + + @Column(name="domain") + private String domain; + + @Column(name="networktype") + @Enumerated(EnumType.STRING) + NetworkType networkType; + + @Column(name="dhcp_provider") + private String dhcpProvider; + + @Column(name="zone_token") + private String zoneToken; + + @Column(name="allocation_state") + @Enumerated(value=EnumType.STRING) + AllocationState allocationState; + + @Column(name="is_security_group_enabled") + boolean securityGroupEnabled; + + @Column(name="is_local_storage_enabled") + boolean localStorageEnabled; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="domain_id") + private long domainId; + + @Column(name="domain_uuid") + private String domainUuid; + + @Column(name="domain_name") + private String domainName; + + @Column(name="domain_path") + private String domainPath; + + + public DataCenterJoinVO() { + } + + @Override + public long getId() { + return id; + } + + @Override + public void setId(long id) { + this.id = id; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDns1() { + return dns1; + } + + public void setDns1(String dns1) { + this.dns1 = dns1; + } + + public String getDns2() { + return dns2; + } + + public void setDns2(String dns2) { + this.dns2 = dns2; + } + + public String getInternalDns1() { + return internalDns1; + } + + public void setInternalDns1(String internalDns1) { + this.internalDns1 = internalDns1; + } + + public String getInternalDns2() { + return internalDns2; + } + + public void setInternalDns2(String internalDns2) { + this.internalDns2 = internalDns2; + } + + public String getGuestNetworkCidr() { + return guestNetworkCidr; + } + + public void setGuestNetworkCidr(String guestNetworkCidr) { + this.guestNetworkCidr = guestNetworkCidr; + } + + public String getDomain() { + return domain; + } + + public void setDomain(String domain) { + this.domain = domain; + } + + public NetworkType getNetworkType() { + return networkType; + } + + public void setNetworkType(NetworkType networkType) { + this.networkType = networkType; + } + + public String getDhcpProvider() { + return dhcpProvider; + } + + public void setDhcpProvider(String dhcpProvider) { + this.dhcpProvider = dhcpProvider; + } + + public String getZoneToken() { + return zoneToken; + } + + public void setZoneToken(String zoneToken) { + this.zoneToken = zoneToken; + } + + public AllocationState getAllocationState() { + return allocationState; + } + + public void setAllocationState(AllocationState allocationState) { + this.allocationState = allocationState; + } + + public boolean isSecurityGroupEnabled() { + return securityGroupEnabled; + } + + public void setSecurityGroupEnabled(boolean securityGroupEnabled) { + this.securityGroupEnabled = securityGroupEnabled; + } + + + public boolean isLocalStorageEnabled() { + return localStorageEnabled; + } + + public void setLocalStorageEnabled(boolean localStorageEnabled) { + this.localStorageEnabled = localStorageEnabled; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public String getDomainUuid() { + return domainUuid; + } + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getDomainPath() { + return domainPath; + } + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + +} diff --git a/server/src/com/cloud/api/query/vo/DiskOfferingJoinVO.java b/server/src/com/cloud/api/query/vo/DiskOfferingJoinVO.java new file mode 100644 index 00000000000..7785beeece3 --- /dev/null +++ b/server/src/com/cloud/api/query/vo/DiskOfferingJoinVO.java @@ -0,0 +1,233 @@ +// 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.api.query.vo; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.storage.DiskOfferingVO.Type; +import com.cloud.utils.db.GenericDao; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name="disk_offering_view") +public class DiskOfferingJoinVO extends BaseViewVO implements InternalIdentity, Identity { + + @Id + @Column(name="id", updatable=false, nullable = false) + private long id; + + @Column(name="uuid") + private String uuid; + + @Column(name="name") + private String name; + + @Column(name="display_text") + private String displayText; + + @Column(name="disk_size") + long diskSize; + + @Column(name="tags", length=4096) + String tags; + + @Column(name="use_local_storage") + private boolean useLocalStorage; + + @Column(name="system_use") + private boolean systemUse; + + @Column(name="customized") + private boolean customized; + + @Column(name="sort_key") + int sortKey; + + @Column(name="type") + Type type; + + @Column(name=GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="domain_id") + private long domainId; + + @Column(name="domain_uuid") + private String domainUuid; + + @Column(name="domain_name") + private String domainName = null; + + @Column(name="domain_path") + private String domainPath = null; + + + public DiskOfferingJoinVO() { + } + + @Override + public long getId() { + return id; + } + + @Override + public void setId(long id) { + this.id = id; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public long getDiskSize() { + return diskSize; + } + + public void setDiskSize(long diskSize) { + this.diskSize = diskSize; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public boolean isUseLocalStorage() { + return useLocalStorage; + } + + public void setUseLocalStorage(boolean useLocalStorage) { + this.useLocalStorage = useLocalStorage; + } + + public boolean isSystemUse() { + return systemUse; + } + + public void setSystemUse(boolean systemUse) { + this.systemUse = systemUse; + } + + public boolean isCustomized() { + return customized; + } + + public void setCustomized(boolean customized) { + this.customized = customized; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public String getDomainUuid() { + return domainUuid; + } + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getDomainPath() { + return domainPath; + } + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + public int getSortKey() { + return sortKey; + } + + public void setSortKey(int sortKey) { + this.sortKey = sortKey; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + + +} diff --git a/server/src/com/cloud/api/query/vo/ServiceOfferingJoinVO.java b/server/src/com/cloud/api/query/vo/ServiceOfferingJoinVO.java new file mode 100644 index 00000000000..fe4a1658ec8 --- /dev/null +++ b/server/src/com/cloud/api/query/vo/ServiceOfferingJoinVO.java @@ -0,0 +1,311 @@ +// 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.api.query.vo; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name="service_offering_view") +public class ServiceOfferingJoinVO extends BaseViewVO implements InternalIdentity, Identity { + + @Id + @Column(name="id", updatable=false, nullable = false) + private long id; + + @Column(name="uuid") + private String uuid; + + @Column(name="name") + private String name; + + @Column(name="display_text") + private String displayText; + + @Column(name="tags", length=4096) + String tags; + + @Column(name="use_local_storage") + private boolean useLocalStorage; + + @Column(name="system_use") + private boolean systemUse; + + @Column(name="cpu") + private int cpu; + + @Column(name="speed") + private int speed; + + @Column(name="ram_size") + private int ramSize; + + @Column(name="nw_rate") + private Integer rateMbps; + + @Column(name="mc_rate") + private Integer multicastRateMbps; + + @Column(name="ha_enabled") + private boolean offerHA; + + @Column(name="limit_cpu_use") + private boolean limitCpuUse; + + @Column(name="host_tag") + private String hostTag; + + @Column(name="default_use") + private boolean default_use; + + @Column(name="vm_type") + private String vm_type; + + @Column(name="sort_key") + int sortKey; + + + @Column(name=GenericDao.CREATED_COLUMN) + private Date created; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="domain_id") + private long domainId; + + @Column(name="domain_uuid") + private String domainUuid; + + @Column(name="domain_name") + private String domainName = null; + + @Column(name="domain_path") + private String domainPath = null; + + + public ServiceOfferingJoinVO() { + } + + @Override + public long getId() { + return id; + } + + @Override + public void setId(long id) { + this.id = id; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public boolean isUseLocalStorage() { + return useLocalStorage; + } + + public void setUseLocalStorage(boolean useLocalStorage) { + this.useLocalStorage = useLocalStorage; + } + + public boolean isSystemUse() { + return systemUse; + } + + public void setSystemUse(boolean systemUse) { + this.systemUse = systemUse; + } + + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public long getDomainId() { + return domainId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public String getDomainUuid() { + return domainUuid; + } + + public void setDomainUuid(String domainUuid) { + this.domainUuid = domainUuid; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public String getDomainPath() { + return domainPath; + } + + public void setDomainPath(String domainPath) { + this.domainPath = domainPath; + } + + public int getSortKey() { + return sortKey; + } + + public void setSortKey(int sortKey) { + this.sortKey = sortKey; + } + + public int getCpu() { + return cpu; + } + + public void setCpu(int cpu) { + this.cpu = cpu; + } + + public int getSpeed() { + return speed; + } + + public void setSpeed(int speed) { + this.speed = speed; + } + + public int getRamSize() { + return ramSize; + } + + public void setRamSize(int ramSize) { + this.ramSize = ramSize; + } + + public Integer getRateMbps() { + return rateMbps; + } + + public void setRateMbps(Integer rateMbps) { + this.rateMbps = rateMbps; + } + + public Integer getMulticastRateMbps() { + return multicastRateMbps; + } + + public void setMulticastRateMbps(Integer multicastRateMbps) { + this.multicastRateMbps = multicastRateMbps; + } + + public boolean isOfferHA() { + return offerHA; + } + + public void setOfferHA(boolean offerHA) { + this.offerHA = offerHA; + } + + public boolean isLimitCpuUse() { + return limitCpuUse; + } + + public void setLimitCpuUse(boolean limitCpuUse) { + this.limitCpuUse = limitCpuUse; + } + + public String getHostTag() { + return hostTag; + } + + public void setHostTag(String hostTag) { + this.hostTag = hostTag; + } + + public boolean isDefaultUse() { + return default_use; + } + + public void setDefaultUse(boolean default_use) { + this.default_use = default_use; + } + + public String getSystemVmType() { + return vm_type; + } + + public void setSystemVmType(String vm_type) { + this.vm_type = vm_type; + } + + +} diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index ce3698f7854..4ae144e6ce1 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -360,7 +360,6 @@ public enum Config { ConcurrentSnapshotsThresholdPerHost("Advanced", ManagementServer.class, Long.class, "concurrent.snapshots.threshold.perhost", null, "Limits number of snapshots that can be handled by the host concurrently; default is NULL - unlimited", null); - private final String _category; private final Class _componentClass; private final Class _type; diff --git a/server/src/com/cloud/dao/EntityManagerImpl.java b/server/src/com/cloud/dao/EntityManagerImpl.java index b4ea081fa1c..283927473fc 100644 --- a/server/src/com/cloud/dao/EntityManagerImpl.java +++ b/server/src/com/cloud/dao/EntityManagerImpl.java @@ -54,6 +54,13 @@ public class EntityManagerImpl implements EntityManager, Manager { return dao.findByUuid(uuid); } + @Override + public T findByUuidIncludingRemoved(Class entityType, String uuid) { + // Finds and returns a unique VO using uuid, null if entity not found in db + GenericDao dao = (GenericDao)GenericDaoBase.getDao(entityType); + return dao.findByUuidIncludingRemoved(uuid); + } + @Override public T findByXId(Class entityType, String xid) { return null; diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java index dc09db60859..b39feb7d086 100755 --- a/server/src/com/cloud/network/NetworkServiceImpl.java +++ b/server/src/com/cloud/network/NetworkServiceImpl.java @@ -1816,9 +1816,6 @@ public class NetworkServiceImpl implements NetworkService, Manager { throw new InvalidParameterValueException("Please specify valid integers for the vlan range."); } - //check for vnet conflicts with other physical network(s) in the zone - checkGuestVnetsConflicts(zoneId, vnetStart, vnetEnd, null); - if ((vnetStart > vnetEnd) || (vnetStart < 0) || (vnetEnd > 4096)) { s_logger.warn("Invalid vnet range: start range:" + vnetStart + " end range:" + vnetEnd); throw new InvalidParameterValueException("Vnet range should be between 0-4096 and start range should be lesser than or equal to end range"); @@ -1997,9 +1994,6 @@ public class NetworkServiceImpl implements NetworkService, Manager { throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage + " and start range should be lesser than or equal to stop range"); } - //check if new vnet conflicts with vnet ranges of other physical networks - checkGuestVnetsConflicts(network.getDataCenterId(), newStartVnet, newEndVnet, network.getId()); - if (physicalNetworkHasAllocatedVnets(network.getDataCenterId(), network.getId())) { String[] existingRange = network.getVnet().split("-"); int existingStartVnet = Integer.parseInt(existingRange[0]); @@ -2044,24 +2038,6 @@ public class NetworkServiceImpl implements NetworkService, Manager { return network; } - protected void checkGuestVnetsConflicts(long zoneId, int newStartVnet, int newEndVnet, Long pNtwkIdToSkip) { - List pNtwks = _physicalNetworkDao.listByZone(zoneId); - for (PhysicalNetwork pNtwk : pNtwks) { - // skip my own network and networks that don't have vnet range set - if ((pNtwk.getVnet() == null || pNtwk.getVnet().isEmpty()) || (pNtwkIdToSkip != null && pNtwkIdToSkip == pNtwk.getId())) { - continue; - } - String[] existingRange = pNtwk.getVnet().split("-"); - int startVnet = Integer.parseInt(existingRange[0]); - int endVnet = Integer.parseInt(existingRange[1]); - if ((newStartVnet >= startVnet && newStartVnet <= endVnet) - || (newEndVnet <= endVnet && newEndVnet >= startVnet)) { - throw new InvalidParameterValueException("Vnet range for physical network conflicts with another " + - "physical network's vnet in the zone"); - } - } - } - private boolean physicalNetworkHasAllocatedVnets(long zoneId, long physicalNetworkId) { return !_dcDao.listAllocatedVnets(physicalNetworkId).isEmpty(); } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 5edd529e876..a67cc4aa78b 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -629,8 +629,9 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, } @Override - public List listSwifts(ListSwiftsCmd cmd) { - return _swiftMgr.listSwifts(cmd); + public Pair, Integer> listSwifts(ListSwiftsCmd cmd) { + Pair, Integer> swifts = _swiftMgr.listSwifts(cmd); + return new Pair, Integer>(swifts.first(), swifts.second()); } @Override diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 2b0cf7df24a..75a2af7596a 100755 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -563,8 +563,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { return; } String already = _configDao.getValue("ssh.privatekey"); - String homeDir = null; - homeDir = Script.runSimpleBashScript("echo ~" + username); + String homeDir = System.getProperty("user.home"); if (homeDir == null) { throw new CloudRuntimeException("Cannot get home directory for account: " + username); } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 63d6a3dae9e..e9d2e23730c 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -47,6 +47,7 @@ import javax.management.MBeanRegistrationException; import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; +import com.cloud.storage.dao.*; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoCmd; @@ -74,6 +75,7 @@ import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd; import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd; import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd; import org.apache.cloudstack.api.command.user.ssh.CreateSSHKeyPairCmd; +import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd; import org.apache.cloudstack.api.command.user.ssh.DeleteSSHKeyPairCmd; import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd; import org.apache.cloudstack.api.command.user.ssh.RegisterSSHKeyPairCmd; @@ -139,7 +141,6 @@ import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; -import com.cloud.exception.CloudAuthenticationException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.OperationTimedoutException; @@ -178,7 +179,6 @@ import com.cloud.server.ResourceTag.TaggedResourceType; import com.cloud.server.auth.UserAuthenticator; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; -import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.GuestOS; import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.GuestOSVO; @@ -193,13 +193,6 @@ import com.cloud.storage.UploadVO; import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; import com.cloud.storage.VolumeVO; -import com.cloud.storage.dao.DiskOfferingDao; -import com.cloud.storage.dao.GuestOSCategoryDao; -import com.cloud.storage.dao.GuestOSDao; -import com.cloud.storage.dao.StoragePoolDao; -import com.cloud.storage.dao.UploadDao; -import com.cloud.storage.dao.VMTemplateDao; -import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.s3.S3Manager; import com.cloud.storage.secondary.SecondaryStorageVmManager; import com.cloud.storage.snapshot.SnapshotManager; @@ -565,120 +558,6 @@ public class ManagementServerImpl implements ManagementServer { return PasswordGenerator.generateRandomPassword(6); } - @Override - public List listDataCenters(ListZonesByCmd cmd) { - Account account = UserContext.current().getCaller(); - List dcs = null; - Long domainId = cmd.getDomainId(); - Long id = cmd.getId(); - boolean removeDisabledZones = false; - String keyword = cmd.getKeyword(); - if (domainId != null) { - // for domainId != null - // right now, we made the decision to only list zones associated - // with this domain - dcs = _dcDao.findZonesByDomainId(domainId, keyword); // private - // zones - } else if ((account == null || account.getType() == Account.ACCOUNT_TYPE_ADMIN)) { - if (keyword != null) { - dcs = _dcDao.findByKeyword(keyword); - } else { - dcs = _dcDao.listAll(); // all zones - } - } else if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) { - // it was decided to return all zones for the user's domain, and - // everything above till root - // list all zones belonging to this domain, and all of its parents - // check the parent, if not null, add zones for that parent to list - dcs = new ArrayList(); - DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - if (domainRecord != null) { - while (true) { - dcs.addAll(_dcDao.findZonesByDomainId(domainRecord.getId(), keyword)); - if (domainRecord.getParent() != null) { - domainRecord = _domainDao.findById(domainRecord.getParent()); - } else { - break; - } - } - } - // add all public zones too - dcs.addAll(_dcDao.listPublicZones(keyword)); - removeDisabledZones = true; - } else if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { - // it was decided to return all zones for the domain admin, and - // everything above till root - dcs = new ArrayList(); - DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - // this covers path till root - if (domainRecord != null) { - DomainVO localRecord = domainRecord; - while (true) { - dcs.addAll(_dcDao.findZonesByDomainId(localRecord.getId(), keyword)); - if (localRecord.getParent() != null) { - localRecord = _domainDao.findById(localRecord.getParent()); - } else { - break; - } - } - } - // this covers till leaf - if (domainRecord != null) { - // find all children for this domain based on a like search by - // path - List allChildDomains = _domainDao.findAllChildren(domainRecord.getPath(), domainRecord.getId()); - List allChildDomainIds = new ArrayList(); - // create list of domainIds for search - for (DomainVO domain : allChildDomains) { - allChildDomainIds.add(domain.getId()); - } - // now make a search for zones based on this - if (allChildDomainIds.size() > 0) { - List childZones = _dcDao.findChildZones((allChildDomainIds.toArray()), keyword); - dcs.addAll(childZones); - } - } - // add all public zones too - dcs.addAll(_dcDao.listPublicZones(keyword)); - removeDisabledZones = true; - } - - if (removeDisabledZones) { - dcs.removeAll(_dcDao.listDisabledZones()); - } - - Boolean available = cmd.isAvailable(); - if (account != null) { - if ((available != null) && Boolean.FALSE.equals(available)) { - List routers = _routerDao.listBy(account.getId()); - for (Iterator iter = dcs.iterator(); iter.hasNext();) { - DataCenterVO dc = iter.next(); - boolean found = false; - for (DomainRouterVO router : routers) { - if (dc.getId() == router.getDataCenterId()) { - found = true; - break; - } - } - if (!found) { - iter.remove(); - } - } - } - } - - if (id != null) { - List singleZone = new ArrayList(); - for (DataCenterVO zone : dcs) { - if (zone.getId() == id) { - singleZone.add(zone); - } - } - return singleZone; - } - return dcs; - } - @Override public HostVO getHostBy(long hostId) { return _hostDao.findById(hostId); @@ -754,221 +633,6 @@ public class ManagementServerImpl implements ManagementServer { return cal.getTime(); } - // This method is used for permissions check for both disk and service - // offerings - private boolean isPermissible(Long accountDomainId, Long offeringDomainId) { - - if (accountDomainId == offeringDomainId) { - return true; // account and service offering in same domain - } - - DomainVO domainRecord = _domainDao.findById(accountDomainId); - - if (domainRecord != null) { - while (true) { - if (domainRecord.getId() == offeringDomainId) { - return true; - } - - // try and move on to the next domain - if (domainRecord.getParent() != null) { - domainRecord = _domainDao.findById(domainRecord.getParent()); - } else { - break; - } - } - } - - return false; - } - - @Override - public List searchForServiceOfferings(ListServiceOfferingsCmd cmd) { - - // Note - // The list method for offerings is being modified in accordance with - // discussion with Will/Kevin - // For now, we will be listing the following based on the usertype - // 1. For root, we will list all offerings - // 2. For domainAdmin and regular users, we will list everything in - // their domains+parent domains ... all the way - // till - // root - Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); - isAscending = (isAscending == null ? true : isAscending); - Filter searchFilter = new Filter(ServiceOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchCriteria sc = _offeringsDao.createSearchCriteria(); - - Account caller = UserContext.current().getCaller(); - Object name = cmd.getServiceOfferingName(); - Object id = cmd.getId(); - Object keyword = cmd.getKeyword(); - Long vmId = cmd.getVirtualMachineId(); - Long domainId = cmd.getDomainId(); - Boolean isSystem = cmd.getIsSystem(); - String vmTypeStr = cmd.getSystemVmType(); - - if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) { - throw new InvalidParameterValueException("Only ROOT admins can access system's offering"); - } - - // Keeping this logic consistent with domain specific zones - // if a domainId is provided, we just return the so associated with this - // domain - if (domainId != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { - // check if the user's domain == so's domain || user's domain is a - // child of so's domain - if (!isPermissible(caller.getDomainId(), domainId)) { - throw new PermissionDeniedException("The account:" + caller.getAccountName() - + " does not fall in the same domain hierarchy as the service offering"); - } - } - - // For non-root users - if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) - || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { - if (isSystem) { - throw new InvalidParameterValueException("Only root admins can access system's offering"); - } - return searchServiceOfferingsInternal(caller, name, id, vmId, keyword, searchFilter); - } - - // for root users, the existing flow - if (caller.getDomainId() != 1 && isSystem) { // NON ROOT admin - throw new InvalidParameterValueException("Non ROOT admins cannot access system's offering"); - } - - if (keyword != null) { - SearchCriteria ssc = _offeringsDao.createSearchCriteria(); - ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } else if (vmId != null) { - UserVmVO vmInstance = _userVmDao.findById(vmId); - if ((vmInstance == null) || (vmInstance.getRemoved() != null)) { - InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id"); - ex.addProxyObject(vmInstance, vmId, "vmId"); - throw ex; - } - - _accountMgr.checkAccess(caller, null, true, vmInstance); - - ServiceOfferingVO offering = _offeringsDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId()); - sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId()); - - // Only return offerings with the same Guest IP type and storage - // pool preference - // sc.addAnd("guestIpType", SearchCriteria.Op.EQ, - // offering.getGuestIpType()); - sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage()); - } - if (id != null) { - sc.addAnd("id", SearchCriteria.Op.EQ, id); - } - - if (isSystem != null) { - sc.addAnd("systemUse", SearchCriteria.Op.EQ, isSystem); - } - - if (name != null) { - sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); - } - - if (domainId != null) { - sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); - } - - if (vmTypeStr != null) { - sc.addAnd("vm_type", SearchCriteria.Op.EQ, vmTypeStr); - } - - sc.addAnd("removed", SearchCriteria.Op.NULL); - return _offeringsDao.search(sc, searchFilter); - - } - - private List searchServiceOfferingsInternal(Account caller, Object name, Object id, Long vmId, Object keyword, - Filter searchFilter) { - - // it was decided to return all offerings for the user's domain, and - // everything above till root (for normal user - // or - // domain admin) - // list all offerings belonging to this domain, and all of its parents - // check the parent, if not null, add offerings for that parent to list - List sol = new ArrayList(); - DomainVO domainRecord = _domainDao.findById(caller.getDomainId()); - boolean includePublicOfferings = true; - if (domainRecord != null) { - while (true) { - if (id != null) { - ServiceOfferingVO so = _offeringsDao.findById((Long) id); - if (so != null) { - sol.add(so); - } - return sol; - } - - SearchCriteria sc = _offeringsDao.createSearchCriteria(); - - if (keyword != null) { - includePublicOfferings = false; - SearchCriteria ssc = _offeringsDao.createSearchCriteria(); - ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } else if (vmId != null) { - UserVmVO vmInstance = _userVmDao.findById(vmId); - if ((vmInstance == null) || (vmInstance.getRemoved() != null)) { - InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); - ex.addProxyObject(vmInstance, vmId, "vmId"); - throw ex; - } - - _accountMgr.checkAccess(caller, null, false, vmInstance); - - ServiceOfferingVO offering = _offeringsDao.findById(vmInstance.getServiceOfferingId()); - sc.addAnd("id", SearchCriteria.Op.NEQ, offering.getId()); - - sc.addAnd("useLocalStorage", SearchCriteria.Op.EQ, offering.getUseLocalStorage()); - } - - if (name != null) { - includePublicOfferings = false; - sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%"); - } - sc.addAnd("systemUse", SearchCriteria.Op.EQ, false); - - // for this domain - sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId()); - - // don't return removed service offerings - sc.addAnd("removed", SearchCriteria.Op.NULL); - - // search and add for this domain - sol.addAll(_offeringsDao.search(sc, searchFilter)); - - // try and move on to the next domain - if (domainRecord.getParent() != null) { - domainRecord = _domainDao.findById(domainRecord.getParent()); - } else { - break;// now we got all the offerings for this user/dom adm - } - } - } else { - s_logger.error("Could not find the domainId for account:" + caller.getAccountName()); - throw new CloudAuthenticationException("Could not find the domainId for account:" + caller.getAccountName()); - } - - // add all the public offerings to the sol list before returning - if (includePublicOfferings) { - sol.addAll(_offeringsDao.findPublicServiceOfferings()); - } - - return sol; - } @Override public List searchForClusters(long zoneId, Long startIndex, Long pageSizeVal, String hypervisorType) { @@ -2270,169 +1934,7 @@ public class ManagementServerImpl implements ManagementServer { || (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); } - private List searchDiskOfferingsInternal(Account account, Object name, Object id, Object keyword, Filter searchFilter) { - // it was decided to return all offerings for the user's domain, and - // everything above till root (for normal user - // or - // domain admin) - // list all offerings belonging to this domain, and all of its parents - // check the parent, if not null, add offerings for that parent to list - List dol = new ArrayList(); - DomainVO domainRecord = _domainDao.findById(account.getDomainId()); - boolean includePublicOfferings = true; - if (domainRecord != null) { - while (true) { - SearchBuilder sb = _diskOfferingDao.createSearchBuilder(); - sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL); - - SearchCriteria sc = sb.create(); - if (keyword != null) { - includePublicOfferings = false; - SearchCriteria ssc = _diskOfferingDao.createSearchCriteria(); - ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } - - if (name != null) { - includePublicOfferings = false; - sc.setParameters("name", "%" + name + "%"); - } - - if (id != null) { - includePublicOfferings = false; - sc.setParameters("id", id); - } - - // for this domain - sc.addAnd("domainId", SearchCriteria.Op.EQ, domainRecord.getId()); - - // search and add for this domain - dol.addAll(_diskOfferingDao.search(sc, searchFilter)); - - // try and move on to the next domain - if (domainRecord.getParent() != null) { - domainRecord = _domainDao.findById(domainRecord.getParent()); - } else { - break;// now we got all the offerings for this user/dom adm - } - } - } else { - s_logger.error("Could not find the domainId for account:" + account.getAccountName()); - throw new CloudAuthenticationException("Could not find the domainId for account:" + account.getAccountName()); - } - - // add all the public offerings to the sol list before returning - if (includePublicOfferings) { - dol.addAll(_diskOfferingDao.findPublicDiskOfferings()); - } - - return dol; - - } - - @Override - public List searchForDiskOfferings(ListDiskOfferingsCmd cmd) { - // Note - // The list method for offerings is being modified in accordance with - // discussion with Will/Kevin - // For now, we will be listing the following based on the usertype - // 1. For root, we will list all offerings - // 2. For domainAdmin and regular users, we will list everything in - // their domains+parent domains ... all the way - // till - // root - - Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); - isAscending = (isAscending == null ? true : isAscending); - Filter searchFilter = new Filter(DiskOfferingVO.class, "sortKey", isAscending, cmd.getStartIndex(), cmd.getPageSizeVal()); - SearchBuilder sb = _diskOfferingDao.createSearchBuilder(); - - // SearchBuilder and SearchCriteria are now flexible so that the search - // builder can be built with all possible - // search terms and only those with criteria can be set. The proper SQL - // should be generated as a result. - Account account = UserContext.current().getCaller(); - Object name = cmd.getDiskOfferingName(); - Object id = cmd.getId(); - Object keyword = cmd.getKeyword(); - Long domainId = cmd.getDomainId(); - // Keeping this logic consistent with domain specific zones - // if a domainId is provided, we just return the disk offering - // associated with this domain - if (domainId != null) { - if (account.getType() == Account.ACCOUNT_TYPE_ADMIN) { - return _diskOfferingDao.listByDomainId(domainId);// no perm - // check - } else { - // check if the user's domain == do's domain || user's domain is - // a child of so's domain - if (isPermissible(account.getDomainId(), domainId)) { - // perm check succeeded - return _diskOfferingDao.listByDomainId(domainId); - } else { - throw new PermissionDeniedException("The account:" + account.getAccountName() - + " does not fall in the same domain hierarchy as the disk offering"); - } - } - } - - // For non-root users - if ((account.getType() == Account.ACCOUNT_TYPE_NORMAL || account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) - || account.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { - return searchDiskOfferingsInternal(account, name, id, keyword, searchFilter); - } - - // For root users, preserving existing flow - sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); - sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); - sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.NULL); - - // FIXME: disk offerings should search back up the hierarchy for - // available disk offerings... - /* - * sb.addAnd("domainId", sb.entity().getDomainId(), - * SearchCriteria.Op.EQ); if (domainId != null) { - * SearchBuilder domainSearch = - * _domainDao.createSearchBuilder(); domainSearch.addAnd("path", - * domainSearch.entity().getPath(), SearchCriteria.Op.LIKE); - * sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), - * domainSearch.entity().getId()); } - */ - - SearchCriteria sc = sb.create(); - if (keyword != null) { - SearchCriteria ssc = _diskOfferingDao.createSearchCriteria(); - ssc.addOr("displayText", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); - - sc.addAnd("name", SearchCriteria.Op.SC, ssc); - } - - if (name != null) { - sc.setParameters("name", "%" + name + "%"); - } - - if (id != null) { - sc.setParameters("id", id); - } - - // FIXME: disk offerings should search back up the hierarchy for - // available disk offerings... - /* - * if (domainId != null) { sc.setParameters("domainId", domainId); // - * //DomainVO domain = _domainDao.findById((Long)domainId); // // I want - * to join on user_vm.domain_id = domain.id where domain.path like - * 'foo%' //sc.setJoinParameters("domainSearch", "path", - * domain.getPath() + "%"); // } - */ - - return _diskOfferingDao.search(sc, searchFilter); - } @Override public List> getCommands() { diff --git a/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java b/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java index 9f8d170e797..467d491d779 100644 --- a/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java +++ b/server/src/com/cloud/storage/dao/SnapshotPolicyDao.java @@ -20,6 +20,7 @@ import java.util.List; import com.cloud.storage.SnapshotPolicyVO; import com.cloud.utils.DateUtil.IntervalType; +import com.cloud.utils.Pair; import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDao; @@ -29,6 +30,8 @@ import com.cloud.utils.db.GenericDao; public interface SnapshotPolicyDao extends GenericDao { List listByVolumeId(long volumeId); List listByVolumeId(long volumeId, Filter filter); + Pair, Integer> listAndCountByVolumeId(long volumeId); + Pair, Integer> listAndCountByVolumeId(long volumeId, Filter filter); SnapshotPolicyVO findOneByVolumeInterval(long volumeId, IntervalType intvType); List listActivePolicies(); SnapshotPolicyVO findOneByVolume(long volumeId); diff --git a/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java b/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java index 9beed6706de..3f894a22640 100644 --- a/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java +++ b/server/src/com/cloud/storage/dao/SnapshotPolicyDaoImpl.java @@ -25,6 +25,7 @@ import org.springframework.stereotype.Component; import com.cloud.storage.SnapshotPolicyVO; import com.cloud.utils.DateUtil.IntervalType; +import com.cloud.utils.Pair; import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; @@ -66,6 +67,19 @@ public class SnapshotPolicyDaoImpl extends GenericDaoBase, Integer> listAndCountByVolumeId(long volumeId) { + return listAndCountByVolumeId(volumeId, null); + } + + @Override + public Pair, Integer> listAndCountByVolumeId(long volumeId, Filter filter) { + SearchCriteria sc = VolumeIdSearch.create(); + sc.setParameters("volumeId", volumeId); + sc.setParameters("active", true); + return searchAndCount(sc, filter); + } + protected SnapshotPolicyDaoImpl() { VolumeIdSearch = createSearchBuilder(); VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 6bf6d5e5f2a..1209d5cb752 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -71,6 +71,7 @@ import com.cloud.exception.StorageUnavailableException; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.PhysicalNetworkTrafficType; import com.cloud.org.Grouping; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.resource.ResourceManager; @@ -1231,14 +1232,15 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma } @Override - public List listPoliciesforVolume(ListSnapshotPoliciesCmd cmd) { + public Pair, Integer> listPoliciesforVolume(ListSnapshotPoliciesCmd cmd) { Long volumeId = cmd.getVolumeId(); VolumeVO volume = _volsDao.findById(volumeId); if (volume == null) { throw new InvalidParameterValueException("Unable to find a volume with id " + volumeId); } _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume); - return listPoliciesforVolume(cmd.getVolumeId()); + Pair, Integer> result = _snapshotPolicyDao.listAndCountByVolumeId(volumeId); + return new Pair, Integer>(result.first(), result.second()); } @Override diff --git a/server/src/com/cloud/storage/swift/SwiftManager.java b/server/src/com/cloud/storage/swift/SwiftManager.java index 0dd6e1cf22a..2abdac7f807 100644 --- a/server/src/com/cloud/storage/swift/SwiftManager.java +++ b/server/src/com/cloud/storage/swift/SwiftManager.java @@ -27,6 +27,7 @@ import com.cloud.exception.DiscoveryException; import com.cloud.storage.Swift; import com.cloud.storage.SwiftVO; import com.cloud.storage.VMTemplateSwiftVO; +import com.cloud.utils.Pair; import com.cloud.utils.component.Manager; public interface SwiftManager extends Manager { @@ -50,7 +51,7 @@ public interface SwiftManager extends Manager { Long chooseZoneForTmpltExtract(Long tmpltId); - List listSwifts(ListSwiftsCmd cmd); + Pair, Integer> listSwifts(ListSwiftsCmd cmd); VMTemplateSwiftVO findByTmpltId(Long tmpltId); } diff --git a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java index ef3deed74b1..01e2955b540 100644 --- a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java +++ b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java @@ -52,6 +52,7 @@ import com.cloud.storage.dao.SwiftDao; import com.cloud.storage.dao.VMTemplateHostDao; import com.cloud.storage.dao.VMTemplateSwiftDao; import com.cloud.storage.dao.VMTemplateZoneDao; +import com.cloud.utils.Pair; import com.cloud.utils.db.Filter; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; @@ -59,15 +60,11 @@ import com.cloud.utils.db.SearchCriteria2; import com.cloud.utils.db.SearchCriteriaService; import com.cloud.utils.exception.CloudRuntimeException; - - @Component @Local(value = { SwiftManager.class }) public class SwiftManagerImpl implements SwiftManager { private static final Logger s_logger = Logger.getLogger(SwiftManagerImpl.class); - - private String _name; @Inject private SwiftDao _swiftDao; @@ -262,13 +259,13 @@ public class SwiftManagerImpl implements SwiftManager { } @Override - public List listSwifts(ListSwiftsCmd cmd) { + public Pair, Integer> listSwifts(ListSwiftsCmd cmd) { Filter searchFilter = new Filter(SwiftVO.class, "id", Boolean.TRUE, cmd.getStartIndex(), cmd.getPageSizeVal()); SearchCriteria sc = _swiftDao.createSearchCriteria(); if (cmd.getId() != null) { sc.addAnd("id", SearchCriteria.Op.EQ, cmd.getId()); } - return _swiftDao.search(sc, searchFilter); + return _swiftDao.searchAndCount(sc, searchFilter); } diff --git a/server/test/com/cloud/api/APITest.java b/server/test/com/cloud/api/APITest.java index 69c488f5a10..0b040abc3f5 100644 --- a/server/test/com/cloud/api/APITest.java +++ b/server/test/com/cloud/api/APITest.java @@ -19,17 +19,17 @@ package com.cloud.api; import java.io.BufferedReader; import java.io.EOFException; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.math.BigInteger; import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLConnection; import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Iterator; +import org.apache.cloudstack.api.response.SuccessResponse; + import com.cloud.utils.exception.CloudRuntimeException; import com.google.gson.Gson; @@ -147,17 +147,38 @@ public abstract class APITest { protected Object fromSerializedString(String result, Class repCls) { try { if (result != null && !result.isEmpty()) { - // get real content - int start = result.indexOf('{', result.indexOf('{') + 1); // find the second { - if ( start < 0 ){ + int start; + int end; + if (repCls == LoginResponse.class || repCls == SuccessResponse.class) { + + start = result.indexOf('{', result.indexOf('{') + 1); // find + // the + // second + // { + + end = result.lastIndexOf('}', result.lastIndexOf('}') - 1); // find + // the + // second + // } + // backwards + + } else { + // get real content + start = result.indexOf('{', result.indexOf('{', result.indexOf('{') + 1) + 1); // find + // the + // third + // { + end = result.lastIndexOf('}', result.lastIndexOf('}', result.lastIndexOf('}') - 1) - 1); // find + // the + // third + // } + // backwards + } + if (start < 0 || end < 0) { throw new CloudRuntimeException("Response format is wrong: " + result); } - int end = result.lastIndexOf('}', result.lastIndexOf('}')-1); // find the second } backwards - if ( end < 0 ){ - throw new CloudRuntimeException("Response format is wrong: " + result); - } - String content = result.substring(start, end+1); + String content = result.substring(start, end + 1); Gson gson = ApiGsonHelper.getBuilder().create(); return gson.fromJson(content, repCls); } diff --git a/server/test/com/cloud/api/ListPerfTest.java b/server/test/com/cloud/api/ListPerfTest.java index eb98d9187fe..b8cb97eb8f0 100644 --- a/server/test/com/cloud/api/ListPerfTest.java +++ b/server/test/com/cloud/api/ListPerfTest.java @@ -16,11 +16,18 @@ // under the License. package com.cloud.api; +import static org.junit.Assert.*; + import java.util.HashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.junit.Before; import org.junit.Test; +import com.cloud.utils.exception.CloudRuntimeException; + /** * Test fixture to do performance test for list command @@ -163,6 +170,4 @@ public class ListPerfTest extends APITest { } - - } diff --git a/server/test/com/cloud/resource/MockResourceManagerImpl.java b/server/test/com/cloud/resource/MockResourceManagerImpl.java index e94cdea9853..a0dad479144 100644 --- a/server/test/com/cloud/resource/MockResourceManagerImpl.java +++ b/server/test/com/cloud/resource/MockResourceManagerImpl.java @@ -202,7 +202,7 @@ public class MockResourceManagerImpl implements ResourceManager, Manager { * @see com.cloud.resource.ResourceService#listSwifts(com.cloud.api.commands.ListSwiftsCmd) */ @Override - public List listSwifts(ListSwiftsCmd cmd) { + public Pair, Integer> listSwifts(ListSwiftsCmd cmd) { // TODO Auto-generated method stub return null; } diff --git a/setup/db/create-schema-view.sql b/setup/db/create-schema-view.sql index bf04c1caa57..f68a6cadb71 100644 --- a/setup/db/create-schema-view.sql +++ b/setup/db/create-schema-view.sql @@ -14,808 +14,1123 @@ -- KIND, either express or implied. See the License for the -- specific language governing permissions and limitations -- under the License. -use cloud; ---- DB views for list api --- +-- DB views for list api + DROP VIEW IF EXISTS `cloud`.`user_vm_view`; CREATE VIEW `cloud`.`user_vm_view` AS -select -vm_instance.id id, -vm_instance.name name, -user_vm.display_name display_name, -user_vm.user_data user_data, -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, -instance_group.id instance_group_id, -instance_group.uuid instance_group_uuid, -instance_group.name instance_group_name, -vm_instance.uuid uuid, -vm_instance.last_host_id last_host_id, -vm_instance.vm_type type, -vm_instance.vnc_password vnc_password, -vm_instance.limit_cpu_use limit_cpu_use, -vm_instance.created created, -vm_instance.state state, -vm_instance.removed removed, -vm_instance.ha_enabled ha_enabled, -vm_instance.hypervisor_type hypervisor_type, -vm_instance.instance_name instance_name, -vm_instance.guest_os_id guest_os_id, -guest_os.uuid guest_os_uuid, -vm_instance.pod_id pod_id, -host_pod_ref.uuid pod_uuid, -vm_instance.private_ip_address private_ip_address, -vm_instance.private_mac_address private_mac_address, -vm_instance.vm_type vm_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -data_center.is_security_group_enabled security_group_enabled, -host.id host_id, -host.uuid host_uuid, -host.name host_name, -vm_template.id template_id, -vm_template.uuid template_uuid, -vm_template.name template_name, -vm_template.display_text template_display_text, -vm_template.enable_password password_enabled, -iso.id iso_id, -iso.uuid iso_uuid, -iso.name iso_name, -iso.display_text iso_display_text, -service_offering.id service_offering_id, -disk_offering.uuid service_offering_uuid, -service_offering.cpu cpu, -service_offering.speed speed, -service_offering.ram_size ram_size, -disk_offering.name service_offering_name, -storage_pool.id pool_id, -storage_pool.uuid pool_uuid, -storage_pool.pool_type pool_type, -volumes.id volume_id, -volumes.uuid volume_uuid, -volumes.device_id volume_device_id, -volumes.volume_type volume_type, -security_group.id security_group_id, -security_group.uuid security_group_uuid, -security_group.name security_group_name, -security_group.description security_group_description, -nics.id nic_id, -nics.uuid nic_uuid, -nics.network_id network_id, -nics.ip4_address ip_address, -nics.default_nic is_default_nic, -nics.gateway gateway, -nics.netmask netmask, -nics.mac_address mac_address, -nics.broadcast_uri broadcast_uri, -nics.isolation_uri isolation_uri, -vpc.id vpc_id, -vpc.uuid vpc_uuid, -networks.uuid network_uuid, -networks.traffic_type traffic_type, -networks.guest_type guest_type, -user_ip_address.id public_ip_id, -user_ip_address.uuid public_ip_uuid, -user_ip_address.public_ip_address public_ip_address, -ssh_keypairs.keypair_name keypair_name, -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 user_vm -inner join vm_instance on vm_instance.id = user_vm.id and vm_instance.removed is NULL -inner join account on vm_instance.account_id=account.id -inner join domain on vm_instance.domain_id=domain.id -left join guest_os on vm_instance.guest_os_id = guest_os.id -left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id -left join projects on projects.project_account_id = account.id -left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id -left join instance_group on instance_group_vm_map.group_id=instance_group.id -left join data_center on vm_instance.data_center_id=data_center.id -left join host on vm_instance.host_id=host.id -left join vm_template on vm_instance.vm_template_id=vm_template.id -left join vm_template iso on iso.id=user_vm.iso_id -left join service_offering on vm_instance.service_offering_id=service_offering.id -left join disk_offering on vm_instance.service_offering_id=disk_offering.id -left join volumes on vm_instance.id=volumes.instance_id -left join storage_pool on volumes.pool_id=storage_pool.id -left join security_group_vm_map on vm_instance.id=security_group_vm_map.instance_id -left join security_group on security_group_vm_map.security_group_id=security_group.id -left join nics on vm_instance.id=nics.instance_id -left join networks on nics.network_id=networks.id -left join vpc on networks.vpc_id = vpc.id -left join user_ip_address on user_ip_address.vm_id=vm_instance.id -left join user_vm_details on user_vm_details.vm_id=vm_instance.id and user_vm_details.name = "SSH.PublicKey" -left join ssh_keypairs on ssh_keypairs.public_key = user_vm_details.value -left join resource_tags on resource_tags.resource_id = vm_instance.id and resource_tags.resource_type = "UserVm" -left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "VirtualMachine" and async_job.job_status = 0; + select + vm_instance.id id, + vm_instance.name name, + user_vm.display_name display_name, + user_vm.user_data user_data, + 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, + instance_group.id instance_group_id, + instance_group.uuid instance_group_uuid, + instance_group.name instance_group_name, + vm_instance.uuid uuid, + vm_instance.last_host_id last_host_id, + vm_instance.vm_type type, + vm_instance.vnc_password vnc_password, + vm_instance.limit_cpu_use limit_cpu_use, + vm_instance.created created, + vm_instance.state state, + vm_instance.removed removed, + vm_instance.ha_enabled ha_enabled, + vm_instance.hypervisor_type hypervisor_type, + vm_instance.instance_name instance_name, + vm_instance.guest_os_id guest_os_id, + guest_os.uuid guest_os_uuid, + vm_instance.pod_id pod_id, + host_pod_ref.uuid pod_uuid, + vm_instance.private_ip_address private_ip_address, + vm_instance.private_mac_address private_mac_address, + vm_instance.vm_type vm_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + data_center.is_security_group_enabled security_group_enabled, + host.id host_id, + host.uuid host_uuid, + host.name host_name, + vm_template.id template_id, + vm_template.uuid template_uuid, + vm_template.name template_name, + vm_template.display_text template_display_text, + vm_template.enable_password password_enabled, + iso.id iso_id, + iso.uuid iso_uuid, + iso.name iso_name, + iso.display_text iso_display_text, + service_offering.id service_offering_id, + disk_offering.uuid service_offering_uuid, + service_offering.cpu cpu, + service_offering.speed speed, + service_offering.ram_size ram_size, + disk_offering.name service_offering_name, + storage_pool.id pool_id, + storage_pool.uuid pool_uuid, + storage_pool.pool_type pool_type, + volumes.id volume_id, + volumes.uuid volume_uuid, + volumes.device_id volume_device_id, + volumes.volume_type volume_type, + security_group.id security_group_id, + security_group.uuid security_group_uuid, + security_group.name security_group_name, + security_group.description security_group_description, + nics.id nic_id, + nics.uuid nic_uuid, + nics.network_id network_id, + nics.ip4_address ip_address, + nics.default_nic is_default_nic, + nics.gateway gateway, + nics.netmask netmask, + nics.mac_address mac_address, + nics.broadcast_uri broadcast_uri, + nics.isolation_uri isolation_uri, + vpc.id vpc_id, + vpc.uuid vpc_uuid, + networks.uuid network_uuid, + networks.traffic_type traffic_type, + networks.guest_type guest_type, + user_ip_address.id public_ip_id, + user_ip_address.uuid public_ip_uuid, + user_ip_address.public_ip_address public_ip_address, + ssh_keypairs.keypair_name keypair_name, + 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`.`user_vm` + inner join + `cloud`.`vm_instance` ON vm_instance.id = user_vm.id + and vm_instance.removed is NULL + inner join + `cloud`.`account` ON vm_instance.account_id = account.id + inner join + `cloud`.`domain` ON vm_instance.domain_id = domain.id + left join + `cloud`.`guest_os` ON vm_instance.guest_os_id = guest_os.id + left join + `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`instance_group_vm_map` ON vm_instance.id = instance_group_vm_map.instance_id + left join + `cloud`.`instance_group` ON instance_group_vm_map.group_id = instance_group.id + left join + `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id + left join + `cloud`.`host` ON vm_instance.host_id = host.id + left join + `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id + left join + `cloud`.`vm_template` iso ON iso.id = user_vm.iso_id + left join + `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id + left join + `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id + left join + `cloud`.`volumes` ON vm_instance.id = volumes.instance_id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`security_group_vm_map` ON vm_instance.id = security_group_vm_map.instance_id + left join + `cloud`.`security_group` ON security_group_vm_map.security_group_id = security_group.id + left join + `cloud`.`nics` ON vm_instance.id = nics.instance_id + left join + `cloud`.`networks` ON nics.network_id = networks.id + left join + `cloud`.`vpc` ON networks.vpc_id = vpc.id + left join + `cloud`.`user_ip_address` ON user_ip_address.vm_id = vm_instance.id + left join + `cloud`.`user_vm_details` ON user_vm_details.vm_id = vm_instance.id + and user_vm_details.name = 'SSH.PublicKey' + left join + `cloud`.`ssh_keypairs` ON ssh_keypairs.public_key = user_vm_details.value + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = vm_instance.id + and resource_tags.resource_type = 'UserVm' + left join + `cloud`.`async_job` ON async_job.instance_id = vm_instance.id + and async_job.instance_type = 'VirtualMachine' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`domain_router_view`; -CREATE VIEW domain_router_view AS -select -vm_instance.id id, -vm_instance.name name, -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, -vm_instance.uuid uuid, -vm_instance.created created, -vm_instance.state state, -vm_instance.removed removed, -vm_instance.pod_id pod_id, -vm_instance.instance_name instance_name, -host_pod_ref.uuid pod_uuid, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -data_center.dns1 dns1, -data_center.dns2 dns2, -host.id host_id, -host.uuid host_uuid, -host.name host_name, -vm_template.id template_id, -vm_template.uuid template_uuid, -service_offering.id service_offering_id, -disk_offering.uuid service_offering_uuid, -disk_offering.name service_offering_name, -nics.id nic_id, -nics.uuid nic_uuid, -nics.network_id network_id, -nics.ip4_address ip_address, -nics.default_nic is_default_nic, -nics.gateway gateway, -nics.netmask netmask, -nics.mac_address mac_address, -nics.broadcast_uri broadcast_uri, -nics.isolation_uri isolation_uri, -vpc.id vpc_id, -vpc.uuid vpc_uuid, -networks.uuid network_uuid, -networks.name network_name, -networks.network_domain network_domain, -networks.traffic_type traffic_type, -networks.guest_type guest_type, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id, -domain_router.template_version template_version, -domain_router.scripts_version scripts_version, -domain_router.is_redundant_router is_redundant_router, -domain_router.redundant_state redundant_state, -domain_router.stop_pending stop_pending -from domain_router -inner join vm_instance on vm_instance.id = domain_router.id -inner join account on vm_instance.account_id=account.id -inner join domain on vm_instance.domain_id=domain.id -left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id -left join projects on projects.project_account_id = account.id -left join data_center on vm_instance.data_center_id=data_center.id -left join host on vm_instance.host_id=host.id -left join vm_template on vm_instance.vm_template_id=vm_template.id -left join service_offering on vm_instance.service_offering_id=service_offering.id -left join disk_offering on vm_instance.service_offering_id=disk_offering.id -left join volumes on vm_instance.id=volumes.instance_id -left join storage_pool on volumes.pool_id=storage_pool.id -left join nics on vm_instance.id=nics.instance_id -left join networks on nics.network_id=networks.id -left join vpc on networks.vpc_id = vpc.id -left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "DomainRouter" and async_job.job_status = 0; +CREATE VIEW `cloud`.`domain_router_view` AS + select + vm_instance.id id, + vm_instance.name name, + 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, + vm_instance.uuid uuid, + vm_instance.created created, + vm_instance.state state, + vm_instance.removed removed, + vm_instance.pod_id pod_id, + vm_instance.instance_name instance_name, + host_pod_ref.uuid pod_uuid, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + data_center.dns1 dns1, + data_center.dns2 dns2, + host.id host_id, + host.uuid host_uuid, + host.name host_name, + vm_template.id template_id, + vm_template.uuid template_uuid, + service_offering.id service_offering_id, + disk_offering.uuid service_offering_uuid, + disk_offering.name service_offering_name, + nics.id nic_id, + nics.uuid nic_uuid, + nics.network_id network_id, + nics.ip4_address ip_address, + nics.default_nic is_default_nic, + nics.gateway gateway, + nics.netmask netmask, + nics.mac_address mac_address, + nics.broadcast_uri broadcast_uri, + nics.isolation_uri isolation_uri, + vpc.id vpc_id, + vpc.uuid vpc_uuid, + networks.uuid network_uuid, + networks.name network_name, + networks.network_domain network_domain, + networks.traffic_type traffic_type, + networks.guest_type guest_type, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id, + domain_router.template_version template_version, + domain_router.scripts_version scripts_version, + domain_router.is_redundant_router is_redundant_router, + domain_router.redundant_state redundant_state, + domain_router.stop_pending stop_pending + from + `cloud`.`domain_router` + inner join + `cloud`.`vm_instance` ON vm_instance.id = domain_router.id + inner join + `cloud`.`account` ON vm_instance.account_id = account.id + inner join + `cloud`.`domain` ON vm_instance.domain_id = domain.id + left join + `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id + left join + `cloud`.`host` ON vm_instance.host_id = host.id + left join + `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id + left join + `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id + left join + `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id + left join + `cloud`.`volumes` ON vm_instance.id = volumes.instance_id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`nics` ON vm_instance.id = nics.instance_id + left join + `cloud`.`networks` ON nics.network_id = networks.id + left join + `cloud`.`vpc` ON networks.vpc_id = vpc.id + left join + `cloud`.`async_job` ON async_job.instance_id = vm_instance.id + and async_job.instance_type = 'DomainRouter' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`security_group_view`; -CREATE VIEW security_group_view AS -select -security_group.id id, -security_group.name name, -security_group.description description, -security_group.uuid uuid, -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, -security_group_rule.id rule_id, -security_group_rule.uuid rule_uuid, -security_group_rule.type rule_type, -security_group_rule.start_port rule_start_port, -security_group_rule.end_port rule_end_port, -security_group_rule.protocol rule_protocol, -security_group_rule.allowed_network_id rule_allowed_network_id, -security_group_rule.allowed_ip_cidr rule_allowed_ip_cidr, -security_group_rule.create_status rule_create_status, -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 security_group -left join security_group_rule on security_group.id = security_group_rule.security_group_id -inner join account on security_group.account_id=account.id -inner join domain on security_group.domain_id=domain.id -left join projects on projects.project_account_id = security_group.account_id -left join resource_tags on resource_tags.resource_id = security_group.id and resource_tags.resource_type = "SecurityGroup" -left join async_job on async_job.instance_id = security_group.id and async_job.instance_type = "SecurityGroup" and async_job.job_status = 0; +CREATE VIEW `cloud`.`security_group_view` AS + select + security_group.id id, + security_group.name name, + security_group.description description, + security_group.uuid uuid, + 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, + security_group_rule.id rule_id, + security_group_rule.uuid rule_uuid, + security_group_rule.type rule_type, + security_group_rule.start_port rule_start_port, + security_group_rule.end_port rule_end_port, + security_group_rule.protocol rule_protocol, + security_group_rule.allowed_network_id rule_allowed_network_id, + security_group_rule.allowed_ip_cidr rule_allowed_ip_cidr, + security_group_rule.create_status rule_create_status, + 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`.`security_group` + left join + `cloud`.`security_group_rule` ON security_group.id = security_group_rule.security_group_id + inner join + `cloud`.`account` ON security_group.account_id = account.id + inner join + `cloud`.`domain` ON security_group.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = security_group.account_id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = security_group.id + and resource_tags.resource_type = 'SecurityGroup' + left join + `cloud`.`async_job` ON async_job.instance_id = security_group.id + and async_job.instance_type = 'SecurityGroup' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`resource_tag_view`; -CREATE VIEW resource_tag_view AS -select -resource_tags.id, -resource_tags.uuid, -resource_tags.key, -resource_tags.value, -resource_tags.resource_id, -resource_tags.resource_uuid, -resource_tags.resource_type, -resource_tags.customer, -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 -from resource_tags -inner join account on resource_tags.account_id=account.id -inner join domain on resource_tags.domain_id=domain.id -left join projects on projects.project_account_id = resource_tags.account_id; +CREATE VIEW `cloud`.`resource_tag_view` AS + select + resource_tags.id, + resource_tags.uuid, + resource_tags.key, + resource_tags.value, + resource_tags.resource_id, + resource_tags.resource_uuid, + resource_tags.resource_type, + resource_tags.customer, + 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 + from + `cloud`.`resource_tags` + inner join + `cloud`.`account` ON resource_tags.account_id = account.id + inner join + `cloud`.`domain` ON resource_tags.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = resource_tags.account_id; DROP VIEW IF EXISTS `cloud`.`event_view`; -CREATE VIEW event_view AS -select -event.id, -event.uuid, -event.type, -event.state, -event.description, -event.created, -event.level, -event.parameters, -event.start_id, -eve.uuid start_uuid, -event.user_id, -user.username user_name, -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 -from event -inner join account on event.account_id=account.id -inner join domain on event.domain_id=domain.id -inner join user on event.user_id = user.id -left join projects on projects.project_account_id = event.account_id -left join event eve on event.start_id = eve.id; +CREATE VIEW `cloud`.`event_view` AS + select + event.id, + event.uuid, + event.type, + event.state, + event.description, + event.created, + event.level, + event.parameters, + event.start_id, + eve.uuid start_uuid, + event.user_id, + user.username user_name, + 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 + from + `cloud`.`event` + inner join + `cloud`.`account` ON event.account_id = account.id + inner join + `cloud`.`domain` ON event.domain_id = domain.id + inner join + `cloud`.`user` ON event.user_id = user.id + left join + `cloud`.`projects` ON projects.project_account_id = event.account_id + left join + `cloud`.`event` eve ON event.start_id = eve.id; DROP VIEW IF EXISTS `cloud`.`instance_group_view`; -CREATE VIEW instance_group_view AS -select -instance_group.id, -instance_group.uuid, -instance_group.name, -instance_group.removed, -instance_group.created, -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 -from instance_group -inner join account on instance_group.account_id=account.id -inner join domain on account.domain_id=domain.id -left join projects on projects.project_account_id = instance_group.account_id; +CREATE VIEW `cloud`.`instance_group_view` AS + select + instance_group.id, + instance_group.uuid, + instance_group.name, + instance_group.removed, + instance_group.created, + 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 + from + `cloud`.`instance_group` + inner join + `cloud`.`account` ON instance_group.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = instance_group.account_id; DROP VIEW IF EXISTS `cloud`.`user_view`; -CREATE VIEW user_view AS -select -user.id, -user.uuid, -user.username, -user.password, -user.firstname, -user.lastname, -user.email, -user.state, -user.api_key, -user.secret_key, -user.created, -user.removed, -user.timezone, -user.registration_token, -user.is_registered, -user.incorrect_login_attempts, -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, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from user -inner join account on user.account_id = account.id -inner join domain on account.domain_id=domain.id -left join async_job on async_job.instance_id = user.id and async_job.instance_type = "User" and async_job.job_status = 0; - - +CREATE VIEW `cloud`.`user_view` AS + select + user.id, + user.uuid, + user.username, + user.password, + user.firstname, + user.lastname, + user.email, + user.state, + user.api_key, + user.secret_key, + user.created, + user.removed, + user.timezone, + user.registration_token, + user.is_registered, + user.incorrect_login_attempts, + 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, + 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`.`user` + inner join + `cloud`.`account` ON user.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`async_job` ON async_job.instance_id = user.id + and async_job.instance_type = 'User' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`project_view`; -CREATE VIEW project_view AS -select -projects.id, -projects.uuid, -projects.name, -projects.display_text, -projects.state, -projects.removed, -projects.created, -account.account_name owner, -pacct.account_id, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -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 -from projects -inner join domain on projects.domain_id=domain.id -inner join project_account on projects.id = project_account.project_id and project_account.account_role = "Admin" -inner join account on account.id = project_account.account_id -left join resource_tags on resource_tags.resource_id = projects.id and resource_tags.resource_type = "Project" -left join project_account pacct on projects.id = pacct.project_id; +CREATE VIEW `cloud`.`project_view` AS + select + projects.id, + projects.uuid, + projects.name, + projects.display_text, + projects.state, + projects.removed, + projects.created, + account.account_name owner, + pacct.account_id, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + 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 + from + `cloud`.`projects` + inner join + `cloud`.`domain` ON projects.domain_id = domain.id + inner join + `cloud`.`project_account` ON projects.id = project_account.project_id + and project_account.account_role = 'Admin' + inner join + `cloud`.`account` ON account.id = project_account.account_id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = projects.id + and resource_tags.resource_type = 'Project' + left join + `cloud`.`project_account` pacct ON projects.id = pacct.project_id; DROP VIEW IF EXISTS `cloud`.`project_account_view`; -CREATE VIEW project_account_view AS -select -project_account.id, -account.id account_id, -account.uuid account_uuid, -account.account_name, -account.type account_type, -project_account.account_role, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from project_account -inner join account on project_account.account_id = account.id -inner join domain on account.domain_id=domain.id -inner join projects on projects.id = project_account.project_id; +CREATE VIEW `cloud`.`project_account_view` AS + select + project_account.id, + account.id account_id, + account.uuid account_uuid, + account.account_name, + account.type account_type, + project_account.account_role, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`project_account` + inner join + `cloud`.`account` ON project_account.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + inner join + `cloud`.`projects` ON projects.id = project_account.project_id; DROP VIEW IF EXISTS `cloud`.`project_invitation_view`; -CREATE VIEW project_invitation_view AS -select -project_invitations.id, -project_invitations.uuid, -project_invitations.email, -project_invitations.created, -project_invitations.state, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -account.id account_id, -account.uuid account_uuid, -account.account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from project_invitations -left join account on project_invitations.account_id = account.id -left join domain on project_invitations.domain_id=domain.id -left join projects on projects.id = project_invitations.project_id; +CREATE VIEW `cloud`.`project_invitation_view` AS + select + project_invitations.id, + project_invitations.uuid, + project_invitations.email, + project_invitations.created, + project_invitations.state, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + account.id account_id, + account.uuid account_uuid, + account.account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`project_invitations` + left join + `cloud`.`account` ON project_invitations.account_id = account.id + left join + `cloud`.`domain` ON project_invitations.domain_id = domain.id + left join + `cloud`.`projects` ON projects.id = project_invitations.project_id; DROP VIEW IF EXISTS `cloud`.`host_view`; -CREATE VIEW host_view AS -select -host.id, -host.uuid, -host.name, -host.status, -host.disconnected, -host.type, -host.private_ip_address, -host.version, -host.hypervisor_type, -host.hypervisor_version, -host.capabilities, -host.last_ping, -host.created, -host.removed, -host.resource_state, -host.mgmt_server_id, -host.cpus, -host.speed, -host.ram, -cluster.id cluster_id, -cluster.uuid cluster_uuid, -cluster.name cluster_name, -cluster.cluster_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -host_pod_ref.id pod_id, -host_pod_ref.uuid pod_uuid, -host_pod_ref.name pod_name, -host_tags.tag, -guest_os_category.id guest_os_category_id, -guest_os_category.uuid guest_os_category_uuid, -guest_os_category.name guest_os_category_name, -mem_caps.used_capacity memory_used_capacity, -mem_caps.reserved_capacity memory_reserved_capacity, -cpu_caps.used_capacity cpu_used_capacity, -cpu_caps.reserved_capacity cpu_reserved_capacity, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from host -left join cluster on host.cluster_id = cluster.id -left join data_center on host.data_center_id = data_center.id -left join host_pod_ref on host.pod_id = host_pod_ref.id -left join host_details on host.id = host_details.id and host_details.name = "guest.os.category.id" -left join guest_os_category on guest_os_category.id = CONVERT( host_details.value, UNSIGNED ) -left join host_tags on host_tags.host_id = host.id -left join op_host_capacity mem_caps on host.id = mem_caps.host_id and mem_caps.capacity_type = 0 -left join op_host_capacity cpu_caps on host.id = cpu_caps.host_id and cpu_caps.capacity_type = 1 -left join async_job on async_job.instance_id = host.id and async_job.instance_type = "Host" and async_job.job_status = 0; +CREATE VIEW `cloud`.`host_view` AS + select + host.id, + host.uuid, + host.name, + host.status, + host.disconnected, + host.type, + host.private_ip_address, + host.version, + host.hypervisor_type, + host.hypervisor_version, + host.capabilities, + host.last_ping, + host.created, + host.removed, + host.resource_state, + host.mgmt_server_id, + host.cpus, + host.speed, + host.ram, + cluster.id cluster_id, + cluster.uuid cluster_uuid, + cluster.name cluster_name, + cluster.cluster_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + host_pod_ref.id pod_id, + host_pod_ref.uuid pod_uuid, + host_pod_ref.name pod_name, + host_tags.tag, + guest_os_category.id guest_os_category_id, + guest_os_category.uuid guest_os_category_uuid, + guest_os_category.name guest_os_category_name, + mem_caps.used_capacity memory_used_capacity, + mem_caps.reserved_capacity memory_reserved_capacity, + cpu_caps.used_capacity cpu_used_capacity, + cpu_caps.reserved_capacity cpu_reserved_capacity, + 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`.`host` + left join + `cloud`.`cluster` ON host.cluster_id = cluster.id + left join + `cloud`.`data_center` ON host.data_center_id = data_center.id + left join + `cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id + left join + `cloud`.`host_details` ON host.id = host_details.id + and host_details.name = 'guest.os.category.id' + left join + `cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED) + left join + `cloud`.`host_tags` ON host_tags.host_id = host.id + left join + `cloud`.`op_host_capacity` mem_caps ON host.id = mem_caps.host_id + and mem_caps.capacity_type = 0 + left join + `cloud`.`op_host_capacity` cpu_caps ON host.id = cpu_caps.host_id + and cpu_caps.capacity_type = 1 + left join + `cloud`.`async_job` ON async_job.instance_id = host.id + and async_job.instance_type = 'Host' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`volume_view`; -CREATE VIEW volume_view AS -select -volumes.id, -volumes.uuid, -volumes.name, -volumes.device_id, -volumes.volume_type, -volumes.size, -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, -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, -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 volumes -inner join account on volumes.account_id=account.id -inner join domain on volumes.domain_id=domain.id -left join projects on projects.project_account_id = account.id -left join data_center on volumes.data_center_id = data_center.id -left join vm_instance on volumes.instance_id = vm_instance.id -left join user_vm on user_vm.id = vm_instance.id -left join volume_host_ref on volumes.id = volume_host_ref.volume_id and volumes.data_center_id = volume_host_ref.zone_id -left join disk_offering on volumes.disk_offering_id = disk_offering.id -left join storage_pool on volumes.pool_id = storage_pool.id -left join cluster on storage_pool.cluster_id = cluster.id -left join vm_template on volumes.template_id = vm_template.id -left join resource_tags on resource_tags.resource_id = volumes.id and resource_tags.resource_type = "Volume" -left join async_job on async_job.instance_id = volumes.id and async_job.instance_type = "Volume" and async_job.job_status = 0; +CREATE VIEW `cloud`.`volume_view` AS + select + volumes.id, + volumes.uuid, + volumes.name, + volumes.device_id, + volumes.volume_type, + volumes.size, + 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, + 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, + 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`.`account_netstats_view`; -CREATE VIEW account_netstats_view AS -SELECT account_id, -sum(net_bytes_received)+ sum(current_bytes_received) as bytesReceived, -sum(net_bytes_sent)+ sum(current_bytes_sent) as bytesSent -FROM user_statistics -group by account_id; +CREATE VIEW `cloud`.`account_netstats_view` AS + SELECT + account_id, + sum(net_bytes_received) + sum(current_bytes_received) as bytesReceived, + sum(net_bytes_sent) + sum(current_bytes_sent) as bytesSent + FROM + `cloud`.`user_statistics` + group by account_id; DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`; -CREATE VIEW account_vmstats_view AS -SELECT account_id, state, count(*) as vmcount -from vm_instance -group by account_id, state; +CREATE VIEW `cloud`.`account_vmstats_view` AS + SELECT + account_id, state, count(*) as vmcount + from + `cloud`.`vm_instance` + group by account_id , state; DROP VIEW IF EXISTS `cloud`.`free_ip_view`; -CREATE VIEW free_ip_view AS -select count(user_ip_address.id) free_ip -from user_ip_address -inner join vlan on vlan.id = user_ip_address.vlan_db_id and vlan.vlan_type = "VirtualNetwork" -where state = "Free"; +CREATE VIEW `cloud`.`free_ip_view` AS + select + count(user_ip_address.id) free_ip + from + `cloud`.`user_ip_address` + inner join + `cloud`.`vlan` ON vlan.id = user_ip_address.vlan_db_id + and vlan.vlan_type = 'VirtualNetwork' + where + state = 'Free'; DROP VIEW IF EXISTS `cloud`.`account_view`; -CREATE VIEW account_view AS -select -account.id, -account.uuid, -account.account_name, -account.type, -account.state, -account.removed, -account.cleanup_needed, -account.network_domain, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -account_netstats_view.bytesReceived, -account_netstats_view.bytesSent, -vmlimit.max vmLimit, -vmcount.count vmTotal, -runningvm.vmcount runningVms, -stoppedvm.vmcount stoppedVms, -iplimit.max ipLimit, -ipcount.count ipTotal, -free_ip_view.free_ip ipFree, -volumelimit.max volumeLimit, -volumecount.count volumeTotal, -snapshotlimit.max snapshotLimit, -snapshotcount.count snapshotTotal, -templatelimit.max templateLimit, -templatecount.count templateTotal, -vpclimit.max vpcLimit, -vpccount.count vpcTotal, -projectlimit.max projectLimit, -projectcount.count projectTotal, -networklimit.max networkLimit, -networkcount.count networkTotal, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from free_ip_view, account -inner join domain on account.domain_id=domain.id -left join data_center on account.default_zone_id = data_center.id -left join account_netstats_view on account.id = account_netstats_view.account_id -left join resource_limit vmlimit on account.id = vmlimit.account_id and vmlimit.type = "user_vm" -left join resource_count vmcount on account.id = vmcount.account_id and vmcount.type = "user_vm" -left join account_vmstats_view runningvm on account.id = runningvm.account_id and runningvm.state = "Running" -left join account_vmstats_view stoppedvm on account.id = stoppedvm.account_id and stoppedvm.state = "Stopped" -left join resource_limit iplimit on account.id = iplimit.account_id and iplimit.type = "public_ip" -left join resource_count ipcount on account.id = ipcount.account_id and ipcount.type = "public_ip" -left join resource_limit volumelimit on account.id = volumelimit.account_id and volumelimit.type = "volume" -left join resource_count volumecount on account.id = volumecount.account_id and volumecount.type = "volume" -left join resource_limit snapshotlimit on account.id = snapshotlimit.account_id and snapshotlimit.type = "snapshot" -left join resource_count snapshotcount on account.id = snapshotcount.account_id and snapshotcount.type = "snapshot" -left join resource_limit templatelimit on account.id = templatelimit.account_id and templatelimit.type = "template" -left join resource_count templatecount on account.id = templatecount.account_id and templatecount.type = "template" -left join resource_limit vpclimit on account.id = vpclimit.account_id and vpclimit.type = "vpc" -left join resource_count vpccount on account.id = vpccount.account_id and vpccount.type = "vpc" -left join resource_limit projectlimit on account.id = projectlimit.account_id and projectlimit.type = "project" -left join resource_count projectcount on account.id = projectcount.account_id and projectcount.type = "project" -left join resource_limit networklimit on account.id = networklimit.account_id and networklimit.type = "network" -left join resource_count networkcount on account.id = networkcount.account_id and networkcount.type = "network" -left join async_job on async_job.instance_id = account.id and async_job.instance_type = "Account" and async_job.job_status = 0; +CREATE VIEW `cloud`.`account_view` AS + select + account.id, + account.uuid, + account.account_name, + account.type, + account.state, + account.removed, + account.cleanup_needed, + account.network_domain, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + account_netstats_view.bytesReceived, + account_netstats_view.bytesSent, + vmlimit.max vmLimit, + vmcount.count vmTotal, + runningvm.vmcount runningVms, + stoppedvm.vmcount stoppedVms, + iplimit.max ipLimit, + ipcount.count ipTotal, + free_ip_view.free_ip ipFree, + volumelimit.max volumeLimit, + volumecount.count volumeTotal, + snapshotlimit.max snapshotLimit, + snapshotcount.count snapshotTotal, + templatelimit.max templateLimit, + templatecount.count templateTotal, + vpclimit.max vpcLimit, + vpccount.count vpcTotal, + projectlimit.max projectLimit, + projectcount.count projectTotal, + networklimit.max networkLimit, + networkcount.count networkTotal, + 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`.`free_ip_view`, + `cloud`.`account` + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`data_center` ON account.default_zone_id = data_center.id + left join + `cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id + left join + `cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id + and vmlimit.type = 'user_vm' + left join + `cloud`.`resource_count` vmcount ON account.id = vmcount.account_id + and vmcount.type = 'user_vm' + left join + `cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id + and runningvm.state = 'Running' + left join + `cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id + and stoppedvm.state = 'Stopped' + left join + `cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id + and iplimit.type = 'public_ip' + left join + `cloud`.`resource_count` ipcount ON account.id = ipcount.account_id + and ipcount.type = 'public_ip' + left join + `cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id + and volumelimit.type = 'volume' + left join + `cloud`.`resource_count` volumecount ON account.id = volumecount.account_id + and volumecount.type = 'volume' + left join + `cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id + and snapshotlimit.type = 'snapshot' + left join + `cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id + and snapshotcount.type = 'snapshot' + left join + `cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id + and templatelimit.type = 'template' + left join + `cloud`.`resource_count` templatecount ON account.id = templatecount.account_id + and templatecount.type = 'template' + left join + `cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id + and vpclimit.type = 'vpc' + left join + `cloud`.`resource_count` vpccount ON account.id = vpccount.account_id + and vpccount.type = 'vpc' + left join + `cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id + and projectlimit.type = 'project' + left join + `cloud`.`resource_count` projectcount ON account.id = projectcount.account_id + and projectcount.type = 'project' + left join + `cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id + and networklimit.type = 'network' + left join + `cloud`.`resource_count` networkcount ON account.id = networkcount.account_id + and networkcount.type = 'network' + left join + `cloud`.`async_job` ON async_job.instance_id = account.id + and async_job.instance_type = 'Account' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`async_job_view`; -CREATE VIEW async_job_view AS -select -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, -user.id user_id, -user.uuid user_uuid, -async_job.id, -async_job.uuid, -async_job.job_cmd, -async_job.job_status, -async_job.job_process_status, -async_job.job_result_code, -async_job.job_result, -async_job.created, -async_job.removed, -async_job.instance_type, -async_job.instance_id, -CASE -WHEN async_job.instance_type = 'Volume' THEN volumes.uuid -WHEN async_job.instance_type = 'Template' or async_job.instance_type = 'Iso' THEN vm_template.uuid -WHEN async_job.instance_type = 'VirtualMachine' or async_job.instance_type = 'ConsoleProxy' or async_job.instance_type = 'SystemVm' or async_job.instance_type = 'DomainRouter' THEN vm_instance.uuid -WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid -WHEN async_job.instance_type = 'Host' THEN host.uuid -WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid -WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid -WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid -WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid -WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid -WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid -WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid -WHEN async_job.instance_type = 'Account' THEN acct.uuid -WHEN async_job.instance_type = 'User' THEN us.uuid -WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid -WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid -WHEN async_job.instance_type = 'Counter' THEN counter.uuid -WHEN async_job.instance_type = 'Condition' THEN conditions.uuid -WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid -WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid -WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid -ELSE null -END instance_uuid -from async_job -left join account on async_job.account_id = account.id -left join domain on domain.id = account.domain_id -left join user on async_job.user_id = user.id -left join volumes on async_job.instance_id = volumes.id -left join vm_template on async_job.instance_id = vm_template.id -left join vm_instance on async_job.instance_id = vm_instance.id -left join snapshots on async_job.instance_id = snapshots.id -left join host on async_job.instance_id = host.id -left join storage_pool on async_job.instance_id = storage_pool.id -left join user_ip_address on async_job.instance_id = user_ip_address.id -left join security_group on async_job.instance_id = security_group.id -left join physical_network on async_job.instance_id = physical_network.id -left join physical_network_traffic_types on async_job.instance_id = physical_network_traffic_types.id -left join physical_network_service_providers on async_job.instance_id = physical_network_service_providers.id -left join firewall_rules on async_job.instance_id = firewall_rules.id -left join account acct on async_job.instance_id = acct.id -left join user us on async_job.instance_id = us.id -left join static_routes on async_job.instance_id = static_routes.id -left join vpc_gateways on async_job.instance_id = vpc_gateways.id -left join counter on async_job.instance_id = counter.id -left join conditions on async_job.instance_id = conditions.id -left join autoscale_policies on async_job.instance_id = autoscale_policies.id -left join autoscale_vmprofiles on async_job.instance_id = autoscale_vmprofiles.id -left join autoscale_vmgroups on async_job.instance_id = autoscale_vmgroups.id; +CREATE VIEW `cloud`.`async_job_view` AS + select + 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, + user.id user_id, + user.uuid user_uuid, + async_job.id, + async_job.uuid, + async_job.job_cmd, + async_job.job_status, + async_job.job_process_status, + async_job.job_result_code, + async_job.job_result, + async_job.created, + async_job.removed, + async_job.instance_type, + async_job.instance_id, + CASE + WHEN async_job.instance_type = 'Volume' THEN volumes.uuid + WHEN + async_job.instance_type = 'Template' + or async_job.instance_type = 'Iso' + THEN + vm_template.uuid + WHEN + async_job.instance_type = 'VirtualMachine' + or async_job.instance_type = 'ConsoleProxy' + or async_job.instance_type = 'SystemVm' + or async_job.instance_type = 'DomainRouter' + THEN + vm_instance.uuid + WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid + WHEN async_job.instance_type = 'Host' THEN host.uuid + WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid + WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid + WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid + WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid + WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid + WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid + WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid + WHEN async_job.instance_type = 'Account' THEN acct.uuid + WHEN async_job.instance_type = 'User' THEN us.uuid + WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid + WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid + WHEN async_job.instance_type = 'Counter' THEN counter.uuid + WHEN async_job.instance_type = 'Condition' THEN conditions.uuid + WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid + WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid + WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid + ELSE null + END instance_uuid + from + `cloud`.`async_job` + left join + `cloud`.`account` ON async_job.account_id = account.id + left join + `cloud`.`domain` ON domain.id = account.domain_id + left join + `cloud`.`user` ON async_job.user_id = user.id + left join + `cloud`.`volumes` ON async_job.instance_id = volumes.id + left join + `cloud`.`vm_template` ON async_job.instance_id = vm_template.id + left join + `cloud`.`vm_instance` ON async_job.instance_id = vm_instance.id + left join + `cloud`.`snapshots` ON async_job.instance_id = snapshots.id + left join + `cloud`.`host` ON async_job.instance_id = host.id + left join + `cloud`.`storage_pool` ON async_job.instance_id = storage_pool.id + left join + `cloud`.`user_ip_address` ON async_job.instance_id = user_ip_address.id + left join + `cloud`.`security_group` ON async_job.instance_id = security_group.id + left join + `cloud`.`physical_network` ON async_job.instance_id = physical_network.id + left join + `cloud`.`physical_network_traffic_types` ON async_job.instance_id = physical_network_traffic_types.id + left join + `cloud`.`physical_network_service_providers` ON async_job.instance_id = physical_network_service_providers.id + left join + `cloud`.`firewall_rules` ON async_job.instance_id = firewall_rules.id + left join + `cloud`.`account` acct ON async_job.instance_id = acct.id + left join + `cloud`.`user` us ON async_job.instance_id = us.id + left join + `cloud`.`static_routes` ON async_job.instance_id = static_routes.id + left join + `cloud`.`vpc_gateways` ON async_job.instance_id = vpc_gateways.id + left join + `cloud`.`counter` ON async_job.instance_id = counter.id + left join + `cloud`.`conditions` ON async_job.instance_id = conditions.id + left join + `cloud`.`autoscale_policies` ON async_job.instance_id = autoscale_policies.id + left join + `cloud`.`autoscale_vmprofiles` ON async_job.instance_id = autoscale_vmprofiles.id + left join + `cloud`.`autoscale_vmgroups` ON async_job.instance_id = autoscale_vmgroups.id; DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; -CREATE VIEW storage_pool_view AS -select -storage_pool.id, -storage_pool.uuid, -storage_pool.name, -storage_pool.status, -storage_pool.path, -storage_pool.pool_type, -storage_pool.host_address, -storage_pool.created, -storage_pool.removed, -storage_pool.capacity_bytes, -cluster.id cluster_id, -cluster.uuid cluster_uuid, -cluster.name cluster_name, -cluster.cluster_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -host_pod_ref.id pod_id, -host_pod_ref.uuid pod_uuid, -host_pod_ref.name pod_name, -storage_pool_details.name tag, -op_host_capacity.used_capacity disk_used_capacity, -op_host_capacity.reserved_capacity disk_reserved_capacity, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from storage_pool -left join cluster on storage_pool.cluster_id = cluster.id -left join data_center on storage_pool.data_center_id = data_center.id -left join host_pod_ref on storage_pool.pod_id = host_pod_ref.id -left join storage_pool_details on storage_pool_details.pool_id = storage_pool.id and storage_pool_details.value = 'true' -left join op_host_capacity on storage_pool.id = op_host_capacity.host_id and op_host_capacity.capacity_type = 3 -left join async_job on async_job.instance_id = storage_pool.id and async_job.instance_type = "StoragePool" and async_job.job_status = 0; \ No newline at end of file +CREATE VIEW `cloud`.`storage_pool_view` AS + select + storage_pool.id, + storage_pool.uuid, + storage_pool.name, + storage_pool.status, + storage_pool.path, + storage_pool.pool_type, + storage_pool.host_address, + storage_pool.created, + storage_pool.removed, + storage_pool.capacity_bytes, + cluster.id cluster_id, + cluster.uuid cluster_uuid, + cluster.name cluster_name, + cluster.cluster_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + host_pod_ref.id pod_id, + host_pod_ref.uuid pod_uuid, + host_pod_ref.name pod_name, + storage_pool_details.name tag, + op_host_capacity.used_capacity disk_used_capacity, + op_host_capacity.reserved_capacity disk_reserved_capacity, + 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`.`storage_pool` + left join + `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id + left join + `cloud`.`data_center` ON storage_pool.data_center_id = data_center.id + left join + `cloud`.`host_pod_ref` ON storage_pool.pod_id = host_pod_ref.id + left join + `cloud`.`storage_pool_details` ON storage_pool_details.pool_id = storage_pool.id + and storage_pool_details.value = 'true' + left join + `cloud`.`op_host_capacity` ON storage_pool.id = op_host_capacity.host_id + and op_host_capacity.capacity_type = 3 + left join + `cloud`.`async_job` ON async_job.instance_id = storage_pool.id + and async_job.instance_type = 'StoragePool' + and async_job.job_status = 0; + +DROP VIEW IF EXISTS `cloud`.`disk_offering_view`; +CREATE VIEW `cloud`.`disk_offering_view` AS + select + disk_offering.id, + disk_offering.uuid, + disk_offering.name, + disk_offering.display_text, + disk_offering.disk_size, + disk_offering.created, + disk_offering.tags, + disk_offering.customized, + disk_offering.removed, + disk_offering.use_local_storage, + disk_offering.system_use, + disk_offering.sort_key, + disk_offering.type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`disk_offering` + left join + `cloud`.`domain` ON disk_offering.domain_id = domain.id; + +DROP VIEW IF EXISTS `cloud`.`service_offering_view`; +CREATE VIEW `cloud`.`service_offering_view` AS + select + service_offering.id, + disk_offering.uuid, + disk_offering.name, + disk_offering.display_text, + disk_offering.created, + disk_offering.tags, + disk_offering.removed, + disk_offering.use_local_storage, + disk_offering.system_use, + service_offering.cpu, + service_offering.speed, + service_offering.ram_size, + service_offering.nw_rate, + service_offering.mc_rate, + service_offering.ha_enabled, + service_offering.limit_cpu_use, + service_offering.host_tag, + service_offering.default_use, + service_offering.vm_type, + service_offering.sort_key, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`service_offering` + inner join + `cloud`.`disk_offering` ON service_offering.id = disk_offering.id + left join + `cloud`.`domain` ON disk_offering.domain_id = domain.id; + +DROP VIEW IF EXISTS `cloud`.`data_center_view`; +CREATE VIEW `cloud`.`data_center_view` AS + select + data_center.id, + data_center.uuid, + data_center.name, + data_center.is_security_group_enabled, + data_center.is_local_storage_enabled, + data_center.description, + data_center.dns1, + data_center.dns2, + data_center.internal_dns1, + data_center.internal_dns2, + data_center.guest_network_cidr, + data_center.domain, + data_center.networktype, + data_center.allocation_state, + data_center.zone_token, + data_center.dhcp_provider, + data_center.removed, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`data_center` + left join + `cloud`.`domain` ON data_center.domain_id = domain.id; \ No newline at end of file diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index a9d168d6eed..93949b8e4fa 100644 --- a/setup/db/db/schema-40to410.sql +++ b/setup/db/db/schema-40to410.sql @@ -141,808 +141,1124 @@ UPDATE `cloud`.`conditions` set uuid=id WHERE uuid is NULL; INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', '"detail.batch.query.size"', '2000', 'Default entity detail batch query size for listing'); ---- DB views for list api --- -use cloud; +-- DB views for list api DROP VIEW IF EXISTS `cloud`.`user_vm_view`; CREATE VIEW `cloud`.`user_vm_view` AS -select -vm_instance.id id, -vm_instance.name name, -user_vm.display_name display_name, -user_vm.user_data user_data, -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, -instance_group.id instance_group_id, -instance_group.uuid instance_group_uuid, -instance_group.name instance_group_name, -vm_instance.uuid uuid, -vm_instance.last_host_id last_host_id, -vm_instance.vm_type type, -vm_instance.vnc_password vnc_password, -vm_instance.limit_cpu_use limit_cpu_use, -vm_instance.created created, -vm_instance.state state, -vm_instance.removed removed, -vm_instance.ha_enabled ha_enabled, -vm_instance.hypervisor_type hypervisor_type, -vm_instance.instance_name instance_name, -vm_instance.guest_os_id guest_os_id, -guest_os.uuid guest_os_uuid, -vm_instance.pod_id pod_id, -host_pod_ref.uuid pod_uuid, -vm_instance.private_ip_address private_ip_address, -vm_instance.private_mac_address private_mac_address, -vm_instance.vm_type vm_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -data_center.is_security_group_enabled security_group_enabled, -host.id host_id, -host.uuid host_uuid, -host.name host_name, -vm_template.id template_id, -vm_template.uuid template_uuid, -vm_template.name template_name, -vm_template.display_text template_display_text, -vm_template.enable_password password_enabled, -iso.id iso_id, -iso.uuid iso_uuid, -iso.name iso_name, -iso.display_text iso_display_text, -service_offering.id service_offering_id, -disk_offering.uuid service_offering_uuid, -service_offering.cpu cpu, -service_offering.speed speed, -service_offering.ram_size ram_size, -disk_offering.name service_offering_name, -storage_pool.id pool_id, -storage_pool.uuid pool_uuid, -storage_pool.pool_type pool_type, -volumes.id volume_id, -volumes.uuid volume_uuid, -volumes.device_id volume_device_id, -volumes.volume_type volume_type, -security_group.id security_group_id, -security_group.uuid security_group_uuid, -security_group.name security_group_name, -security_group.description security_group_description, -nics.id nic_id, -nics.uuid nic_uuid, -nics.network_id network_id, -nics.ip4_address ip_address, -nics.default_nic is_default_nic, -nics.gateway gateway, -nics.netmask netmask, -nics.mac_address mac_address, -nics.broadcast_uri broadcast_uri, -nics.isolation_uri isolation_uri, -vpc.id vpc_id, -vpc.uuid vpc_uuid, -networks.uuid network_uuid, -networks.traffic_type traffic_type, -networks.guest_type guest_type, -user_ip_address.id public_ip_id, -user_ip_address.uuid public_ip_uuid, -user_ip_address.public_ip_address public_ip_address, -ssh_keypairs.keypair_name keypair_name, -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 user_vm -inner join vm_instance on vm_instance.id = user_vm.id and vm_instance.removed is NULL -inner join account on vm_instance.account_id=account.id -inner join domain on vm_instance.domain_id=domain.id -left join guest_os on vm_instance.guest_os_id = guest_os.id -left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id -left join projects on projects.project_account_id = account.id -left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id -left join instance_group on instance_group_vm_map.group_id=instance_group.id -left join data_center on vm_instance.data_center_id=data_center.id -left join host on vm_instance.host_id=host.id -left join vm_template on vm_instance.vm_template_id=vm_template.id -left join vm_template iso on iso.id=user_vm.iso_id -left join service_offering on vm_instance.service_offering_id=service_offering.id -left join disk_offering on vm_instance.service_offering_id=disk_offering.id -left join volumes on vm_instance.id=volumes.instance_id -left join storage_pool on volumes.pool_id=storage_pool.id -left join security_group_vm_map on vm_instance.id=security_group_vm_map.instance_id -left join security_group on security_group_vm_map.security_group_id=security_group.id -left join nics on vm_instance.id=nics.instance_id -left join networks on nics.network_id=networks.id -left join vpc on networks.vpc_id = vpc.id -left join user_ip_address on user_ip_address.vm_id=vm_instance.id -left join user_vm_details on user_vm_details.vm_id=vm_instance.id and user_vm_details.name = "SSH.PublicKey" -left join ssh_keypairs on ssh_keypairs.public_key = user_vm_details.value -left join resource_tags on resource_tags.resource_id = vm_instance.id and resource_tags.resource_type = "UserVm" -left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "VirtualMachine" and async_job.job_status = 0; + select + vm_instance.id id, + vm_instance.name name, + user_vm.display_name display_name, + user_vm.user_data user_data, + 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, + instance_group.id instance_group_id, + instance_group.uuid instance_group_uuid, + instance_group.name instance_group_name, + vm_instance.uuid uuid, + vm_instance.last_host_id last_host_id, + vm_instance.vm_type type, + vm_instance.vnc_password vnc_password, + vm_instance.limit_cpu_use limit_cpu_use, + vm_instance.created created, + vm_instance.state state, + vm_instance.removed removed, + vm_instance.ha_enabled ha_enabled, + vm_instance.hypervisor_type hypervisor_type, + vm_instance.instance_name instance_name, + vm_instance.guest_os_id guest_os_id, + guest_os.uuid guest_os_uuid, + vm_instance.pod_id pod_id, + host_pod_ref.uuid pod_uuid, + vm_instance.private_ip_address private_ip_address, + vm_instance.private_mac_address private_mac_address, + vm_instance.vm_type vm_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + data_center.is_security_group_enabled security_group_enabled, + host.id host_id, + host.uuid host_uuid, + host.name host_name, + vm_template.id template_id, + vm_template.uuid template_uuid, + vm_template.name template_name, + vm_template.display_text template_display_text, + vm_template.enable_password password_enabled, + iso.id iso_id, + iso.uuid iso_uuid, + iso.name iso_name, + iso.display_text iso_display_text, + service_offering.id service_offering_id, + disk_offering.uuid service_offering_uuid, + service_offering.cpu cpu, + service_offering.speed speed, + service_offering.ram_size ram_size, + disk_offering.name service_offering_name, + storage_pool.id pool_id, + storage_pool.uuid pool_uuid, + storage_pool.pool_type pool_type, + volumes.id volume_id, + volumes.uuid volume_uuid, + volumes.device_id volume_device_id, + volumes.volume_type volume_type, + security_group.id security_group_id, + security_group.uuid security_group_uuid, + security_group.name security_group_name, + security_group.description security_group_description, + nics.id nic_id, + nics.uuid nic_uuid, + nics.network_id network_id, + nics.ip4_address ip_address, + nics.default_nic is_default_nic, + nics.gateway gateway, + nics.netmask netmask, + nics.mac_address mac_address, + nics.broadcast_uri broadcast_uri, + nics.isolation_uri isolation_uri, + vpc.id vpc_id, + vpc.uuid vpc_uuid, + networks.uuid network_uuid, + networks.traffic_type traffic_type, + networks.guest_type guest_type, + user_ip_address.id public_ip_id, + user_ip_address.uuid public_ip_uuid, + user_ip_address.public_ip_address public_ip_address, + ssh_keypairs.keypair_name keypair_name, + 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`.`user_vm` + inner join + `cloud`.`vm_instance` ON vm_instance.id = user_vm.id + and vm_instance.removed is NULL + inner join + `cloud`.`account` ON vm_instance.account_id = account.id + inner join + `cloud`.`domain` ON vm_instance.domain_id = domain.id + left join + `cloud`.`guest_os` ON vm_instance.guest_os_id = guest_os.id + left join + `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`instance_group_vm_map` ON vm_instance.id = instance_group_vm_map.instance_id + left join + `cloud`.`instance_group` ON instance_group_vm_map.group_id = instance_group.id + left join + `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id + left join + `cloud`.`host` ON vm_instance.host_id = host.id + left join + `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id + left join + `cloud`.`vm_template` iso ON iso.id = user_vm.iso_id + left join + `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id + left join + `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id + left join + `cloud`.`volumes` ON vm_instance.id = volumes.instance_id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`security_group_vm_map` ON vm_instance.id = security_group_vm_map.instance_id + left join + `cloud`.`security_group` ON security_group_vm_map.security_group_id = security_group.id + left join + `cloud`.`nics` ON vm_instance.id = nics.instance_id + left join + `cloud`.`networks` ON nics.network_id = networks.id + left join + `cloud`.`vpc` ON networks.vpc_id = vpc.id + left join + `cloud`.`user_ip_address` ON user_ip_address.vm_id = vm_instance.id + left join + `cloud`.`user_vm_details` ON user_vm_details.vm_id = vm_instance.id + and user_vm_details.name = 'SSH.PublicKey' + left join + `cloud`.`ssh_keypairs` ON ssh_keypairs.public_key = user_vm_details.value + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = vm_instance.id + and resource_tags.resource_type = 'UserVm' + left join + `cloud`.`async_job` ON async_job.instance_id = vm_instance.id + and async_job.instance_type = 'VirtualMachine' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`domain_router_view`; -CREATE VIEW domain_router_view AS -select -vm_instance.id id, -vm_instance.name name, -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, -vm_instance.uuid uuid, -vm_instance.created created, -vm_instance.state state, -vm_instance.removed removed, -vm_instance.pod_id pod_id, -vm_instance.instance_name instance_name, -host_pod_ref.uuid pod_uuid, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -data_center.dns1 dns1, -data_center.dns2 dns2, -host.id host_id, -host.uuid host_uuid, -host.name host_name, -vm_template.id template_id, -vm_template.uuid template_uuid, -service_offering.id service_offering_id, -disk_offering.uuid service_offering_uuid, -disk_offering.name service_offering_name, -nics.id nic_id, -nics.uuid nic_uuid, -nics.network_id network_id, -nics.ip4_address ip_address, -nics.default_nic is_default_nic, -nics.gateway gateway, -nics.netmask netmask, -nics.mac_address mac_address, -nics.broadcast_uri broadcast_uri, -nics.isolation_uri isolation_uri, -vpc.id vpc_id, -vpc.uuid vpc_uuid, -networks.uuid network_uuid, -networks.name network_name, -networks.network_domain network_domain, -networks.traffic_type traffic_type, -networks.guest_type guest_type, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id, -domain_router.template_version template_version, -domain_router.scripts_version scripts_version, -domain_router.is_redundant_router is_redundant_router, -domain_router.redundant_state redundant_state, -domain_router.stop_pending stop_pending -from domain_router -inner join vm_instance on vm_instance.id = domain_router.id -inner join account on vm_instance.account_id=account.id -inner join domain on vm_instance.domain_id=domain.id -left join host_pod_ref on vm_instance.pod_id = host_pod_ref.id -left join projects on projects.project_account_id = account.id -left join data_center on vm_instance.data_center_id=data_center.id -left join host on vm_instance.host_id=host.id -left join vm_template on vm_instance.vm_template_id=vm_template.id -left join service_offering on vm_instance.service_offering_id=service_offering.id -left join disk_offering on vm_instance.service_offering_id=disk_offering.id -left join volumes on vm_instance.id=volumes.instance_id -left join storage_pool on volumes.pool_id=storage_pool.id -left join nics on vm_instance.id=nics.instance_id -left join networks on nics.network_id=networks.id -left join vpc on networks.vpc_id = vpc.id -left join async_job on async_job.instance_id = vm_instance.id and async_job.instance_type = "DomainRouter" and async_job.job_status = 0; +CREATE VIEW `cloud`.`domain_router_view` AS + select + vm_instance.id id, + vm_instance.name name, + 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, + vm_instance.uuid uuid, + vm_instance.created created, + vm_instance.state state, + vm_instance.removed removed, + vm_instance.pod_id pod_id, + vm_instance.instance_name instance_name, + host_pod_ref.uuid pod_uuid, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + data_center.dns1 dns1, + data_center.dns2 dns2, + host.id host_id, + host.uuid host_uuid, + host.name host_name, + vm_template.id template_id, + vm_template.uuid template_uuid, + service_offering.id service_offering_id, + disk_offering.uuid service_offering_uuid, + disk_offering.name service_offering_name, + nics.id nic_id, + nics.uuid nic_uuid, + nics.network_id network_id, + nics.ip4_address ip_address, + nics.default_nic is_default_nic, + nics.gateway gateway, + nics.netmask netmask, + nics.mac_address mac_address, + nics.broadcast_uri broadcast_uri, + nics.isolation_uri isolation_uri, + vpc.id vpc_id, + vpc.uuid vpc_uuid, + networks.uuid network_uuid, + networks.name network_name, + networks.network_domain network_domain, + networks.traffic_type traffic_type, + networks.guest_type guest_type, + async_job.id job_id, + async_job.uuid job_uuid, + async_job.job_status job_status, + async_job.account_id job_account_id, + domain_router.template_version template_version, + domain_router.scripts_version scripts_version, + domain_router.is_redundant_router is_redundant_router, + domain_router.redundant_state redundant_state, + domain_router.stop_pending stop_pending + from + `cloud`.`domain_router` + inner join + `cloud`.`vm_instance` ON vm_instance.id = domain_router.id + inner join + `cloud`.`account` ON vm_instance.account_id = account.id + inner join + `cloud`.`domain` ON vm_instance.domain_id = domain.id + left join + `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id + left join + `cloud`.`projects` ON projects.project_account_id = account.id + left join + `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id + left join + `cloud`.`host` ON vm_instance.host_id = host.id + left join + `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id + left join + `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id + left join + `cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id + left join + `cloud`.`volumes` ON vm_instance.id = volumes.instance_id + left join + `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id + left join + `cloud`.`nics` ON vm_instance.id = nics.instance_id + left join + `cloud`.`networks` ON nics.network_id = networks.id + left join + `cloud`.`vpc` ON networks.vpc_id = vpc.id + left join + `cloud`.`async_job` ON async_job.instance_id = vm_instance.id + and async_job.instance_type = 'DomainRouter' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`security_group_view`; -CREATE VIEW security_group_view AS -select -security_group.id id, -security_group.name name, -security_group.description description, -security_group.uuid uuid, -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, -security_group_rule.id rule_id, -security_group_rule.uuid rule_uuid, -security_group_rule.type rule_type, -security_group_rule.start_port rule_start_port, -security_group_rule.end_port rule_end_port, -security_group_rule.protocol rule_protocol, -security_group_rule.allowed_network_id rule_allowed_network_id, -security_group_rule.allowed_ip_cidr rule_allowed_ip_cidr, -security_group_rule.create_status rule_create_status, -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 security_group -left join security_group_rule on security_group.id = security_group_rule.security_group_id -inner join account on security_group.account_id=account.id -inner join domain on security_group.domain_id=domain.id -left join projects on projects.project_account_id = security_group.account_id -left join resource_tags on resource_tags.resource_id = security_group.id and resource_tags.resource_type = "SecurityGroup" -left join async_job on async_job.instance_id = security_group.id and async_job.instance_type = "SecurityGroup" and async_job.job_status = 0; +CREATE VIEW `cloud`.`security_group_view` AS + select + security_group.id id, + security_group.name name, + security_group.description description, + security_group.uuid uuid, + 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, + security_group_rule.id rule_id, + security_group_rule.uuid rule_uuid, + security_group_rule.type rule_type, + security_group_rule.start_port rule_start_port, + security_group_rule.end_port rule_end_port, + security_group_rule.protocol rule_protocol, + security_group_rule.allowed_network_id rule_allowed_network_id, + security_group_rule.allowed_ip_cidr rule_allowed_ip_cidr, + security_group_rule.create_status rule_create_status, + 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`.`security_group` + left join + `cloud`.`security_group_rule` ON security_group.id = security_group_rule.security_group_id + inner join + `cloud`.`account` ON security_group.account_id = account.id + inner join + `cloud`.`domain` ON security_group.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = security_group.account_id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = security_group.id + and resource_tags.resource_type = 'SecurityGroup' + left join + `cloud`.`async_job` ON async_job.instance_id = security_group.id + and async_job.instance_type = 'SecurityGroup' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`resource_tag_view`; -CREATE VIEW resource_tag_view AS -select -resource_tags.id, -resource_tags.uuid, -resource_tags.key, -resource_tags.value, -resource_tags.resource_id, -resource_tags.resource_uuid, -resource_tags.resource_type, -resource_tags.customer, -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 -from resource_tags -inner join account on resource_tags.account_id=account.id -inner join domain on resource_tags.domain_id=domain.id -left join projects on projects.project_account_id = resource_tags.account_id; +CREATE VIEW `cloud`.`resource_tag_view` AS + select + resource_tags.id, + resource_tags.uuid, + resource_tags.key, + resource_tags.value, + resource_tags.resource_id, + resource_tags.resource_uuid, + resource_tags.resource_type, + resource_tags.customer, + 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 + from + `cloud`.`resource_tags` + inner join + `cloud`.`account` ON resource_tags.account_id = account.id + inner join + `cloud`.`domain` ON resource_tags.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = resource_tags.account_id; DROP VIEW IF EXISTS `cloud`.`event_view`; -CREATE VIEW event_view AS -select -event.id, -event.uuid, -event.type, -event.state, -event.description, -event.created, -event.level, -event.parameters, -event.start_id, -eve.uuid start_uuid, -event.user_id, -user.username user_name, -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 -from event -inner join account on event.account_id=account.id -inner join domain on event.domain_id=domain.id -inner join user on event.user_id = user.id -left join projects on projects.project_account_id = event.account_id -left join event eve on event.start_id = eve.id; +CREATE VIEW `cloud`.`event_view` AS + select + event.id, + event.uuid, + event.type, + event.state, + event.description, + event.created, + event.level, + event.parameters, + event.start_id, + eve.uuid start_uuid, + event.user_id, + user.username user_name, + 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 + from + `cloud`.`event` + inner join + `cloud`.`account` ON event.account_id = account.id + inner join + `cloud`.`domain` ON event.domain_id = domain.id + inner join + `cloud`.`user` ON event.user_id = user.id + left join + `cloud`.`projects` ON projects.project_account_id = event.account_id + left join + `cloud`.`event` eve ON event.start_id = eve.id; DROP VIEW IF EXISTS `cloud`.`instance_group_view`; -CREATE VIEW instance_group_view AS -select -instance_group.id, -instance_group.uuid, -instance_group.name, -instance_group.removed, -instance_group.created, -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 -from instance_group -inner join account on instance_group.account_id=account.id -inner join domain on account.domain_id=domain.id -left join projects on projects.project_account_id = instance_group.account_id; +CREATE VIEW `cloud`.`instance_group_view` AS + select + instance_group.id, + instance_group.uuid, + instance_group.name, + instance_group.removed, + instance_group.created, + 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 + from + `cloud`.`instance_group` + inner join + `cloud`.`account` ON instance_group.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`projects` ON projects.project_account_id = instance_group.account_id; DROP VIEW IF EXISTS `cloud`.`user_view`; -CREATE VIEW user_view AS -select -user.id, -user.uuid, -user.username, -user.password, -user.firstname, -user.lastname, -user.email, -user.state, -user.api_key, -user.secret_key, -user.created, -user.removed, -user.timezone, -user.registration_token, -user.is_registered, -user.incorrect_login_attempts, -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, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from user -inner join account on user.account_id = account.id -inner join domain on account.domain_id=domain.id -left join async_job on async_job.instance_id = user.id and async_job.instance_type = "User" and async_job.job_status = 0; +CREATE VIEW `cloud`.`user_view` AS + select + user.id, + user.uuid, + user.username, + user.password, + user.firstname, + user.lastname, + user.email, + user.state, + user.api_key, + user.secret_key, + user.created, + user.removed, + user.timezone, + user.registration_token, + user.is_registered, + user.incorrect_login_attempts, + 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, + 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`.`user` + inner join + `cloud`.`account` ON user.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`async_job` ON async_job.instance_id = user.id + and async_job.instance_type = 'User' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`project_view`; -CREATE VIEW project_view AS -select -projects.id, -projects.uuid, -projects.name, -projects.display_text, -projects.state, -projects.removed, -projects.created, -account.account_name owner, -pacct.account_id, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -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 -from projects -inner join domain on projects.domain_id=domain.id -inner join project_account on projects.id = project_account.project_id and project_account.account_role = "Admin" -inner join account on account.id = project_account.account_id -left join resource_tags on resource_tags.resource_id = projects.id and resource_tags.resource_type = "Project" -left join project_account pacct on projects.id = pacct.project_id; +CREATE VIEW `cloud`.`project_view` AS + select + projects.id, + projects.uuid, + projects.name, + projects.display_text, + projects.state, + projects.removed, + projects.created, + account.account_name owner, + pacct.account_id, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + 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 + from + `cloud`.`projects` + inner join + `cloud`.`domain` ON projects.domain_id = domain.id + inner join + `cloud`.`project_account` ON projects.id = project_account.project_id + and project_account.account_role = 'Admin' + inner join + `cloud`.`account` ON account.id = project_account.account_id + left join + `cloud`.`resource_tags` ON resource_tags.resource_id = projects.id + and resource_tags.resource_type = 'Project' + left join + `cloud`.`project_account` pacct ON projects.id = pacct.project_id; DROP VIEW IF EXISTS `cloud`.`project_account_view`; -CREATE VIEW project_account_view AS -select -project_account.id, -account.id account_id, -account.uuid account_uuid, -account.account_name, -account.type account_type, -project_account.account_role, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from project_account -inner join account on project_account.account_id = account.id -inner join domain on account.domain_id=domain.id -inner join projects on projects.id = project_account.project_id; +CREATE VIEW `cloud`.`project_account_view` AS + select + project_account.id, + account.id account_id, + account.uuid account_uuid, + account.account_name, + account.type account_type, + project_account.account_role, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`project_account` + inner join + `cloud`.`account` ON project_account.account_id = account.id + inner join + `cloud`.`domain` ON account.domain_id = domain.id + inner join + `cloud`.`projects` ON projects.id = project_account.project_id; DROP VIEW IF EXISTS `cloud`.`project_invitation_view`; -CREATE VIEW project_invitation_view AS -select -project_invitations.id, -project_invitations.uuid, -project_invitations.email, -project_invitations.created, -project_invitations.state, -projects.id project_id, -projects.uuid project_uuid, -projects.name project_name, -account.id account_id, -account.uuid account_uuid, -account.account_name, -account.type account_type, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path -from project_invitations -left join account on project_invitations.account_id = account.id -left join domain on project_invitations.domain_id=domain.id -left join projects on projects.id = project_invitations.project_id; +CREATE VIEW `cloud`.`project_invitation_view` AS + select + project_invitations.id, + project_invitations.uuid, + project_invitations.email, + project_invitations.created, + project_invitations.state, + projects.id project_id, + projects.uuid project_uuid, + projects.name project_name, + account.id account_id, + account.uuid account_uuid, + account.account_name, + account.type account_type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`project_invitations` + left join + `cloud`.`account` ON project_invitations.account_id = account.id + left join + `cloud`.`domain` ON project_invitations.domain_id = domain.id + left join + `cloud`.`projects` ON projects.id = project_invitations.project_id; DROP VIEW IF EXISTS `cloud`.`host_view`; -CREATE VIEW host_view AS -select -host.id, -host.uuid, -host.name, -host.status, -host.disconnected, -host.type, -host.private_ip_address, -host.version, -host.hypervisor_type, -host.hypervisor_version, -host.capabilities, -host.last_ping, -host.created, -host.removed, -host.resource_state, -host.mgmt_server_id, -host.cpus, -host.speed, -host.ram, -cluster.id cluster_id, -cluster.uuid cluster_uuid, -cluster.name cluster_name, -cluster.cluster_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -host_pod_ref.id pod_id, -host_pod_ref.uuid pod_uuid, -host_pod_ref.name pod_name, -host_tags.tag, -guest_os_category.id guest_os_category_id, -guest_os_category.uuid guest_os_category_uuid, -guest_os_category.name guest_os_category_name, -mem_caps.used_capacity memory_used_capacity, -mem_caps.reserved_capacity memory_reserved_capacity, -cpu_caps.used_capacity cpu_used_capacity, -cpu_caps.reserved_capacity cpu_reserved_capacity, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from host -left join cluster on host.cluster_id = cluster.id -left join data_center on host.data_center_id = data_center.id -left join host_pod_ref on host.pod_id = host_pod_ref.id -left join host_details on host.id = host_details.id and host_details.name = "guest.os.category.id" -left join guest_os_category on guest_os_category.id = CONVERT( host_details.value, UNSIGNED ) -left join host_tags on host_tags.host_id = host.id -left join op_host_capacity mem_caps on host.id = mem_caps.host_id and mem_caps.capacity_type = 0 -left join op_host_capacity cpu_caps on host.id = cpu_caps.host_id and cpu_caps.capacity_type = 1 -left join async_job on async_job.instance_id = host.id and async_job.instance_type = "Host" and async_job.job_status = 0; +CREATE VIEW `cloud`.`host_view` AS + select + host.id, + host.uuid, + host.name, + host.status, + host.disconnected, + host.type, + host.private_ip_address, + host.version, + host.hypervisor_type, + host.hypervisor_version, + host.capabilities, + host.last_ping, + host.created, + host.removed, + host.resource_state, + host.mgmt_server_id, + host.cpus, + host.speed, + host.ram, + cluster.id cluster_id, + cluster.uuid cluster_uuid, + cluster.name cluster_name, + cluster.cluster_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + host_pod_ref.id pod_id, + host_pod_ref.uuid pod_uuid, + host_pod_ref.name pod_name, + host_tags.tag, + guest_os_category.id guest_os_category_id, + guest_os_category.uuid guest_os_category_uuid, + guest_os_category.name guest_os_category_name, + mem_caps.used_capacity memory_used_capacity, + mem_caps.reserved_capacity memory_reserved_capacity, + cpu_caps.used_capacity cpu_used_capacity, + cpu_caps.reserved_capacity cpu_reserved_capacity, + 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`.`host` + left join + `cloud`.`cluster` ON host.cluster_id = cluster.id + left join + `cloud`.`data_center` ON host.data_center_id = data_center.id + left join + `cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id + left join + `cloud`.`host_details` ON host.id = host_details.id + and host_details.name = 'guest.os.category.id' + left join + `cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED) + left join + `cloud`.`host_tags` ON host_tags.host_id = host.id + left join + `cloud`.`op_host_capacity` mem_caps ON host.id = mem_caps.host_id + and mem_caps.capacity_type = 0 + left join + `cloud`.`op_host_capacity` cpu_caps ON host.id = cpu_caps.host_id + and cpu_caps.capacity_type = 1 + left join + `cloud`.`async_job` ON async_job.instance_id = host.id + and async_job.instance_type = 'Host' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`volume_view`; -CREATE VIEW volume_view AS -select -volumes.id, -volumes.uuid, -volumes.name, -volumes.device_id, -volumes.volume_type, -volumes.size, -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, -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, -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 volumes -inner join account on volumes.account_id=account.id -inner join domain on volumes.domain_id=domain.id -left join projects on projects.project_account_id = account.id -left join data_center on volumes.data_center_id = data_center.id -left join vm_instance on volumes.instance_id = vm_instance.id -left join user_vm on user_vm.id = vm_instance.id -left join volume_host_ref on volumes.id = volume_host_ref.volume_id and volumes.data_center_id = volume_host_ref.zone_id -left join disk_offering on volumes.disk_offering_id = disk_offering.id -left join storage_pool on volumes.pool_id = storage_pool.id -left join cluster on storage_pool.cluster_id = cluster.id -left join vm_template on volumes.template_id = vm_template.id -left join resource_tags on resource_tags.resource_id = volumes.id and resource_tags.resource_type = "Volume" -left join async_job on async_job.instance_id = volumes.id and async_job.instance_type = "Volume" and async_job.job_status = 0; +CREATE VIEW `cloud`.`volume_view` AS + select + volumes.id, + volumes.uuid, + volumes.name, + volumes.device_id, + volumes.volume_type, + volumes.size, + 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, + 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, + 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`.`account_netstats_view`; -CREATE VIEW account_netstats_view AS -SELECT account_id, -sum(net_bytes_received)+ sum(current_bytes_received) as bytesReceived, -sum(net_bytes_sent)+ sum(current_bytes_sent) as bytesSent -FROM user_statistics -group by account_id; +CREATE VIEW `cloud`.`account_netstats_view` AS + SELECT + account_id, + sum(net_bytes_received) + sum(current_bytes_received) as bytesReceived, + sum(net_bytes_sent) + sum(current_bytes_sent) as bytesSent + FROM + `cloud`.`user_statistics` + group by account_id; DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`; -CREATE VIEW account_vmstats_view AS -SELECT account_id, state, count(*) as vmcount -from vm_instance -group by account_id, state; +CREATE VIEW `cloud`.`account_vmstats_view` AS + SELECT + account_id, state, count(*) as vmcount + from + `cloud`.`vm_instance` + group by account_id , state; DROP VIEW IF EXISTS `cloud`.`free_ip_view`; -CREATE VIEW free_ip_view AS -select count(user_ip_address.id) free_ip -from user_ip_address -inner join vlan on vlan.id = user_ip_address.vlan_db_id and vlan.vlan_type = "VirtualNetwork" -where state = "Free" +CREATE VIEW `cloud`.`free_ip_view` AS + select + count(user_ip_address.id) free_ip + from + `cloud`.`user_ip_address` + inner join + `cloud`.`vlan` ON vlan.id = user_ip_address.vlan_db_id + and vlan.vlan_type = 'VirtualNetwork' + where + state = 'Free'; DROP VIEW IF EXISTS `cloud`.`account_view`; -CREATE VIEW account_view AS -select -account.id, -account.uuid, -account.account_name, -account.type, -account.state, -account.removed, -account.cleanup_needed, -account.network_domain, -domain.id domain_id, -domain.uuid domain_uuid, -domain.name domain_name, -domain.path domain_path, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -account_netstats_view.bytesReceived, -account_netstats_view.bytesSent, -vmlimit.max vmLimit, -vmcount.count vmTotal, -runningvm.vmcount runningVms, -stoppedvm.vmcount stoppedVms, -iplimit.max ipLimit, -ipcount.count ipTotal, -free_ip_view.free_ip ipFree, -volumelimit.max volumeLimit, -volumecount.count volumeTotal, -snapshotlimit.max snapshotLimit, -snapshotcount.count snapshotTotal, -templatelimit.max templateLimit, -templatecount.count templateTotal, -vpclimit.max vpcLimit, -vpccount.count vpcTotal, -projectlimit.max projectLimit, -projectcount.count projectTotal, -networklimit.max networkLimit, -networkcount.count networkTotal, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from free_ip_view, account -inner join domain on account.domain_id=domain.id -left join data_center on account.default_zone_id = data_center.id -left join account_netstats_view on account.id = account_netstats_view.account_id -left join resource_limit vmlimit on account.id = vmlimit.account_id and vmlimit.type = "user_vm" -left join resource_count vmcount on account.id = vmcount.account_id and vmcount.type = "user_vm" -left join account_vmstats_view runningvm on account.id = runningvm.account_id and runningvm.state = "Running" -left join account_vmstats_view stoppedvm on account.id = stoppedvm.account_id and stoppedvm.state = "Stopped" -left join resource_limit iplimit on account.id = iplimit.account_id and iplimit.type = "public_ip" -left join resource_count ipcount on account.id = ipcount.account_id and ipcount.type = "public_ip" -left join resource_limit volumelimit on account.id = volumelimit.account_id and volumelimit.type = "volume" -left join resource_count volumecount on account.id = volumecount.account_id and volumecount.type = "volume" -left join resource_limit snapshotlimit on account.id = snapshotlimit.account_id and snapshotlimit.type = "snapshot" -left join resource_count snapshotcount on account.id = snapshotcount.account_id and snapshotcount.type = "snapshot" -left join resource_limit templatelimit on account.id = templatelimit.account_id and templatelimit.type = "template" -left join resource_count templatecount on account.id = templatecount.account_id and templatecount.type = "template" -left join resource_limit vpclimit on account.id = vpclimit.account_id and vpclimit.type = "vpc" -left join resource_count vpccount on account.id = vpccount.account_id and vpccount.type = "vpc" -left join resource_limit projectlimit on account.id = projectlimit.account_id and projectlimit.type = "project" -left join resource_count projectcount on account.id = projectcount.account_id and projectcount.type = "project" -left join resource_limit networklimit on account.id = networklimit.account_id and networklimit.type = "network" -left join resource_count networkcount on account.id = networkcount.account_id and networkcount.type = "network" -left join async_job on async_job.instance_id = account.id and async_job.instance_type = "Account" and async_job.job_status = 0; +CREATE VIEW `cloud`.`account_view` AS + select + account.id, + account.uuid, + account.account_name, + account.type, + account.state, + account.removed, + account.cleanup_needed, + account.network_domain, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + account_netstats_view.bytesReceived, + account_netstats_view.bytesSent, + vmlimit.max vmLimit, + vmcount.count vmTotal, + runningvm.vmcount runningVms, + stoppedvm.vmcount stoppedVms, + iplimit.max ipLimit, + ipcount.count ipTotal, + free_ip_view.free_ip ipFree, + volumelimit.max volumeLimit, + volumecount.count volumeTotal, + snapshotlimit.max snapshotLimit, + snapshotcount.count snapshotTotal, + templatelimit.max templateLimit, + templatecount.count templateTotal, + vpclimit.max vpcLimit, + vpccount.count vpcTotal, + projectlimit.max projectLimit, + projectcount.count projectTotal, + networklimit.max networkLimit, + networkcount.count networkTotal, + 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`.`free_ip_view`, + `cloud`.`account` + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`data_center` ON account.default_zone_id = data_center.id + left join + `cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id + left join + `cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id + and vmlimit.type = 'user_vm' + left join + `cloud`.`resource_count` vmcount ON account.id = vmcount.account_id + and vmcount.type = 'user_vm' + left join + `cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id + and runningvm.state = 'Running' + left join + `cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id + and stoppedvm.state = 'Stopped' + left join + `cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id + and iplimit.type = 'public_ip' + left join + `cloud`.`resource_count` ipcount ON account.id = ipcount.account_id + and ipcount.type = 'public_ip' + left join + `cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id + and volumelimit.type = 'volume' + left join + `cloud`.`resource_count` volumecount ON account.id = volumecount.account_id + and volumecount.type = 'volume' + left join + `cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id + and snapshotlimit.type = 'snapshot' + left join + `cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id + and snapshotcount.type = 'snapshot' + left join + `cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id + and templatelimit.type = 'template' + left join + `cloud`.`resource_count` templatecount ON account.id = templatecount.account_id + and templatecount.type = 'template' + left join + `cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id + and vpclimit.type = 'vpc' + left join + `cloud`.`resource_count` vpccount ON account.id = vpccount.account_id + and vpccount.type = 'vpc' + left join + `cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id + and projectlimit.type = 'project' + left join + `cloud`.`resource_count` projectcount ON account.id = projectcount.account_id + and projectcount.type = 'project' + left join + `cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id + and networklimit.type = 'network' + left join + `cloud`.`resource_count` networkcount ON account.id = networkcount.account_id + and networkcount.type = 'network' + left join + `cloud`.`async_job` ON async_job.instance_id = account.id + and async_job.instance_type = 'Account' + and async_job.job_status = 0; DROP VIEW IF EXISTS `cloud`.`async_job_view`; -CREATE VIEW async_job_view AS -select -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, -user.id user_id, -user.uuid user_uuid, -async_job.id, -async_job.uuid, -async_job.job_cmd, -async_job.job_status, -async_job.job_process_status, -async_job.job_result_code, -async_job.job_result, -async_job.created, -async_job.removed, -async_job.instance_type, -async_job.instance_id, -CASE -WHEN async_job.instance_type = 'Volume' THEN volumes.uuid -WHEN async_job.instance_type = 'Template' or async_job.instance_type = 'Iso' THEN vm_template.uuid -WHEN async_job.instance_type = 'VirtualMachine' or async_job.instance_type = 'ConsoleProxy' or async_job.instance_type = 'SystemVm' or async_job.instance_type = 'DomainRouter' THEN vm_instance.uuid -WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid -WHEN async_job.instance_type = 'Host' THEN host.uuid -WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid -WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid -WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid -WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid -WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid -WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid -WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid -WHEN async_job.instance_type = 'Account' THEN acct.uuid -WHEN async_job.instance_type = 'User' THEN us.uuid -WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid -WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid -WHEN async_job.instance_type = 'Counter' THEN counter.uuid -WHEN async_job.instance_type = 'Condition' THEN conditions.uuid -WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid -WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid -WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid -ELSE null -END instance_uuid -from async_job -left join account on async_job.account_id = account.id -left join domain on domain.id = account.domain_id -left join user on async_job.user_id = user.id -left join volumes on async_job.instance_id = volumes.id -left join vm_template on async_job.instance_id = vm_template.id -left join vm_instance on async_job.instance_id = vm_instance.id -left join snapshots on async_job.instance_id = snapshots.id -left join host on async_job.instance_id = host.id -left join storage_pool on async_job.instance_id = storage_pool.id -left join user_ip_address on async_job.instance_id = user_ip_address.id -left join security_group on async_job.instance_id = security_group.id -left join physical_network on async_job.instance_id = physical_network.id -left join physical_network_traffic_types on async_job.instance_id = physical_network_traffic_types.id -left join physical_network_service_providers on async_job.instance_id = physical_network_service_providers.id -left join firewall_rules on async_job.instance_id = firewall_rules.id -left join account acct on async_job.instance_id = acct.id -left join user us on async_job.instance_id = us.id -left join static_routes on async_job.instance_id = static_routes.id -left join vpc_gateways on async_job.instance_id = vpc_gateways.id -left join counter on async_job.instance_id = counter.id -left join conditions on async_job.instance_id = conditions.id -left join autoscale_policies on async_job.instance_id = autoscale_policies.id -left join autoscale_vmprofiles on async_job.instance_id = autoscale_vmprofiles.id -left join autoscale_vmgroups on async_job.instance_id = autoscale_vmgroups.id; +CREATE VIEW `cloud`.`async_job_view` AS + select + 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, + user.id user_id, + user.uuid user_uuid, + async_job.id, + async_job.uuid, + async_job.job_cmd, + async_job.job_status, + async_job.job_process_status, + async_job.job_result_code, + async_job.job_result, + async_job.created, + async_job.removed, + async_job.instance_type, + async_job.instance_id, + CASE + WHEN async_job.instance_type = 'Volume' THEN volumes.uuid + WHEN + async_job.instance_type = 'Template' + or async_job.instance_type = 'Iso' + THEN + vm_template.uuid + WHEN + async_job.instance_type = 'VirtualMachine' + or async_job.instance_type = 'ConsoleProxy' + or async_job.instance_type = 'SystemVm' + or async_job.instance_type = 'DomainRouter' + THEN + vm_instance.uuid + WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid + WHEN async_job.instance_type = 'Host' THEN host.uuid + WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid + WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid + WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid + WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid + WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid + WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid + WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid + WHEN async_job.instance_type = 'Account' THEN acct.uuid + WHEN async_job.instance_type = 'User' THEN us.uuid + WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid + WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid + WHEN async_job.instance_type = 'Counter' THEN counter.uuid + WHEN async_job.instance_type = 'Condition' THEN conditions.uuid + WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid + WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid + WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid + ELSE null + END instance_uuid + from + `cloud`.`async_job` + left join + `cloud`.`account` ON async_job.account_id = account.id + left join + `cloud`.`domain` ON domain.id = account.domain_id + left join + `cloud`.`user` ON async_job.user_id = user.id + left join + `cloud`.`volumes` ON async_job.instance_id = volumes.id + left join + `cloud`.`vm_template` ON async_job.instance_id = vm_template.id + left join + `cloud`.`vm_instance` ON async_job.instance_id = vm_instance.id + left join + `cloud`.`snapshots` ON async_job.instance_id = snapshots.id + left join + `cloud`.`host` ON async_job.instance_id = host.id + left join + `cloud`.`storage_pool` ON async_job.instance_id = storage_pool.id + left join + `cloud`.`user_ip_address` ON async_job.instance_id = user_ip_address.id + left join + `cloud`.`security_group` ON async_job.instance_id = security_group.id + left join + `cloud`.`physical_network` ON async_job.instance_id = physical_network.id + left join + `cloud`.`physical_network_traffic_types` ON async_job.instance_id = physical_network_traffic_types.id + left join + `cloud`.`physical_network_service_providers` ON async_job.instance_id = physical_network_service_providers.id + left join + `cloud`.`firewall_rules` ON async_job.instance_id = firewall_rules.id + left join + `cloud`.`account` acct ON async_job.instance_id = acct.id + left join + `cloud`.`user` us ON async_job.instance_id = us.id + left join + `cloud`.`static_routes` ON async_job.instance_id = static_routes.id + left join + `cloud`.`vpc_gateways` ON async_job.instance_id = vpc_gateways.id + left join + `cloud`.`counter` ON async_job.instance_id = counter.id + left join + `cloud`.`conditions` ON async_job.instance_id = conditions.id + left join + `cloud`.`autoscale_policies` ON async_job.instance_id = autoscale_policies.id + left join + `cloud`.`autoscale_vmprofiles` ON async_job.instance_id = autoscale_vmprofiles.id + left join + `cloud`.`autoscale_vmgroups` ON async_job.instance_id = autoscale_vmgroups.id; DROP VIEW IF EXISTS `cloud`.`storage_pool_view`; -CREATE VIEW storage_pool_view AS -select -storage_pool.id, -storage_pool.uuid, -storage_pool.name, -storage_pool.status, -storage_pool.path, -storage_pool.pool_type, -storage_pool.host_address, -storage_pool.created, -storage_pool.removed, -storage_pool.capacity_bytes, -cluster.id cluster_id, -cluster.uuid cluster_uuid, -cluster.name cluster_name, -cluster.cluster_type, -data_center.id data_center_id, -data_center.uuid data_center_uuid, -data_center.name data_center_name, -host_pod_ref.id pod_id, -host_pod_ref.uuid pod_uuid, -host_pod_ref.name pod_name, -storage_pool_details.name tag, -op_host_capacity.used_capacity disk_used_capacity, -op_host_capacity.reserved_capacity disk_reserved_capacity, -async_job.id job_id, -async_job.uuid job_uuid, -async_job.job_status job_status, -async_job.account_id job_account_id -from storage_pool -left join cluster on storage_pool.cluster_id = cluster.id -left join data_center on storage_pool.data_center_id = data_center.id -left join host_pod_ref on storage_pool.pod_id = host_pod_ref.id -left join storage_pool_details on storage_pool_details.pool_id = storage_pool.id and storage_pool_details.value = 'true' -left join op_host_capacity on storage_pool.id = op_host_capacity.host_id and op_host_capacity.capacity_type = 3 -left join async_job on async_job.instance_id = storage_pool.id and async_job.instance_type = "StoragePool" and async_job.job_status = 0; +CREATE VIEW `cloud`.`storage_pool_view` AS + select + storage_pool.id, + storage_pool.uuid, + storage_pool.name, + storage_pool.status, + storage_pool.path, + storage_pool.pool_type, + storage_pool.host_address, + storage_pool.created, + storage_pool.removed, + storage_pool.capacity_bytes, + cluster.id cluster_id, + cluster.uuid cluster_uuid, + cluster.name cluster_name, + cluster.cluster_type, + data_center.id data_center_id, + data_center.uuid data_center_uuid, + data_center.name data_center_name, + host_pod_ref.id pod_id, + host_pod_ref.uuid pod_uuid, + host_pod_ref.name pod_name, + storage_pool_details.name tag, + op_host_capacity.used_capacity disk_used_capacity, + op_host_capacity.reserved_capacity disk_reserved_capacity, + 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`.`storage_pool` + left join + `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id + left join + `cloud`.`data_center` ON storage_pool.data_center_id = data_center.id + left join + `cloud`.`host_pod_ref` ON storage_pool.pod_id = host_pod_ref.id + left join + `cloud`.`storage_pool_details` ON storage_pool_details.pool_id = storage_pool.id + and storage_pool_details.value = 'true' + left join + `cloud`.`op_host_capacity` ON storage_pool.id = op_host_capacity.host_id + and op_host_capacity.capacity_type = 3 + left join + `cloud`.`async_job` ON async_job.instance_id = storage_pool.id + and async_job.instance_type = 'StoragePool' + and async_job.job_status = 0; +DROP VIEW IF EXISTS `cloud`.`disk_offering_view`; +CREATE VIEW `cloud`.`disk_offering_view` AS + select + disk_offering.id, + disk_offering.uuid, + disk_offering.name, + disk_offering.display_text, + disk_offering.disk_size, + disk_offering.created, + disk_offering.tags, + disk_offering.customized, + disk_offering.removed, + disk_offering.use_local_storage, + disk_offering.system_use, + disk_offering.sort_key, + disk_offering.type, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`disk_offering` + left join + `cloud`.`domain` ON disk_offering.domain_id = domain.id; + +DROP VIEW IF EXISTS `cloud`.`service_offering_view`; +CREATE VIEW `cloud`.`service_offering_view` AS + select + service_offering.id, + disk_offering.uuid, + disk_offering.name, + disk_offering.display_text, + disk_offering.created, + disk_offering.tags, + disk_offering.removed, + disk_offering.use_local_storage, + disk_offering.system_use, + service_offering.cpu, + service_offering.speed, + service_offering.ram_size, + service_offering.nw_rate, + service_offering.mc_rate, + service_offering.ha_enabled, + service_offering.limit_cpu_use, + service_offering.host_tag, + service_offering.default_use, + service_offering.vm_type, + service_offering.sort_key, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`service_offering` + inner join + `cloud`.`disk_offering` ON service_offering.id = disk_offering.id + left join + `cloud`.`domain` ON disk_offering.domain_id = domain.id; + +DROP VIEW IF EXISTS `cloud`.`data_center_view`; +CREATE VIEW `cloud`.`data_center_view` AS + select + data_center.id, + data_center.uuid, + data_center.name, + data_center.is_security_group_enabled, + data_center.is_local_storage_enabled, + data_center.description, + data_center.dns1, + data_center.dns2, + data_center.internal_dns1, + data_center.internal_dns2, + data_center.guest_network_cidr, + data_center.domain, + data_center.networktype, + data_center.allocation_state, + data_center.zone_token, + data_center.dhcp_provider, + data_center.removed, + domain.id domain_id, + domain.uuid domain_uuid, + domain.name domain_name, + domain.path domain_path + from + `cloud`.`data_center` + left join + `cloud`.`domain` ON data_center.domain_id = domain.id; + INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'direct.agent.pool.size', '500', 'Default size for DirectAgentPool'); diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py index 339a2014522..eadf23ff173 100644 --- a/tools/cli/cloudmonkey/cloudmonkey.py +++ b/tools/cli/cloudmonkey/cloudmonkey.py @@ -75,7 +75,8 @@ class CloudMonkeyShell(cmd.Cmd, object): # datastructure {'verb': {cmd': ['api', [params], doc, required=[]]}} cache_verbs = precached_verbs - def __init__(self): + def __init__(self, pname): + self.program_name = pname if os.path.exists(self.config_file): config = self.read_config() else: @@ -262,8 +263,9 @@ class CloudMonkeyShell(cmd.Cmd, object): return isAsync = isAsync and (self.asyncblock == "true") - if isAsync and 'jobid' in response[response.keys()[0]]: - jobId = response[response.keys()[0]]['jobid'] + responsekey = filter(lambda x: 'response' in x, response.keys())[0] + if isAsync and 'jobid' in response[responsekey]: + jobId = response[responsekey]['jobid'] command = "queryAsyncJobResult" requests = {'jobid': jobId} timeout = int(self.timeout) @@ -282,7 +284,7 @@ class CloudMonkeyShell(cmd.Cmd, object): jobstatus = result['jobstatus'] if jobstatus == 2: jobresult = result["jobresult"] - self.print_shell("Async query failed for jobid=", + self.print_shell("\rAsync query failed for jobid", jobId, "\nError", jobresult["errorcode"], jobresult["errortext"]) return @@ -293,7 +295,7 @@ class CloudMonkeyShell(cmd.Cmd, object): timeout = timeout - pollperiod progress += 1 logger.debug("job: %s to timeout in %ds" % (jobId, timeout)) - self.print_shell("Error:", "Async query timeout for jobid=", jobId) + self.print_shell("Error:", "Async query timeout for jobid", jobId) return response @@ -306,7 +308,19 @@ class CloudMonkeyShell(cmd.Cmd, object): return None return api_mod + def pipe_runner(self, args): + if args.find(' |') > -1: + pname = self.program_name + if '.py' in pname: + pname = "python " + pname + self.do_shell("%s %s" % (pname, args)) + return True + return False + def default(self, args): + if self.pipe_runner(args): + return + lexp = shlex.shlex(args.strip()) lexp.whitespace = " " lexp.whitespace_split = True @@ -387,7 +401,8 @@ class CloudMonkeyShell(cmd.Cmd, object): self.cache_verbs[verb][subject][1]) search_string = text - autocompletions.append("filter=") + if self.tabularize == "true": + autocompletions.append("filter=") return [s for s in autocompletions if s.startswith(search_string)] def do_api(self, args): @@ -504,22 +519,21 @@ def main(): for rule in grammar: def add_grammar(rule): def grammar_closure(self, args): - if '|' in args: # FIXME: Consider parsing issues - prog_name = sys.argv[0] - if '.py' in prog_name: - prog_name = "python " + prog_name - self.do_shell("%s %s %s" % (prog_name, rule, args)) + if self.pipe_runner("%s %s" % (rule, args)): return try: args_partition = args.partition(" ") res = self.cache_verbs[rule][args_partition[0]] + cmd = res[0] + helpdoc = res[2] + args = args_partition[2] except KeyError, e: self.print_shell("Error: invalid %s api arg" % rule, e) return if ' --help' in args or ' -h' in args: - self.print_shell(res[2]) + self.print_shell(helpdoc) return - self.default(res[0] + " " + args_partition[2]) + self.default("%s %s" % (cmd, args)) return grammar_closure grammar_handler = add_grammar(rule) @@ -527,7 +541,7 @@ def main(): grammar_handler.__name__ = 'do_' + rule setattr(self, grammar_handler.__name__, grammar_handler) - shell = CloudMonkeyShell() + shell = CloudMonkeyShell(sys.argv[0]) if len(sys.argv) > 1: shell.onecmd(' '.join(sys.argv[1:])) else: diff --git a/tools/cli/cloudmonkey/common.py b/tools/cli/cloudmonkey/common.py index 3199af26c85..0865a8ee8cc 100644 --- a/tools/cli/cloudmonkey/common.py +++ b/tools/cli/cloudmonkey/common.py @@ -40,9 +40,9 @@ config_fields = {'host': 'localhost', 'port': '8080', os.path.expanduser('~/.cloudmonkey_history')} # Add verbs in grammar -grammar = ['create', 'list', 'delete', 'update', +grammar = ['create', 'list', 'delete', 'update', 'lock', 'enable', 'activate', 'disable', 'add', 'remove', - 'attach', 'detach', 'associate', 'generate', 'ldap', + 'attach', 'detach', 'associate', 'disassociate', 'generate', 'ldap', 'assign', 'authorize', 'change', 'register', 'configure', 'start', 'restart', 'reboot', 'stop', 'reconnect', 'cancel', 'destroy', 'revoke', 'mark', 'reset', diff --git a/tools/cli/setup.py b/tools/cli/setup.py index 739c044f7dd..f1efa741a02 100644 --- a/tools/cli/setup.py +++ b/tools/cli/setup.py @@ -53,7 +53,7 @@ setup( include_package_data = True, zip_safe = False, classifiers = [ - "Development Status :: 4 - Beta", + "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", diff --git a/tools/devcloud/devcloud.sql b/tools/devcloud/devcloud.sql index cebf5a3702e..009c2b5c0d5 100644 --- a/tools/devcloud/devcloud.sql +++ b/tools/devcloud/devcloud.sql @@ -37,4 +37,4 @@ INSERT INTO `cloud`.`configuration` (instance, name, value) VALUE('DEFAULT', 'se UPDATE `cloud`.`configuration` SET value='10' where name = 'storage.overprovisioning.factor'; UPDATE `cloud`.`configuration` SET value='10' where name = 'cpu.overprovisioning.factor'; UPDATE `cloud`.`configuration` SET value='10' where name = 'mem.overprovisioning.factor'; -UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="https://github.com/downloads/bhaisaab/incubator-cloudstack/ttylinux_pv.vhd",checksum="046e134e642e6d344b34648223ba4bc1",display_text="tiny Linux" where id=5; +UPDATE `cloud`.`vm_template` SET unique_name="tiny Linux",name="tiny Linux",url="http://people.apache.org/~bhaisaab/vms/ttylinux_pv.vhd",checksum="046e134e642e6d344b34648223ba4bc1",display_text="tiny Linux" where id=5; diff --git a/tools/devcloud/devcloud_internal-mgt.cfg b/tools/devcloud/devcloud_internal-mgt.cfg new file mode 100644 index 00000000000..fe3dd1b41da --- /dev/null +++ b/tools/devcloud/devcloud_internal-mgt.cfg @@ -0,0 +1,121 @@ +# 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. +# + +{ + "zones": [ + { + "name": "DevCloud0", + "physical_networks": [ + { + "broadcastdomainrange": "Zone", + "name": "test-network", + "traffictypes": [ + { + "typ": "Guest" + }, + { + "typ": "Management" + } + ], + "providers": [ + { + "broadcastdomainrange": "ZONE", + "name": "VirtualRouter" + }, + { + "broadcastdomainrange": "Pod", + "name": "SecurityGroupProvider" + } + ] + } + ], + "dns2": "4.4.4.4", + "dns1": "8.8.8.8", + "securitygroupenabled": "true", + "localstorageenabled": "true", + "networktype": "Basic", + "pods": [ + { + "endip": "192.168.56.220", + "name": "test00", + "startip": "192.168.56.200", + "guestIpRanges": [ + { + "startip": "192.168.56.100", + "endip": "192.168.56.199", + "netmask": "255.255.255.0", + "gateway": "192.168.56.1" + } + ], + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "test000", + "hypervisor": "XenServer", + "hosts": [ + { + "username": "root", + "url": "http://192.168.56.10/", + "password": "password" + } + ], + "clustertype": "CloudManaged" + } + ], + "gateway": "192.168.56.1" + } + ], + "internaldns1": "192.168.56.1", + "secondaryStorages": [ + { + "url": "nfs://192.168.56.10:/opt/storage/secondary" + } + ] + } + ], + "logger": [ + { + "name": "TestClient", + "file": "/tmp/testclient.log" + }, + { + "name": "TestCase", + "file": "/tmp/testcase.log" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "192.168.56.10", + "port": 8096 + } + ], + "dbSvr": + { + "dbSvr": "127.0.0.1", + "port": 3306, + "user": "cloud", + "passwd": "cloud", + "db": "cloud" + } + "globalConfig": [ + { + "name": "host", + "value": "192.168.56.10" + } + ] +} diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css index 58563a6711a..6519ed053e8 100644 --- a/ui/css/cloudstack3.css +++ b/ui/css/cloudstack3.css @@ -5778,6 +5778,10 @@ label.error { height: 223px; } +.multi-wizard.instance-wizard .select-network.no-add-network .select table .select-container { + height: 282px; +} + .multi-wizard.instance-wizard .select-network .select.new-network table .select-container { height: 29px; overflow: visible; @@ -5802,6 +5806,10 @@ label.error { margin: -17px 0 0; } +.multi-wizard.instance-wizard .select-network.no-add-network .select.new-network { + display: none !important; +} + .multi-wizard.instance-wizard .select-network .main-desc { width: 252px; top: 12px; @@ -5851,6 +5859,10 @@ label.error { margin: 7px 0px 7px 7px; } +.multi-wizard.instance-wizard .select-network.no-add-network .select-vpc { + visibility: hidden !important; +} + .multi-wizard.instance-wizard .select-network .select-vpc select { width: 124px; } diff --git a/ui/index.jsp b/ui/index.jsp index a9b83e6fdd5..5481da80130 100644 --- a/ui/index.jsp +++ b/ui/index.jsp @@ -220,7 +220,7 @@ under the License. -
+

@@ -959,7 +959,7 @@ under the License.
-
+
 
diff --git a/ui/scripts/configuration.js b/ui/scripts/configuration.js index dc5f8f004c3..0fbea2d7335 100644 --- a/ui/scripts/configuration.js +++ b/ui/scripts/configuration.js @@ -1293,11 +1293,11 @@ } } //hide/show service fields ***** (end) ***** - - - //show LB InlineMode dropdown only when (1)LB Service is checked (2)Service Provider is F5 - if((args.$form.find('.form-item[rel=\"service.Lb.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) - &&(args.$form.find('.form-item[rel=\"service.Lb.provider\"]').find('select').val() == 'F5BigIp') && ( args.$form.find('.form-item[rel=\"service.Firewall.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) && (args.$form.find('.form-item[rel=\"service.Firewall.provider\"]').find('select').val() == 'JuniperSRX')) { + + //show LB InlineMode dropdown only when (1)LB service is checked and LB service provider is F5BigIp (2)Firewall service is checked and Firewall service provider is JuniperSRX + if((args.$form.find('.form-item[rel=\"service.Lb.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) && (args.$form.find('.form-item[rel=\"service.Lb.provider\"]').find('select').val() == 'F5BigIp') && + (args.$form.find('.form-item[rel=\"service.Firewall.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) && (args.$form.find('.form-item[rel=\"service.Firewall.provider\"]').find('select').val() == 'JuniperSRX')) + { args.$form.find('.form-item[rel=\"service.Lb.inlineModeDropdown\"]').css('display', 'inline-block'); } else { @@ -1325,10 +1325,10 @@ args.$form.find('.form-item[rel=\"service.Lb.elasticLbCheckbox\"]').find('input[type=checkbox]').attr('checked', false); } - //show Elastic IP checkbox only when (1)StaticNat Service is checked (2)Service Provider is Netscaler (3)Guest IP Type is Shared + //show Elastic IP checkbox only when (1)StaticNat service is checked (2)StaticNat service provider is Netscaler if((args.$form.find('.form-item[rel=\"service.StaticNat.isEnabled\"]').find('input[type=checkbox]').is(':checked') == true) &&(args.$form.find('.form-item[rel=\"service.StaticNat.provider\"]').find('select').val() == 'Netscaler') - &&(args.$form.find('.form-item[rel=\"guestIpType\"]').find('select').val() == 'Shared')) { + ) { args.$form.find('.form-item[rel=\"service.StaticNat.elasticIpCheckbox\"]').css('display', 'inline-block'); } else { diff --git a/ui/scripts/instanceWizard.js b/ui/scripts/instanceWizard.js index e4b1f31d427..070f7e7b98d 100644 --- a/ui/scripts/instanceWizard.js +++ b/ui/scripts/instanceWizard.js @@ -16,7 +16,7 @@ // under the License. (function($, cloudStack) { - var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, community; + var zoneObjs, hypervisorObjs, featuredTemplateObjs, communityTemplateObjs, myTemplateObjs, featuredIsoObjs, community, networkObjs; var selectedZoneObj, selectedTemplateObj, selectedHypervisor, selectedDiskOfferingObj; var step5ContainerType = 'nothing-to-select'; //'nothing-to-select', 'select-network', 'select-security-group' @@ -40,6 +40,33 @@ !data.vpcid; }, + // Runs when advanced SG-enabled zone is run, before + // the security group step + // + // -- if it returns false, then 'Select Security Group' is skipped. + // + advSGFilter: function(args) { + var selectedNetworks; + + if ($.isArray(args.data['my-networks'])) { + selectedNetworks = $(args.data['my-networks']).map(function(index, myNetwork) { + return $.grep(networkObjs, function(networkObj) { + return networkObj.id == myNetwork; + }); + }); + } else { + selectedNetworks = $.grep(networkObjs, function(networkObj) { + return networkObj.id == args.data['my-networks']; + }); + } + + return $.grep(selectedNetworks, function(network) { + return $.grep(network.service, function(service) { + return service.name == 'SecurityGroup'; + }).length; + }).length; + }, + // Data providers for each wizard step steps: [ @@ -268,25 +295,31 @@ } if (selectedZoneObj.networktype == "Advanced") { //Advanced zone. Show network list. - var $networkStep = $(".step.network:visible .nothing-to-select"); + var $networkStep = $(".step.network:visible .nothing-to-select"); + var $networkStepContainer = $('.step.network:visible'); + if(args.initArgs.pluginForm != null && args.initArgs.pluginForm.name == "vpcTierInstanceWizard") { //from VPC Tier chart step5ContainerType = 'nothing-to-select'; $networkStep.find("#from_instance_page_1").hide(); $networkStep.find("#from_instance_page_2").hide(); $networkStep.find("#from_vpc_tier").text("tier " + args.context.networks[0].name); $networkStep.find("#from_vpc_tier").show(); - } - else { //from Instance page + } else { //from Instance page if(selectedZoneObj.securitygroupsenabled != true) { // Advanced SG-disabled zone step5ContainerType = 'select-network'; $networkStep.find("#from_instance_page_1").show(); $networkStep.find("#from_instance_page_2").show(); $networkStep.find("#from_vpc_tier").text(""); $networkStep.find("#from_vpc_tier").hide(); + $networkStepContainer.removeClass('next-use-security-groups'); + } else { // Advanced SG-enabled zone + step5ContainerType = 'select-advanced-sg'; } - else { // Advanced SG-enabled zone - step5ContainerType = 'select-security-group'; - } + + if ($networkStepContainer.hasClass('next-use-security-groups')) { + $networkStepContainer.removeClass('repeat next-use-security-groups loaded'); + step5ContainerType = 'select-security-group'; + } } } else { //Basic zone. Show securigy group list or nothing(when no SecurityGroup service in guest network) @@ -320,10 +353,11 @@ } //step5ContainerType = 'nothing-to-select'; //for testing only, comment it out before checking in - if(step5ContainerType == 'select-network') { + if(step5ContainerType == 'select-network' || step5ContainerType == 'select-advanced-sg') { var defaultNetworkArray = [], optionalNetworkArray = []; var networkData = { - zoneId: args.currentData.zoneid + zoneId: args.currentData.zoneid, + canusefordeploy: true }; // step5ContainerType of Advanced SG-enabled zone is 'select-security-group', so won't come into this block @@ -340,7 +374,7 @@ networkData.account = g_account; } - var networkObjs, vpcObjs; + var vpcObjs; //listVPCs without account/domainid/listAll parameter will return only VPCs belonging to the current login. That's what should happen in Instances page's VM Wizard. //i.e. If the current login is root-admin, do not show VPCs belonging to regular-user/domain-admin in Instances page's VM Wizard. @@ -358,6 +392,18 @@ async: false, success: function(json) { networkObjs = json.listnetworksresponse.network ? json.listnetworksresponse.network : []; + + if(networkObjs.length > 0) { + for(var i = 0; i < networkObjs.length; i++) { + var networkObj = networkObjs[i]; + var serviceObjArray = networkObj.service; + for(var k = 0; k < serviceObjArray.length; k++) { + if(serviceObjArray[k].name == "SecurityGroup") { + networkObjs[i].type = networkObjs[i].type + ' (sg)'; + } + } + } + } } }); @@ -379,12 +425,21 @@ }); //get network offerings (end) *** + $networkStepContainer.removeClass('repeat next-use-security-groups'); + + if (step5ContainerType == 'select-advanced-sg') { + $networkStepContainer.addClass('repeat next-use-security-groups'); + + // Add guest network is disabled + $networkStepContainer.find('.select-network').addClass('no-add-network'); + } else { + $networkStepContainer.find('.select-network').removeClass('no-add-network'); + } args.response.success({ type: 'select-network', - data: { - myNetworks: [], //not used any more - sharedNetworks: networkObjs, + data: { + networkObjs: networkObjs, securityGroups: [], networkOfferings: networkOfferingObjs, vpcs: vpcObjs @@ -415,9 +470,8 @@ }); args.response.success({ type: 'select-security-group', - data: { - myNetworks: [], //not used any more - sharedNetworks: [], + data: { + networkObjs: [], securityGroups: securityGroupArray, networkOfferings: [], vpcs: [] @@ -428,9 +482,8 @@ else if(step5ContainerType == 'nothing-to-select') { args.response.success({ type: 'nothing-to-select', - data: { - myNetworks: [], //not used any more - sharedNetworks: [], + data: { + networkObjs: [], securityGroups: [], networkOfferings: [], vpcs: [] @@ -545,41 +598,38 @@ if(checkedSecurityGroupIdArray.length > 0) array1.push("&securitygroupids=" + checkedSecurityGroupIdArray.join(",")); - - /* - if(selectedZoneObj.networktype == "Advanced" && selectedZoneObj.securitygroupsenabled == true) { // Advanced SG-enabled zone - var networkData = { - zoneId: selectedZoneObj.id, - type: 'Shared', - supportedServices: 'SecurityGroup' - }; - if (!(cloudStack.context.projects && cloudStack.context.projects[0])) { - networkData.domainid = g_domainid; - networkData.account = g_account; - } + + if(selectedZoneObj.networktype == "Advanced" && selectedZoneObj.securitygroupsenabled == true) { // Advanced SG-enabled zone + var array2 = []; + var myNetworks = $('.multi-wizard:visible form').data('my-networks'); //widget limitation: If using an advanced security group zone, get the guest networks like this + var defaultNetworkId = $('.multi-wizard:visible form').find('input[name=defaultNetwork]:checked').val(); + + var checkedNetworkIdArray; + if(typeof(myNetworks) == "object" && myNetworks.length != null) { //myNetworks is an array of string, e.g. ["203", "202"], + checkedNetworkIdArray = myNetworks; + } + else if(typeof(myNetworks) == "string" && myNetworks.length > 0) { //myNetworks is a string, e.g. "202" + checkedNetworkIdArray = []; + checkedNetworkIdArray.push(myNetworks); + } + else { // typeof(myNetworks) == null + checkedNetworkIdArray = []; + } - var selectedNetworkObj = null; - $.ajax({ - url: createURL('listNetworks'), - data: networkData, - async: false, - success: function(json) { - var networks = json.listnetworksresponse.network; - if(networks != null && networks.length > 0) { - selectedNetworkObj = networks[0]; //each Advanced SG-enabled zone has only one guest network that is Shared and has SecurityGroup service - } + //add default network first + if(defaultNetworkId != null && defaultNetworkId.length > 0 && defaultNetworkId != 'new-network') + array2.push(defaultNetworkId); + + //then, add other checked networks + if(checkedNetworkIdArray.length > 0) { + for(var i=0; i < checkedNetworkIdArray.length; i++) { + if(checkedNetworkIdArray[i] != defaultNetworkId) //exclude defaultNetworkId that has been added to array2 + array2.push(checkedNetworkIdArray[i]); } - }); - if(selectedNetworkObj != null) { - array1.push("&networkIds=" + selectedNetworkObj.id); } - else { - alert('unable to find any Shared network with SecurityGroup service. Therefore, unable to deploy VM in this Advanced SecurityGroup-enabled zone.'); - return; - } - } - */ - + + array1.push("&networkIds=" + array2.join(",")); + } } else if (step5ContainerType == 'nothing-to-select') { if(args.context.networks != null) { //from VPC tier diff --git a/ui/scripts/projects.js b/ui/scripts/projects.js index 31b68e7a338..b62dcb4c6a2 100644 --- a/ui/scripts/projects.js +++ b/ui/scripts/projects.js @@ -1026,7 +1026,7 @@ createForm: { desc: 'message.enter.token', fields: { - projectid: { label: 'label.project.id', validation: { required: true, docID: 'helpEnterTokenProjectID' }}, + projectid: { label: 'label.project.id', validation: { required: true}, docID: 'helpEnterTokenProjectID' }, token: { label: 'label.token', docID: 'helpEnterTokenToken', validation: { required: true }} } }, diff --git a/ui/scripts/ui-custom/instanceWizard.js b/ui/scripts/ui-custom/instanceWizard.js index d2724a524f3..67d2a69c968 100644 --- a/ui/scripts/ui-custom/instanceWizard.js +++ b/ui/scripts/ui-custom/instanceWizard.js @@ -598,6 +598,8 @@ response: { success: function(args) { var vpcs = args.data.vpcs; + var addClass = args.addClass; + var removeClass = args.removeClass; // Populate VPC drop-down $vpcSelect.html(''); @@ -634,7 +636,7 @@ // My networks $step.find('.my-networks .select-container').append( - makeSelects('my-networks', $.merge(args.data.myNetworks, args.data.sharedNetworks), { + makeSelects('my-networks', args.data.networkObjs, { name: 'name', desc: 'type', id: 'id' @@ -753,7 +755,8 @@ ) ); - $targetStep.addClass('loaded'); + if (!$targetStep.hasClass('repeat') && + !$targetStep.hasClass('always-load')) $targetStep.addClass('loaded'); } // Show launch vm button if last step @@ -806,10 +809,28 @@ //step 5 - select network if($activeStep.find('.wizard-step-conditional.select-network:visible').size() > 0) { + var data = $activeStep.data('my-networks'); + + if (!data) { + $activeStep.closest('form').data('my-networks', cloudStack.serializeForm( + $activeStep.closest('form') + )['my-networks']); + } + if($activeStep.find('input[type=checkbox]:checked').size() == 0) { //if no checkbox is checked cloudStack.dialog.notice({ message: 'message.step.4.continue' }); return false; } + + if ($activeStep.hasClass('next-use-security-groups')) { + var advSGFilter = args.advSGFilter({ + data: cloudStack.serializeForm($form) + }); + + if (!advSGFilter) { + showStep(6); + } + } } //step 6 - review (spcifiy displyname, group as well) @@ -828,7 +849,11 @@ } } - showStep($steps.filter(':visible').index() + 2); + if ($activeStep.hasClass('repeat')) { + showStep($steps.filter(':visible').index() + 1); + } else { + showStep($steps.filter(':visible').index() + 2); + } return false; } diff --git a/utils/src/com/cloud/utils/IteratorUtil.java b/utils/src/com/cloud/utils/IteratorUtil.java index d7a85f1e6d3..0a7fd72c882 100644 --- a/utils/src/com/cloud/utils/IteratorUtil.java +++ b/utils/src/com/cloud/utils/IteratorUtil.java @@ -16,8 +16,11 @@ // under the License. package com.cloud.utils; +import java.util.ArrayList; +import java.util.Collection; import java.util.Enumeration; import java.util.Iterator; +import java.util.List; public class IteratorUtil { public static Iterable enumerationAsIterable(final Enumeration e) { @@ -51,4 +54,11 @@ public class IteratorUtil { } }; } + + public static + > List asSortedList(Collection c) { + List list = new ArrayList(c); + java.util.Collections.sort(list); + return list; + } } diff --git a/utils/src/com/cloud/utils/ReflectUtil.java b/utils/src/com/cloud/utils/ReflectUtil.java index 09447059fe6..e5a890a28e2 100755 --- a/utils/src/com/cloud/utils/ReflectUtil.java +++ b/utils/src/com/cloud/utils/ReflectUtil.java @@ -19,7 +19,10 @@ package com.cloud.utils; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; import com.cloud.utils.exception.CloudRuntimeException; @@ -87,26 +90,39 @@ public class ReflectUtil { return isAsync; } - // Returns all fields across the base class for a cmd - public static Field[] getAllFieldsForClass(Class cmdClass, - Class[] searchClasses) { - Field[] fields = cmdClass.getDeclaredFields(); + // Returns all fields until a base class for a cmd class + public static List getAllFieldsForClass(Class cmdClass, + Class baseClass) { + List fields = new ArrayList(); + Collections.addAll(fields, cmdClass.getDeclaredFields()); + Class superClass = cmdClass.getSuperclass(); + while (baseClass.isAssignableFrom(superClass)) { + Field[] superClassFields = superClass.getDeclaredFields(); + if (superClassFields != null) + Collections.addAll(fields, superClassFields); + superClass = superClass.getSuperclass(); + } + return fields; + } + + // Returns all unique fields except excludeClasses for a cmd class + public static Set getAllFieldsForClass(Class cmdClass, + Class[] excludeClasses) { + Set fields = new HashSet(); + Collections.addAll(fields, cmdClass.getDeclaredFields()); Class superClass = cmdClass.getSuperclass(); while (superClass != null && superClass != Object.class) { String superName = superClass.getName(); - for (Class baseClass: searchClasses) { - if(!baseClass.isAssignableFrom(superClass)) - continue; - if (!superName.equals(baseClass.getName())) { - Field[] superClassFields = superClass.getDeclaredFields(); - if (superClassFields != null) { - Field[] tmpFields = new Field[fields.length + superClassFields.length]; - System.arraycopy(fields, 0, tmpFields, 0, fields.length); - System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length); - fields = tmpFields; - } - } + boolean isNameEqualToSuperName = false; + for (Class baseClass: excludeClasses) + if (superName.equals(baseClass.getName())) + isNameEqualToSuperName = true; + + if (!isNameEqualToSuperName) { + Field[] superClassFields = superClass.getDeclaredFields(); + if (superClassFields != null) + Collections.addAll(fields, superClassFields); } superClass = superClass.getSuperclass(); } diff --git a/utils/src/com/cloud/utils/db/GenericDao.java b/utils/src/com/cloud/utils/db/GenericDao.java index 15d04b76a1c..31a25fd7088 100755 --- a/utils/src/com/cloud/utils/db/GenericDao.java +++ b/utils/src/com/cloud/utils/db/GenericDao.java @@ -57,6 +57,9 @@ public interface GenericDao { // Finds one unique VO using uuid T findByUuid(String uuid); + + // Finds one unique VO using uuid including removed entities + T findByUuidIncludingRemoved(String uuid); /** * @return VO object ready to be used for update. It won't have any fields filled in. diff --git a/utils/src/com/cloud/utils/db/GenericDaoBase.java b/utils/src/com/cloud/utils/db/GenericDaoBase.java index 2ca1fe48f74..c083e3af834 100755 --- a/utils/src/com/cloud/utils/db/GenericDaoBase.java +++ b/utils/src/com/cloud/utils/db/GenericDaoBase.java @@ -921,6 +921,14 @@ public abstract class GenericDaoBase implements Gene return findOneBy(sc); } + @Override @DB(txn=false) + @SuppressWarnings("unchecked") + public T findByUuidIncludingRemoved(final String uuid) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("uuid", SearchCriteria.Op.EQ, uuid); + return findOneIncludingRemovedBy(sc); + } + @Override @DB(txn=false) public T findByIdIncludingRemoved(ID id) { return findById(id, true, null); diff --git a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java index 1a0969957a6..e794ea5d9c4 100755 --- a/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java +++ b/utils/src/com/cloud/utils/exception/CSExceptionErrorCode.java @@ -64,6 +64,7 @@ public class CSExceptionErrorCode { ExceptionErrorCodeMap.put("com.cloud.exception.UnsupportedServiceException", 4390); ExceptionErrorCodeMap.put("com.cloud.exception.VirtualMachineMigrationException", 4395); ExceptionErrorCodeMap.put("com.cloud.async.AsyncCommandQueued", 4540); + ExceptionErrorCodeMap.put("com.cloud.exception.RequestLimitException", 4545); // Have a special error code for ServerApiException when it is // thrown in a standalone manner when failing to detect any of the above diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java index 1444f83f425..1e5aab45408 100755 --- a/utils/src/com/cloud/utils/script/Script.java +++ b/utils/src/com/cloud/utils/script/Script.java @@ -195,51 +195,65 @@ public class Script implements Callable { } Task task = null; - if (interpreter.drain()) { + if (interpreter != null && interpreter.drain()) { task = new Task(interpreter, ir); s_executors.execute(task); } - while (true) { - try { - if (_process.waitFor() == 0) { - _logger.debug("Execution is successful."); + while (true) { + try { + if (_process.waitFor() == 0) { + _logger.debug("Execution is successful."); + if (interpreter != null) { + return interpreter.drain() ? task.getResult() : interpreter.interpret(ir); + } else { + // null return is ok apparently + return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code " + _process.exitValue(); + } + } else { + break; + } + } catch (InterruptedException e) { + if (!_isTimeOut) { + /* + * This is not timeout, we are interrupted by others, + * continue + */ + _logger.debug("We are interrupted but it's not a timeout, just continue"); + continue; + } - return interpreter.drain() ? task.getResult() : interpreter.interpret(ir); - } else { - break; - } - } catch (InterruptedException e) { - if (!_isTimeOut) { - /* This is not timeout, we are interrupted by others, continue */ - _logger.debug("We are interrupted but it's not a timeout, just continue"); - continue; - } - - TimedOutLogger log = new TimedOutLogger(_process); - Task timedoutTask = new Task(log, ir); + TimedOutLogger log = new TimedOutLogger(_process); + Task timedoutTask = new Task(log, ir); - timedoutTask.run(); - if (!_passwordCommand) { - _logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult()); - } else { - _logger.warn("Timed out: " + buildCommandLine(command)); - } + timedoutTask.run(); + if (!_passwordCommand) { + _logger.warn("Timed out: " + buildCommandLine(command) + ". Output is: " + timedoutTask.getResult()); + } else { + _logger.warn("Timed out: " + buildCommandLine(command)); + } - return ERR_TIMEOUT; - } finally { - if (future != null) { - future.cancel(false); - } - Thread.interrupted(); - } - } + return ERR_TIMEOUT; + } finally { + if (future != null) { + future.cancel(false); + } + Thread.interrupted(); + } + } - _logger.debug("Exit value is " + _process.exitValue()); + _logger.debug("Exit value is " + _process.exitValue()); BufferedReader reader = new BufferedReader(new InputStreamReader(_process.getInputStream()), 128); - String error = interpreter.processError(reader); + String error; + if (interpreter != null) { + error = interpreter.processError(reader); + } + else { + error = "Non zero exit code : " + _process.exitValue(); + } + if (_logger.isDebugEnabled()) { _logger.debug(error); }