Return-Path: X-Original-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ED19BE5FE for ; Tue, 5 Feb 2013 15:19:35 +0000 (UTC) Received: (qmail 69089 invoked by uid 500); 5 Feb 2013 15:19:35 -0000 Delivered-To: apmail-incubator-cloudstack-dev-archive@incubator.apache.org Received: (qmail 69041 invoked by uid 500); 5 Feb 2013 15:19:35 -0000 Mailing-List: contact cloudstack-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-dev@incubator.apache.org Received: (qmail 69031 invoked by uid 99); 5 Feb 2013 15:19:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2013 15:19:35 +0000 X-ASF-Spam-Status: No, hits=-1.6 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_NEUTRAL,URIBL_DBL_REDIR X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [74.125.149.19] (HELO na3sys009aog138.obsmtp.com) (74.125.149.19) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Feb 2013 15:19:29 +0000 Received: from mail-we0-f200.google.com ([74.125.82.200]) (using TLSv1) by na3sys009aob138.postini.com ([74.125.148.12]) with SMTP ID DSNKUREi21IS9XT2gYo1Cf9UMqIOV769XZyL@postini.com; Tue, 05 Feb 2013 07:19:08 PST Received: by mail-we0-f200.google.com with SMTP id d7so295127wer.3 for ; Tue, 05 Feb 2013 07:18:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-received:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=lEuo56B+zQmm5/eO2hdlO6Xo7X9wRNy+XXH0bWKphBE=; b=e1pH+RFZPkKLAxbyN5f9I3xw4OfVNYGgdtgwW6K6ASfMAPzpM4O+msT3O5G2+X5UXX L0BX6knjnUD08F08niLNY9cgY39lql48Lf7Mz2w5pLVsbOjvY9gFn1oFVGAoraqZBN9R taZQB6UV+157/QbZN7YJCnsHqF+zQMlo8ApImQ83916YIXgCRv37evxhrAcoQzq0Qvfe A4/WpOlIzOn1qccgX+GTA1azPLklAI8pxkY7Em8qiOrqGCXzfpIfay5JeaVR8JTkftuE 3+AXC5gA4+sE2q4lCZVnul6IaVHYEwkAtHlw+DYrEF9UxpjkJqypiVYmn1379R56irlU KUzw== X-Received: by 10.194.23.37 with SMTP id j5mr43106118wjf.28.1360077521974; Tue, 05 Feb 2013 07:18:41 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.194.23.37 with SMTP id j5mr43106091wjf.28.1360077521789; Tue, 05 Feb 2013 07:18:41 -0800 (PST) Received: by 10.194.221.228 with HTTP; Tue, 5 Feb 2013 07:18:41 -0800 (PST) In-Reply-To: <20130205111840.F2E2982A35C@tyr.zones.apache.org> References: <20130205111840.F2E2982A35C@tyr.zones.apache.org> Date: Tue, 5 Feb 2013 10:18:41 -0500 Message-ID: Subject: Fwd: [2/2] git commit: refs/heads/4.1 - CLOUDSTACK-786, CLOUDSTACK-1014: Moved usage APIs to cloud-api. Removed ManagementServerExt. Usage API related implementation is added to UsageServiceImpl From: Chip Childers To: Kishan Kavala , "cloudstack-dev@incubator.apache.org" Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQnpCeoM1LVNrrituDqSEJglqwXEHyCaVisPZh7sWlVfZooV2nK1SPnvxEhQOIvfOojchqOKwneh/msT7kor311a/8JBPv+EsYWKymziJQsbPH9NoWV63VDU3vdR2d9FZ/WdFQ1tF5zZ0jlolGp0n7hmtWxufLvPEfXsUoODH2bokEU0ZfTlJuRQ6xWBZWwzCE+zv5Vs X-Virus-Checked: Checked by ClamAV on apache.org Hey Kishan, Was this refactoring needed as part of 4.1? ---------- Forwarded message ---------- From: Date: Tue, Feb 5, 2013 at 6:18 AM Subject: [2/2] git commit: refs/heads/4.1 - CLOUDSTACK-786, CLOUDSTACK-1014: Moved usage APIs to cloud-api. Removed ManagementServerExt. Usage API related implementation is added to UsageServiceImpl To: cloudstack-commits@incubator.apache.org Updated Branches: refs/heads/4.1 2fd8b15d6 -> 7970384f6 CLOUDSTACK-786, CLOUDSTACK-1014: Moved usage APIs to cloud-api. Removed ManagementServerExt. Usage API related implementation is added to UsageServiceImpl Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7970384f Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7970384f Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7970384f Branch: refs/heads/4.1 Commit: 7970384f6e429b5c97f6d6e80f59cbab6ce90ede Parents: 2fd8b15 Author: Kishan Kavala Authored: Tue Feb 5 16:43:18 2013 +0530 Committer: Kishan Kavala Committed: Tue Feb 5 16:43:40 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/dao/EntityManager.java | 10 + api/src/com/cloud/network/NetworkUsageService.java | 37 ++ api/src/org/apache/cloudstack/api/BaseCmd.java | 4 + .../apache/cloudstack/api/ResponseGenerator.java | 7 + .../command/admin/usage/AddTrafficMonitorCmd.java | 107 +++++ .../admin/usage/DeleteTrafficMonitorCmd.java | 84 ++++ .../admin/usage/GenerateUsageRecordsCmd.java | 89 ++++ .../command/admin/usage/GetUsageRecordsCmd.java | 126 +++++ .../admin/usage/ListTrafficMonitorsCmd.java | 84 ++++ .../api/command/admin/usage/ListUsageTypesCmd.java | 51 ++ api/src/org/apache/cloudstack/usage/Usage.java | 69 +++ .../org/apache/cloudstack/usage/UsageService.java | 64 +++ .../org/apache/cloudstack/usage/UsageTypes.java | 58 +++ client/tomcatconf/componentContext.xml.in | 2 +- .../server/ManagementServerSimulatorImpl.java | 2 +- .../dns-notifier/resources/components-example.xml | 2 +- server/src/com/cloud/api/ApiDBUtils.java | 14 +- server/src/com/cloud/api/ApiResponseHelper.java | 253 ++++++++++ .../cloud/api/commands/AddTrafficMonitorCmd.java | 109 ----- .../api/commands/DeleteTrafficMonitorCmd.java | 86 ---- .../api/commands/GenerateUsageRecordsCmd.java | 91 ---- .../com/cloud/api/commands/GetUsageRecordsCmd.java | 370 --------------- .../cloud/api/commands/ListTrafficMonitorsCmd.java | 86 ---- .../com/cloud/api/commands/ListUsageTypesCmd.java | 53 -- server/src/com/cloud/dao/EntityManagerImpl.java | 7 +- .../src/com/cloud/network/NetworkUsageManager.java | 14 - .../com/cloud/network/NetworkUsageManagerImpl.java | 20 +- .../src/com/cloud/server/ManagementServerExt.java | 63 --- .../com/cloud/server/ManagementServerExtImpl.java | 254 ---------- server/src/com/cloud/usage/UsageServiceImpl.java | 261 ++++++++++ server/src/com/cloud/usage/UsageTypes.java | 58 --- server/src/com/cloud/usage/UsageVO.java | 23 +- usage/src/com/cloud/usage/UsageManagerImpl.java | 1 + .../cloud/usage/parser/IPAddressUsageParser.java | 2 +- .../usage/parser/LoadBalancerUsageParser.java | 2 +- .../usage/parser/NetworkOfferingUsageParser.java | 2 +- .../com/cloud/usage/parser/NetworkUsageParser.java | 2 +- .../usage/parser/PortForwardingUsageParser.java | 2 +- .../usage/parser/SecurityGroupUsageParser.java | 2 +- .../com/cloud/usage/parser/StorageUsageParser.java | 2 +- .../cloud/usage/parser/VMInstanceUsageParser.java | 2 +- .../com/cloud/usage/parser/VPNUserUsageParser.java | 2 +- .../com/cloud/usage/parser/VolumeUsageParser.java | 2 +- 43 files changed, 1358 insertions(+), 1221 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/com/cloud/dao/EntityManager.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/dao/EntityManager.java b/api/src/com/cloud/dao/EntityManager.java index b8fdaa7..8e6a438 100644 --- a/api/src/com/cloud/dao/EntityManager.java +++ b/api/src/com/cloud/dao/EntityManager.java @@ -39,6 +39,16 @@ public interface EntityManager { public T findById(Class entityType, K id); /** + * Finds an entity by its id including removed. + * @param class of the entity you're trying to find. + * @param class of the id that the entity uses. + * @param entityType Type of the entity. + * @param id id value + * @return T if found; null if not. + */ + public T findByIdIncludingRemoved(Class entityType, K id); + + /** * Finds a unique entity by uuid string * @param entity class * @param entityType type of entity you're looking for. http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/com/cloud/network/NetworkUsageService.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/network/NetworkUsageService.java b/api/src/com/cloud/network/NetworkUsageService.java new file mode 100644 index 0000000..1cfea24 --- /dev/null +++ b/api/src/com/cloud/network/NetworkUsageService.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 com.cloud.network; + +import java.util.List; + +import com.cloud.host.Host; + +import org.apache.cloudstack.api.command.admin.usage.AddTrafficMonitorCmd; +import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficMonitorCmd; +import org.apache.cloudstack.api.command.admin.usage.ListTrafficMonitorsCmd; +import org.apache.cloudstack.api.response.TrafficMonitorResponse; +import com.cloud.utils.component.Manager; + +public interface NetworkUsageService extends Manager { + + Host addTrafficMonitor(AddTrafficMonitorCmd cmd); + + boolean deleteTrafficMonitor(DeleteTrafficMonitorCmd cmd); + + List listTrafficMonitors(ListTrafficMonitorsCmd cmd); + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/BaseCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java index d8e2bff..a9ac489 100644 --- a/api/src/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseCmd.java @@ -29,6 +29,7 @@ import javax.inject.Inject; import org.apache.cloudstack.query.QueryService; import org.apache.cloudstack.region.RegionService; +import org.apache.cloudstack.usage.UsageService; import org.apache.log4j.Logger; import com.cloud.configuration.ConfigurationService; @@ -43,6 +44,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.NetworkService; +import com.cloud.network.NetworkUsageService; import com.cloud.network.StorageNetworkService; import com.cloud.network.VpcVirtualNetworkApplianceService; import com.cloud.network.as.AutoScaleService; @@ -124,6 +126,8 @@ public abstract class BaseCmd { @Inject public Site2SiteVpnService _s2sVpnService; @Inject public QueryService _queryService; + @Inject public UsageService _usageService; + @Inject public NetworkUsageService _networkUsageService; public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/ResponseGenerator.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index b95f182..0dc85de 100644 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@ -83,7 +83,9 @@ import org.apache.cloudstack.api.response.SystemVmInstanceResponse; import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.api.response.TemplatePermissionsResponse; import org.apache.cloudstack.api.response.TemplateResponse; +import org.apache.cloudstack.api.response.TrafficMonitorResponse; import org.apache.cloudstack.api.response.TrafficTypeResponse; +import org.apache.cloudstack.api.response.UsageRecordResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VirtualRouterProviderResponse; @@ -94,6 +96,7 @@ import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.api.response.VpnUsersResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.region.Region; +import org.apache.cloudstack.usage.Usage; import com.cloud.async.AsyncJob; import com.cloud.capacity.Capacity; @@ -375,4 +378,8 @@ public interface ResponseGenerator { GuestOSResponse createGuestOSResponse(GuestOS os); SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule sched); + + UsageRecordResponse createUsageResponse(Usage usageRecord); + + TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor); } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java new file mode 100644 index 0000000..48424fe --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java @@ -0,0 +1,107 @@ +// 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.usage; + +import javax.inject.Inject; + +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.TrafficMonitorResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.log4j.Logger; + +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.host.Host; +import com.cloud.user.Account; +import com.cloud.utils.exception.CloudRuntimeException; + +@APICommand(name = "addTrafficMonitor", description="Adds Traffic Monitor Host for Direct Network Usage", responseObject = TrafficMonitorResponse.class) +public class AddTrafficMonitorCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(AddTrafficMonitorCmd.class.getName()); + private static final String s_name = "addtrafficmonitorresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, + required = true, description="Zone in which to add the external firewall appliance.") + private Long zoneId; + + @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the traffic monitor Host") + private String url; + + @Parameter(name=ApiConstants.INCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will be metered") + private String inclZones; + + @Parameter(name=ApiConstants.EXCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will not be metered") + private String exclZones; + + /////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getInclZones() { + return inclZones; + } + + public String getExclZones() { + return exclZones; + } + + public Long getZoneId() { + return zoneId; + } + + public String getUrl() { + return url; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + try { + Host trafficMonitor = _networkUsageService.addTrafficMonitor(this); + TrafficMonitorResponse response = _responseGenerator.createTrafficMonitorResponse(trafficMonitor); + response.setObjectName("trafficmonitor"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } catch (InvalidParameterValueException ipve) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); + } catch (CloudRuntimeException cre) { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); + } + } +} + http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java new file mode 100644 index 0000000..e3bb299 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java @@ -0,0 +1,84 @@ +// 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.usage; + +import javax.inject.Inject; + +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.HostResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.log4j.Logger; + +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; + +@APICommand(name = "deleteTrafficMonitor", description="Deletes an traffic monitor host.", responseObject = SuccessResponse.class) +public class DeleteTrafficMonitorCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName()); + private static final String s_name = "deletetrafficmonitorresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class, + required = true, description="Id of the Traffic Monitor Host.") + private Long id; + + /////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + try { + boolean result = _networkUsageService.deleteTrafficMonitor(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete traffic monitor."); + } + } catch (InvalidParameterValueException e) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to delete traffic monitor."); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java new file mode 100644 index 0000000..13710f9 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java @@ -0,0 +1,89 @@ +// 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.usage; + +import java.util.Date; + +import org.apache.cloudstack.api.*; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.response.SuccessResponse; +import com.cloud.user.Account; + +@APICommand(name = "generateUsageRecords", description="Generates usage records. This will generate records only if there any records to be generated, i.e if the scheduled usage job was not run or failed", responseObject=SuccessResponse.class) +public class GenerateUsageRecordsCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(GenerateUsageRecordsCmd.class.getName()); + + private static final String s_name = "generateusagerecordsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class, + description="List events for the specified domain.") + private Long domainId; + + @Parameter(name=ApiConstants.END_DATE, type=CommandType.DATE, required=true, description="End date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") + private Date endDate; + + @Parameter(name=ApiConstants.START_DATE, type=CommandType.DATE, required=true, description="Start date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.") + private Date startDate; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getDomainId() { + return domainId; + } + + public Date getEndDate() { + return endDate; + } + + public Date getStartDate() { + return startDate; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + boolean result = _usageService.generateUsageRecords(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate usage records"); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/command/admin/usage/GetUsageRecordsCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/GetUsageRecordsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/GetUsageRecordsCmd.java new file mode 100644 index 0000000..f4960dd --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/GetUsageRecordsCmd.java @@ -0,0 +1,126 @@ +// 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.usage; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +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.AccountResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.UsageRecordResponse; +import org.apache.cloudstack.usage.Usage; +import org.apache.log4j.Logger; + +@APICommand(name = "listUsageRecords", description="Lists usage records for accounts", responseObject=UsageRecordResponse.class) +public class GetUsageRecordsCmd extends BaseListCmd { + public static final Logger s_logger = Logger.getLogger(GetUsageRecordsCmd.class.getName()); + + private static final String s_name = "listusagerecordsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="List usage records for the specified user.") + private String accountName; + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class, + description="List usage records for the specified domain.") + private Long domainId; + + @Parameter(name=ApiConstants.END_DATE, type=CommandType.DATE, required=true, description="End date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") + private Date endDate; + + @Parameter(name=ApiConstants.START_DATE, type=CommandType.DATE, required=true, description="Start date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.") + private Date startDate; + + @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.UUID, entityType = AccountResponse.class, + description="List usage records for the specified account") + private Long accountId; + + @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class, + description="List usage records for specified project") + private Long projectId; + + @Parameter(name=ApiConstants.TYPE, type=CommandType.LONG, description="List usage records for the specified usage type") + private Long usageType; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAccountName() { + return accountName; + } + + public Long getDomainId() { + return domainId; + } + + public Date getEndDate() { + return endDate; + } + + public Date getStartDate() { + return startDate; + } + + public Long getAccountId() { + return accountId; + } + + public Long getUsageType() { + return usageType; + } + + public Long getProjectId() { + return projectId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void execute(){ + List usageRecords = _usageService.getUsageRecords(this); + ListResponse response = new ListResponse(); + List usageResponses = new ArrayList(); + for(Usage usageRecord: usageRecords){ + UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord); + usageResponse.setObjectName("usagerecord"); + usageResponses.add(usageResponse); + } + + response.setResponses(usageResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java new file mode 100644 index 0000000..e8e3b22 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java @@ -0,0 +1,84 @@ +// 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.usage; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +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.command.user.offering.ListServiceOfferingsCmd; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.TrafficMonitorResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.log4j.Logger; + +import com.cloud.host.Host; + + +@APICommand(name = "listTrafficMonitors", description="List traffic monitor Hosts.", responseObject = TrafficMonitorResponse.class) +public class ListTrafficMonitorsCmd extends BaseListCmd { + public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName()); + private static final String s_name = "listtrafficmonitorsresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, + required = true, description="zone Id") + private long zoneId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public long getZoneId() { + return zoneId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void execute(){ + List trafficMonitors = _networkUsageService.listTrafficMonitors(this); + + ListResponse listResponse = new ListResponse(); + List responses = new ArrayList(); + for (Host trafficMonitor : trafficMonitors) { + TrafficMonitorResponse response = _responseGenerator.createTrafficMonitorResponse(trafficMonitor); + response.setObjectName("trafficmonitor"); + response.setResponseName(getCommandName()); + responses.add(response); + } + + listResponse.setResponses(responses); + listResponse.setResponseName(getCommandName()); + this.setResponseObject(listResponse); + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java b/api/src/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java new file mode 100644 index 0000000..bc02911 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.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.api.command.admin.usage; + +import java.util.List; + +import org.apache.cloudstack.api.APICommand; +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.UsageTypeResponse; +import com.cloud.user.Account; + +@APICommand(name = "listUsageTypes", description = "List Usage Types", responseObject = UsageTypeResponse.class) +public class ListUsageTypesCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(ListUsageTypesCmd.class.getName()); + private static final String s_name = "listusagetypesresponse"; + + @Override + public String getCommandName() { + return s_name; + } + + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute() { + List result = _usageService.listUsageTypes(); + ListResponse response = new ListResponse(); + response.setResponses(result); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/usage/Usage.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/usage/Usage.java b/api/src/org/apache/cloudstack/usage/Usage.java new file mode 100644 index 0000000..c74d3b7 --- /dev/null +++ b/api/src/org/apache/cloudstack/usage/Usage.java @@ -0,0 +1,69 @@ +// 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.usage; + +import org.apache.cloudstack.api.InternalIdentity; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +public interface Usage { + + public long getId(); + + public Long getZoneId(); + + public Long getAccountId(); + + public Long getDomainId(); + + public String getDescription(); + + public String getUsageDisplay(); + + public int getUsageType(); + + public Double getRawUsage(); + + public Long getVmInstanceId(); + + public String getVmName(); + + public Long getOfferingId(); + + public Long getTemplateId(); + + public Long getUsageId(); + + public String getType(); + + public Long getNetworkId(); + + public Long getSize(); + + public Date getStartDate(); + + public Date getEndDate(); +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/usage/UsageService.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/usage/UsageService.java b/api/src/org/apache/cloudstack/usage/UsageService.java new file mode 100755 index 0000000..3838225 --- /dev/null +++ b/api/src/org/apache/cloudstack/usage/UsageService.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.usage; + +import java.util.List; +import java.util.TimeZone; + +import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd; +import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd; +import org.apache.cloudstack.api.response.UsageTypeResponse; + +public interface UsageService { + /** + * Generate Billing Records from the last time it was generated to the + * time specified. + * + * @param cmd the command wrapping the generate parameters + * - userId unique id of the user, pass in -1 to generate billing records + * for all users + * - startDate + * - endDate inclusive. If date specified is greater than the current time, the + * system will use the current time. + */ + boolean generateUsageRecords(GenerateUsageRecordsCmd cmd); + + /** + * Retrieves all Usage Records generated between the start and end date specified + * + * @param userId unique id of the user, pass in -1 to retrieve billing records + * for all users + * @param startDate inclusive. + * @param endDate inclusive. If date specified is greater than the current time, the + * system will use the current time. + * @param page The page of usage records to see (500 results are returned at a time, if + * more than 500 records exist then additional results can be retrieved by + * the appropriate page number) + * @return a list of usage records + */ + List getUsageRecords(GetUsageRecordsCmd cmd); + + /** + * Retrieves the timezone used for usage aggregation. One day is represented as midnight to 11:59:59pm + * in the given time zone + * @return the timezone specified by the config value usage.aggregation.timezone, or GMT if null + */ + TimeZone getUsageTimezone(); + + List listUsageTypes(); + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/api/src/org/apache/cloudstack/usage/UsageTypes.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/usage/UsageTypes.java b/api/src/org/apache/cloudstack/usage/UsageTypes.java new file mode 100644 index 0000000..2baa1d2 --- /dev/null +++ b/api/src/org/apache/cloudstack/usage/UsageTypes.java @@ -0,0 +1,58 @@ +// 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.usage; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.api.response.UsageTypeResponse; + +public class UsageTypes { + public static final int RUNNING_VM = 1; + public static final int ALLOCATED_VM = 2; // used for tracking how long storage has been allocated for a VM + public static final int IP_ADDRESS = 3; + public static final int NETWORK_BYTES_SENT = 4; + public static final int NETWORK_BYTES_RECEIVED = 5; + public static final int VOLUME = 6; + public static final int TEMPLATE = 7; + public static final int ISO = 8; + public static final int SNAPSHOT = 9; + public static final int SECURITY_GROUP = 10; + public static final int LOAD_BALANCER_POLICY = 11; + public static final int PORT_FORWARDING_RULE = 12; + public static final int NETWORK_OFFERING = 13; + public static final int VPN_USERS = 14; + + public static List listUsageTypes(){ + List responseList = new ArrayList(); + responseList.add(new UsageTypeResponse(RUNNING_VM, "Running Vm Usage")); + responseList.add(new UsageTypeResponse(ALLOCATED_VM, "Allocated Vm Usage")); + responseList.add(new UsageTypeResponse(IP_ADDRESS, "IP Address Usage")); + responseList.add(new UsageTypeResponse(NETWORK_BYTES_SENT, "Network Usage (Bytes Sent)")); + responseList.add(new UsageTypeResponse(NETWORK_BYTES_RECEIVED, "Network Usage (Bytes Received)")); + responseList.add(new UsageTypeResponse(VOLUME, "Volume Usage")); + responseList.add(new UsageTypeResponse(TEMPLATE, "Template Usage")); + responseList.add(new UsageTypeResponse(ISO, "ISO Usage")); + responseList.add(new UsageTypeResponse(SNAPSHOT, "Snapshot Usage")); + responseList.add(new UsageTypeResponse(SECURITY_GROUP, "Security Group Usage")); + responseList.add(new UsageTypeResponse(LOAD_BALANCER_POLICY, "Load Balancer Usage")); + responseList.add(new UsageTypeResponse(PORT_FORWARDING_RULE, "Port Forwarding Usage")); + responseList.add(new UsageTypeResponse(NETWORK_OFFERING, "Network Offering Usage")); + responseList.add(new UsageTypeResponse(VPN_USERS, "VPN users usage")); + return responseList; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/client/tomcatconf/componentContext.xml.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in index e3bf982..065188c 100644 --- a/client/tomcatconf/componentContext.xml.in +++ b/client/tomcatconf/componentContext.xml.in @@ -36,7 +36,7 @@ --> - + http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/plugins/hypervisors/simulator/src/com/cloud/server/ManagementServerSimulatorImpl.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/simulator/src/com/cloud/server/ManagementServerSimulatorImpl.java b/plugins/hypervisors/simulator/src/com/cloud/server/ManagementServerSimulatorImpl.java index db4b619..728271c 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/server/ManagementServerSimulatorImpl.java +++ b/plugins/hypervisors/simulator/src/com/cloud/server/ManagementServerSimulatorImpl.java @@ -21,7 +21,7 @@ import java.util.List; import com.cloud.api.commands.ConfigureSimulator; -public class ManagementServerSimulatorImpl extends ManagementServerExtImpl { +public class ManagementServerSimulatorImpl extends ManagementServerImpl { @Override public List> getCommands() { List> cmdList = super.getCommands(); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/plugins/network-elements/dns-notifier/resources/components-example.xml ---------------------------------------------------------------------- diff --git a/plugins/network-elements/dns-notifier/resources/components-example.xml b/plugins/network-elements/dns-notifier/resources/components-example.xml index 412da0e..36441bd 100755 --- a/plugins/network-elements/dns-notifier/resources/components-example.xml +++ b/plugins/network-elements/dns-notifier/resources/components-example.xml @@ -29,7 +29,7 @@ under the License. - + true http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/server/src/com/cloud/api/ApiDBUtils.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 8e950ab..83132c6 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -83,8 +83,6 @@ 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.api.query.dao.*; -import com.cloud.api.query.vo.*; import com.cloud.async.AsyncJob; import com.cloud.async.AsyncJobManager; import com.cloud.async.AsyncJobVO; @@ -108,6 +106,7 @@ import com.cloud.host.Host; import com.cloud.host.HostStats; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; +import com.cloud.host.dao.HostDetailsDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IpAddress; import com.cloud.network.Network; @@ -156,10 +155,6 @@ import com.cloud.network.dao.Site2SiteCustomerGatewayDao; import com.cloud.network.dao.Site2SiteCustomerGatewayVO; import com.cloud.network.dao.Site2SiteVpnGatewayDao; import com.cloud.network.dao.Site2SiteVpnGatewayVO; -import com.cloud.network.*; -import com.cloud.network.as.*; -import com.cloud.network.as.dao.*; -import com.cloud.network.dao.*; import com.cloud.network.router.VirtualRouter; import com.cloud.network.rules.FirewallRuleVO; import com.cloud.network.security.SecurityGroup; @@ -313,6 +308,7 @@ public class ApiDBUtils { static VpcOfferingDao _vpcOfferingDao; static SnapshotPolicyDao _snapshotPolicyDao; static AsyncJobDao _asyncJobDao; + static HostDetailsDao _hostDetailsDao; @Inject private ManagementServer ms; @Inject public AsyncJobManager asyncMgr; @@ -410,6 +406,7 @@ public class ApiDBUtils { @Inject private VpcOfferingDao vpcOfferingDao; @Inject private SnapshotPolicyDao snapshotPolicyDao; @Inject private AsyncJobDao asyncJobDao; + @Inject private HostDetailsDao hostDetailsDao; @PostConstruct void init() { @@ -507,6 +504,7 @@ public class ApiDBUtils { _vpcOfferingDao = vpcOfferingDao; _snapshotPolicyDao = snapshotPolicyDao; _asyncJobDao = asyncJobDao; + _hostDetailsDao = hostDetailsDao; // Note: stats collector should already have been initialized by this time, otherwise a null instance is returned _statsCollector = StatsCollector.getInstance(); @@ -1493,4 +1491,8 @@ public class ApiDBUtils { public static DataCenterJoinVO newDataCenterView(DataCenter dc){ return _dcJoinDao.newDataCenterView(dc); } + + public static Map findHostDetailsById(long hostId){ + return _hostDetailsDao.findDetails(hostId); + } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/server/src/com/cloud/api/ApiResponseHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 411de94..8c97615 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -81,7 +81,9 @@ import org.apache.cloudstack.api.response.SystemVmInstanceResponse; import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.api.response.TemplatePermissionsResponse; import org.apache.cloudstack.api.response.TemplateResponse; +import org.apache.cloudstack.api.response.TrafficMonitorResponse; import org.apache.cloudstack.api.response.TrafficTypeResponse; +import org.apache.cloudstack.api.response.UsageRecordResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VirtualRouterProviderResponse; @@ -103,6 +105,7 @@ import com.cloud.configuration.Configuration; import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.ResourceCount; import com.cloud.configuration.ResourceLimit; +import com.cloud.dao.EntityManager; import com.cloud.dc.*; import com.cloud.dc.Vlan.VlanType; import com.cloud.domain.Domain; @@ -139,6 +142,7 @@ import com.cloud.network.dao.PhysicalNetworkVO; import com.cloud.network.router.VirtualRouter; import com.cloud.network.rules.*; import com.cloud.network.security.SecurityGroup; +import com.cloud.network.security.SecurityGroupVO; import com.cloud.network.security.SecurityRule; import com.cloud.network.security.SecurityRule.SecurityRuleType; import com.cloud.network.vpc.PrivateGateway; @@ -148,6 +152,7 @@ import com.cloud.network.vpc.VpcOffering; import com.cloud.offering.DiskOffering; import com.cloud.offering.NetworkOffering; import com.cloud.offering.ServiceOffering; +import com.cloud.offerings.NetworkOfferingVO; import com.cloud.org.Cluster; import com.cloud.projects.Project; import com.cloud.projects.ProjectAccount; @@ -155,6 +160,7 @@ import com.cloud.projects.ProjectInvitation; import com.cloud.server.Criteria; import com.cloud.server.ResourceTag; import com.cloud.server.ResourceTag.TaggedResourceType; +import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.*; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; @@ -174,6 +180,7 @@ import com.cloud.utils.net.NetUtils; import com.cloud.vm.ConsoleProxyVO; import com.cloud.vm.InstanceGroup; import com.cloud.vm.NicProfile; +import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; import org.apache.cloudstack.acl.ControlledEntity; @@ -185,11 +192,16 @@ import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd; import org.apache.cloudstack.api.response.*; import org.apache.cloudstack.region.Region; +import org.apache.cloudstack.usage.Usage; +import org.apache.cloudstack.usage.UsageService; +import org.apache.cloudstack.usage.UsageTypes; import org.apache.log4j.Logger; import java.text.DecimalFormat; import java.util.*; +import javax.inject.Inject; + import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -198,6 +210,8 @@ public class ApiResponseHelper implements ResponseGenerator { public final Logger s_logger = Logger.getLogger(ApiResponseHelper.class); private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##"); + @Inject private EntityManager _entityMgr = null; + @Inject private UsageService _usageSvc = null; @Override public UserResponse createUserResponse(User user) { @@ -3118,4 +3132,243 @@ public class ApiResponseHelper implements ResponseGenerator { return response; } + + + @Override + public UsageRecordResponse createUsageResponse(Usage usageRecord) { + UsageRecordResponse usageRecResponse = new UsageRecordResponse(); + + Account account = ApiDBUtils.findAccountByIdIncludingRemoved(usageRecord.getAccountId()); + if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) { + //find the project + Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId()); + usageRecResponse.setProjectId(project.getUuid()); + usageRecResponse.setProjectName(project.getName()); + } else { + usageRecResponse.setAccountId(account.getUuid()); + usageRecResponse.setAccountName(account.getAccountName()); + } + + Domain domain = ApiDBUtils.findDomainById(usageRecord.getDomainId()); + if (domain != null) { + usageRecResponse.setDomainId(domain.getUuid()); + } + + if (usageRecord.getZoneId() != null) { + DataCenter zone = ApiDBUtils.findZoneById(usageRecord.getZoneId()); + if (zone != null) { + usageRecResponse.setZoneId(zone.getUuid()); + } + } + usageRecResponse.setDescription(usageRecord.getDescription()); + usageRecResponse.setUsage(usageRecord.getUsageDisplay()); + usageRecResponse.setUsageType(usageRecord.getUsageType()); + if (usageRecord.getVmInstanceId() != null) { + VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId()); + usageRecResponse.setVirtualMachineId(vm.getUuid()); + } + usageRecResponse.setVmName(usageRecord.getVmName()); + if (usageRecord.getTemplateId() != null) { + VMTemplateVO template = ApiDBUtils.findTemplateById(usageRecord.getTemplateId()); + if (template != null) { + usageRecResponse.setTemplateId(template.getUuid()); + } + } + + if(usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM){ + ServiceOfferingVO svcOffering = _entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class, usageRecord.getOfferingId().toString()); + //Service Offering Id + usageRecResponse.setOfferingId(svcOffering.getUuid()); + //VM Instance ID + VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(vm.getUuid()); + //Hypervisor Type + usageRecResponse.setType(usageRecord.getType()); + + } else if(usageRecord.getUsageType() == UsageTypes.IP_ADDRESS){ + //isSourceNAT + usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat"))?true:false); + //isSystem + usageRecResponse.setSystem((usageRecord.getSize() == 1)?true:false); + //IP Address ID + IPAddressVO ip = _entityMgr.findByIdIncludingRemoved(IPAddressVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(ip.getUuid()); + + } else if(usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED){ + //Device Type + usageRecResponse.setType(usageRecord.getType()); + if(usageRecord.getType().equals("DomainRouter")){ + //Domain Router Id + VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(vm.getUuid()); + } else { + //External Device Host Id + HostVO host = _entityMgr.findByIdIncludingRemoved(HostVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(host.getUuid()); + } + //Network ID + NetworkVO network = _entityMgr.findByIdIncludingRemoved(NetworkVO.class, usageRecord.getNetworkId().toString()); + usageRecResponse.setNetworkId(network.getUuid()); + + } else if(usageRecord.getUsageType() == UsageTypes.VOLUME){ + //Volume ID + VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(volume.getUuid()); + //Volume Size + usageRecResponse.setSize(usageRecord.getSize()); + //Disk Offering Id + if(usageRecord.getOfferingId() != null){ + DiskOfferingVO diskOff = _entityMgr.findByIdIncludingRemoved(DiskOfferingVO.class, usageRecord.getOfferingId().toString()); + usageRecResponse.setOfferingId(diskOff.getUuid()); + } + + } else if(usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO){ + //Template/ISO ID + VMTemplateVO tmpl = _entityMgr.findByIdIncludingRemoved(VMTemplateVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(tmpl.getUuid()); + //Template/ISO Size + usageRecResponse.setSize(usageRecord.getSize()); + + } else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){ + //Snapshot ID + SnapshotVO snap = _entityMgr.findByIdIncludingRemoved(SnapshotVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(snap.getUuid()); + //Snapshot Size + usageRecResponse.setSize(usageRecord.getSize()); + + } else if(usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY){ + //Load Balancer Policy ID + usageRecResponse.setUsageId(usageRecord.getUsageId().toString()); + + } else if(usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE){ + //Port Forwarding Rule ID + usageRecResponse.setUsageId(usageRecord.getUsageId().toString()); + + } else if(usageRecord.getUsageType() == UsageTypes.NETWORK_OFFERING){ + //Network Offering Id + NetworkOfferingVO netOff = _entityMgr.findByIdIncludingRemoved(NetworkOfferingVO.class, usageRecord.getOfferingId().toString()); + usageRecResponse.setOfferingId(netOff.getUuid()); + //is Default + usageRecResponse.setDefault((usageRecord.getUsageId() == 1)? true:false); + + } else if(usageRecord.getUsageType() == UsageTypes.VPN_USERS){ + //VPN User ID + usageRecResponse.setUsageId(usageRecord.getUsageId().toString()); + + } else if(usageRecord.getUsageType() == UsageTypes.SECURITY_GROUP){ + //Security Group Id + SecurityGroupVO sg = _entityMgr.findByIdIncludingRemoved(SecurityGroupVO.class, usageRecord.getUsageId().toString()); + usageRecResponse.setUsageId(sg.getUuid()); + } + + if (usageRecord.getRawUsage() != null) { + DecimalFormat decimalFormat = new DecimalFormat("###########.######"); + usageRecResponse.setRawUsage(decimalFormat.format(usageRecord.getRawUsage())); + } + + if (usageRecord.getStartDate() != null) { + usageRecResponse.setStartDate(getDateStringInternal(usageRecord.getStartDate())); + } + if (usageRecord.getEndDate() != null) { + usageRecResponse.setEndDate(getDateStringInternal(usageRecord.getEndDate())); + } + + return usageRecResponse; + } + + + public String getDateStringInternal(Date inputDate) { + if (inputDate == null) return null; + + TimeZone tz = _usageSvc.getUsageTimezone(); + Calendar cal = Calendar.getInstance(tz); + cal.setTime(inputDate); + + StringBuffer sb = new StringBuffer(); + sb.append(cal.get(Calendar.YEAR)+"-"); + + int month = cal.get(Calendar.MONTH) + 1; + if (month < 10) { + sb.append("0" + month + "-"); + } else { + sb.append(month+"-"); + } + + int day = cal.get(Calendar.DAY_OF_MONTH); + if (day < 10) { + sb.append("0" + day); + } else { + sb.append(""+day); + } + + sb.append("'T'"); + + int hour = cal.get(Calendar.HOUR_OF_DAY); + if (hour < 10) { + sb.append("0" + hour + ":"); + } else { + sb.append(hour+":"); + } + + int minute = cal.get(Calendar.MINUTE); + if (minute < 10) { + sb.append("0" + minute + ":"); + } else { + sb.append(minute+":"); + } + + int seconds = cal.get(Calendar.SECOND); + if (seconds < 10) { + sb.append("0" + seconds); + } else { + sb.append(""+seconds); + } + + double offset = cal.get(Calendar.ZONE_OFFSET); + if (tz.inDaylightTime(inputDate)) { + offset += (1.0*tz.getDSTSavings()); // add the timezone's DST value (typically 1 hour expressed in milliseconds) + } + + offset = offset / (1000d*60d*60d); + int hourOffset = (int)offset; + double decimalVal = Math.abs(offset) - Math.abs(hourOffset); + int minuteOffset = (int)(decimalVal * 60); + + if (hourOffset < 0) { + if (hourOffset > -10) { + sb.append("-0"+Math.abs(hourOffset)); + } else { + sb.append("-"+Math.abs(hourOffset)); + } + } else { + if (hourOffset < 10) { + sb.append("+0" + hourOffset); + } else { + sb.append("+" + hourOffset); + } + } + + sb.append(":"); + + if (minuteOffset == 0) { + sb.append("00"); + } else if (minuteOffset < 10) { + sb.append("0" + minuteOffset); + } else { + sb.append("" + minuteOffset); + } + + return sb.toString(); + } + + @Override + public TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor) { + Map tmDetails = ApiDBUtils.findHostDetailsById(trafficMonitor.getId()); + TrafficMonitorResponse response = new TrafficMonitorResponse(); + response.setId(trafficMonitor.getUuid()); + response.setIpAddress(trafficMonitor.getPrivateIpAddress()); + response.setNumRetries(tmDetails.get("numRetries")); + response.setTimeout(tmDetails.get("timeout")); + return response; + } } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java b/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java deleted file mode 100644 index 8728959..0000000 --- a/server/src/com/cloud/api/commands/AddTrafficMonitorCmd.java +++ /dev/null @@ -1,109 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.api.commands; - -import javax.inject.Inject; - -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.TrafficMonitorResponse; -import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; - -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.host.Host; -import com.cloud.network.NetworkUsageManager; -import com.cloud.user.Account; -import com.cloud.utils.exception.CloudRuntimeException; - -@APICommand(name = "addTrafficMonitor", description="Adds Traffic Monitor Host for Direct Network Usage", responseObject = TrafficMonitorResponse.class) -public class AddTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddTrafficMonitorCmd.class.getName()); - private static final String s_name = "addtrafficmonitorresponse"; - @Inject NetworkUsageManager networkUsageMgr; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class, - required = true, description="Zone in which to add the external firewall appliance.") - private Long zoneId; - - @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the traffic monitor Host") - private String url; - - @Parameter(name=ApiConstants.INCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will be metered") - private String inclZones; - - @Parameter(name=ApiConstants.EXCL_ZONES, type=CommandType.STRING, description="Traffic going into the listed zones will not be metered") - private String exclZones; - - /////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public String getInclZones() { - return inclZones; - } - - public String getExclZones() { - return exclZones; - } - - public Long getZoneId() { - return zoneId; - } - - public String getUrl() { - return url; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute(){ - try { - Host trafficMonitor = networkUsageMgr.addTrafficMonitor(this); - TrafficMonitorResponse response = networkUsageMgr.getApiResponse(trafficMonitor); - response.setObjectName("trafficmonitor"); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } catch (InvalidParameterValueException ipve) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); - } catch (CloudRuntimeException cre) { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); - } - } -} - http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java b/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java deleted file mode 100644 index 081d0be..0000000 --- a/server/src/com/cloud/api/commands/DeleteTrafficMonitorCmd.java +++ /dev/null @@ -1,86 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.api.commands; - -import javax.inject.Inject; - -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.HostResponse; -import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; - -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.network.NetworkUsageManager; -import com.cloud.user.Account; - -@APICommand(name = "deleteTrafficMonitor", description="Deletes an traffic monitor host.", responseObject = SuccessResponse.class) -public class DeleteTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName()); - private static final String s_name = "deletetrafficmonitorresponse"; - @Inject NetworkUsageManager _networkUsageMgr; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class, - required = true, description="Id of the Traffic Monitor Host.") - private Long id; - - /////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public Long getId() { - return id; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute(){ - try { - boolean result = _networkUsageMgr.deleteTrafficMonitor(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete traffic monitor."); - } - } catch (InvalidParameterValueException e) { - throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to delete traffic monitor."); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7970384f/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java b/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java deleted file mode 100644 index 4206cf8..0000000 --- a/server/src/com/cloud/api/commands/GenerateUsageRecordsCmd.java +++ /dev/null @@ -1,91 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.api.commands; - -import java.util.Date; - -import org.apache.cloudstack.api.*; -import org.apache.cloudstack.api.response.DomainResponse; -import org.apache.log4j.Logger; - -import org.apache.cloudstack.api.APICommand; -import org.apache.cloudstack.api.response.SuccessResponse; -import com.cloud.server.ManagementServerExt; -import com.cloud.user.Account; - -@APICommand(name = "generateUsageRecords", description="Generates usage records. This will generate records only if there any records to be generated, i.e if the scheduled usage job was not run or failed", responseObject=SuccessResponse.class) -public class GenerateUsageRecordsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GenerateUsageRecordsCmd.class.getName()); - - private static final String s_name = "generateusagerecordsresponse"; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class, - description="List events for the specified domain.") - private Long domainId; - - @Parameter(name=ApiConstants.END_DATE, type=CommandType.DATE, required=true, description="End date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-03.") - private Date endDate; - - @Parameter(name=ApiConstants.START_DATE, type=CommandType.DATE, required=true, description="Start date range for usage record query. Use yyyy-MM-dd as the date format, e.g. startDate=2009-06-01.") - private Date startDate; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public Long getDomainId() { - return domainId; - } - - public Date getEndDate() { - return endDate; - } - - public Date getStartDate() { - return startDate; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute(){ - ManagementServerExt _mgrExt = (ManagementServerExt)_mgr; - boolean result = _mgrExt.generateUsageRecords(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate usage records"); - } - } -}