mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-786, CLOUDSTACK-1014: Moved usage APIs to cloud-api. Removed ManagementServerExt. Usage API related implementation is added to UsageServiceImpl
This commit is contained in:
parent
2234e043e2
commit
fc0bf21a13
@ -38,6 +38,16 @@ public interface EntityManager {
|
||||
*/
|
||||
public <T, K extends Serializable> T findById(Class<T> entityType, K id);
|
||||
|
||||
/**
|
||||
* Finds an entity by its id including removed.
|
||||
* @param <T> class of the entity you're trying to find.
|
||||
* @param <K> 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, K extends Serializable> T findByIdIncludingRemoved(Class<T> entityType, K id);
|
||||
|
||||
/**
|
||||
* Finds a unique entity by uuid string
|
||||
* @param <T> entity class
|
||||
|
||||
37
api/src/com/cloud/network/NetworkUsageService.java
Normal file
37
api/src/com/cloud/network/NetworkUsageService.java
Normal file
@ -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<? extends Host> listTrafficMonitors(ListTrafficMonitorsCmd cmd);
|
||||
|
||||
}
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.api.commands;
|
||||
package org.apache.cloudstack.api.command.admin.usage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -30,7 +30,6 @@ 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;
|
||||
|
||||
@ -38,7 +37,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
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 /////////////////////
|
||||
@ -94,8 +92,8 @@ public class AddTrafficMonitorCmd extends BaseCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
Host trafficMonitor = networkUsageMgr.addTrafficMonitor(this);
|
||||
TrafficMonitorResponse response = networkUsageMgr.getApiResponse(trafficMonitor);
|
||||
Host trafficMonitor = _networkUsageService.addTrafficMonitor(this);
|
||||
TrafficMonitorResponse response = _responseGenerator.createTrafficMonitorResponse(trafficMonitor);
|
||||
response.setObjectName("trafficmonitor");
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.api.commands;
|
||||
package org.apache.cloudstack.api.command.admin.usage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -29,14 +29,12 @@ 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 /////////////////////
|
||||
@ -71,7 +69,7 @@ public class DeleteTrafficMonitorCmd extends BaseCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
boolean result = _networkUsageMgr.deleteTrafficMonitor(this);
|
||||
boolean result = _networkUsageService.deleteTrafficMonitor(this);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
response.setResponseName(getCommandName());
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.api.commands;
|
||||
package org.apache.cloudstack.api.command.admin.usage;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -24,7 +24,6 @@ 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)
|
||||
@ -79,8 +78,7 @@ public class GenerateUsageRecordsCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
ManagementServerExt _mgrExt = (ManagementServerExt)_mgr;
|
||||
boolean result = _mgrExt.generateUsageRecords(this);
|
||||
boolean result = _usageService.generateUsageRecords(this);
|
||||
if (result) {
|
||||
SuccessResponse response = new SuccessResponse(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
@ -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<? extends Usage> usageRecords = _usageService.getUsageRecords(this);
|
||||
ListResponse<UsageRecordResponse> response = new ListResponse<UsageRecordResponse>();
|
||||
List<UsageRecordResponse> usageResponses = new ArrayList<UsageRecordResponse>();
|
||||
for(Usage usageRecord: usageRecords){
|
||||
UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord);
|
||||
usageResponse.setObjectName("usagerecord");
|
||||
usageResponses.add(usageResponse);
|
||||
}
|
||||
|
||||
response.setResponses(usageResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.api.commands;
|
||||
package org.apache.cloudstack.api.command.admin.usage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.network.NetworkUsageManager;
|
||||
|
||||
|
||||
@APICommand(name = "listTrafficMonitors", description="List traffic monitor Hosts.", responseObject = TrafficMonitorResponse.class)
|
||||
@ -40,7 +39,6 @@ public class ListTrafficMonitorsCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName());
|
||||
private static final String s_name = "listtrafficmonitorsresponse";
|
||||
|
||||
@Inject NetworkUsageManager networkUsageMgr;
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -68,12 +66,12 @@ public class ListTrafficMonitorsCmd extends BaseListCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
List<? extends Host> trafficMonitors = networkUsageMgr.listTrafficMonitors(this);
|
||||
List<? extends Host> trafficMonitors = _networkUsageService.listTrafficMonitors(this);
|
||||
|
||||
ListResponse<TrafficMonitorResponse> listResponse = new ListResponse<TrafficMonitorResponse>();
|
||||
List<TrafficMonitorResponse> responses = new ArrayList<TrafficMonitorResponse>();
|
||||
for (Host trafficMonitor : trafficMonitors) {
|
||||
TrafficMonitorResponse response = networkUsageMgr.getApiResponse(trafficMonitor);
|
||||
TrafficMonitorResponse response = _responseGenerator.createTrafficMonitorResponse(trafficMonitor);
|
||||
response.setObjectName("trafficmonitor");
|
||||
response.setResponseName(getCommandName());
|
||||
responses.add(response);
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.api.commands;
|
||||
package org.apache.cloudstack.api.command.admin.usage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -23,7 +23,6 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import com.cloud.server.ManagementServerExt;
|
||||
import org.apache.cloudstack.api.response.UsageTypeResponse;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@ -43,8 +42,7 @@ public class ListUsageTypesCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
ManagementServerExt _mgrExt = (ManagementServerExt)_mgr;
|
||||
List<UsageTypeResponse> result = _mgrExt.listUsageTypes();
|
||||
List<UsageTypeResponse> result = _usageService.listUsageTypes();
|
||||
ListResponse<UsageTypeResponse> response = new ListResponse<UsageTypeResponse>();
|
||||
response.setResponses(result);
|
||||
response.setResponseName(getCommandName());
|
||||
69
api/src/org/apache/cloudstack/usage/Usage.java
Normal file
69
api/src/org/apache/cloudstack/usage/Usage.java
Normal file
@ -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();
|
||||
}
|
||||
13
server/src/com/cloud/server/ManagementServerExt.java → api/src/org/apache/cloudstack/usage/UsageService.java
Normal file → Executable file
13
server/src/com/cloud/server/ManagementServerExt.java → api/src/org/apache/cloudstack/usage/UsageService.java
Normal file → Executable file
@ -14,16 +14,16 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.server;
|
||||
package org.apache.cloudstack.usage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.cloud.api.commands.GenerateUsageRecordsCmd;
|
||||
import com.cloud.api.commands.GetUsageRecordsCmd;
|
||||
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;
|
||||
import com.cloud.usage.UsageVO;
|
||||
public interface ManagementServerExt extends ManagementServer {
|
||||
|
||||
public interface UsageService {
|
||||
/**
|
||||
* Generate Billing Records from the last time it was generated to the
|
||||
* time specified.
|
||||
@ -50,7 +50,7 @@ public interface ManagementServerExt extends ManagementServer {
|
||||
* the appropriate page number)
|
||||
* @return a list of usage records
|
||||
*/
|
||||
List<UsageVO> getUsageRecords(GetUsageRecordsCmd cmd);
|
||||
List<? extends Usage> getUsageRecords(GetUsageRecordsCmd cmd);
|
||||
|
||||
/**
|
||||
* Retrieves the timezone used for usage aggregation. One day is represented as midnight to 11:59:59pm
|
||||
@ -60,4 +60,5 @@ public interface ManagementServerExt extends ManagementServer {
|
||||
TimeZone getUsageTimezone();
|
||||
|
||||
List<UsageTypeResponse> listUsageTypes();
|
||||
|
||||
}
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.usage;
|
||||
package org.apache.cloudstack.usage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -36,7 +36,7 @@
|
||||
-->
|
||||
<bean id="databaseUpgradeChecker" class="com.cloud.upgrade.DatabaseUpgradeChecker" />
|
||||
|
||||
<bean id="management-server" class ="com.cloud.server.ManagementServerExtImpl" />
|
||||
<bean id="management-server" class ="com.cloud.server.ManagementServerImpl" />
|
||||
<bean id="configuration-server" class="com.cloud.server.ConfigurationServerImpl" />
|
||||
|
||||
<bean id="clusterManagerImpl" class="com.cloud.cluster.ClusterManagerImpl" />
|
||||
|
||||
@ -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<Class<?>> getCommands() {
|
||||
List<Class<?>> cmdList = super.getCommands();
|
||||
|
||||
@ -29,7 +29,7 @@ under the License.
|
||||
</system-integrity-checker>
|
||||
|
||||
<interceptor library="com.cloud.configuration.DefaultInterceptorLibrary"/>
|
||||
<management-server class="com.cloud.server.ManagementServerExtImpl" library="com.cloud.configuration.PremiumComponentLibrary">
|
||||
<management-server class="com.cloud.server.ManagementServerImpl" library="com.cloud.configuration.PremiumComponentLibrary">
|
||||
<dao name="Configuration configuration server" class="com.cloud.configuration.dao.ConfigurationDaoImpl">
|
||||
<param name="premium">true</param>
|
||||
</dao>
|
||||
|
||||
@ -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<String, String> findHostDetailsById(long hostId){
|
||||
return _hostDetailsDao.findDetails(hostId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<String, String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,370 +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.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.cloudstack.api.response.AccountResponse;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.domain.Domain;
|
||||
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.server.ManagementServerExt;
|
||||
import org.apache.cloudstack.api.response.UsageRecordResponse;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uuididentity.dao.IdentityDao;
|
||||
import com.cloud.uuididentity.dao.IdentityDaoImpl;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// Misc parameters ///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
private TimeZone usageTimezone;
|
||||
|
||||
public TimeZone getUsageTimezone() {
|
||||
return usageTimezone;
|
||||
}
|
||||
|
||||
public void setUsageTimezone(TimeZone tz) {
|
||||
this.usageTimezone = tz;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
public String getDateStringInternal(Date inputDate) {
|
||||
if (inputDate == null) return null;
|
||||
|
||||
TimeZone tz = 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 void execute(){
|
||||
ManagementServerExt _mgrExt = (ManagementServerExt)_mgr;
|
||||
List<UsageVO> usageRecords = _mgrExt.getUsageRecords(this);
|
||||
IdentityDao identityDao = new IdentityDaoImpl();
|
||||
ListResponse<UsageRecordResponse> response = new ListResponse<UsageRecordResponse>();
|
||||
List<UsageRecordResponse> usageResponses = new ArrayList<UsageRecordResponse>();
|
||||
for (Object usageRecordGeneric : usageRecords) {
|
||||
UsageRecordResponse usageRecResponse = new UsageRecordResponse();
|
||||
if (usageRecordGeneric instanceof UsageVO) {
|
||||
UsageVO usageRecord = (UsageVO)usageRecordGeneric;
|
||||
|
||||
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 = ApiDBUtils.findVMInstanceById(usageRecord.getVmInstanceId());
|
||||
if (vm != null) {
|
||||
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){
|
||||
//Service Offering Id
|
||||
usageRecResponse.setOfferingId(identityDao.getIdentityUuid("disk_offering", usageRecord.getOfferingId().toString()));
|
||||
//VM Instance ID
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_instance", usageRecord.getUsageId().toString()));
|
||||
//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
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("user_ip_address", usageRecord.getUsageId().toString()));
|
||||
|
||||
} 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
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_instance", usageRecord.getUsageId().toString()));
|
||||
} else {
|
||||
//External Device Host Id
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("host", usageRecord.getUsageId().toString()));
|
||||
}
|
||||
//Network ID
|
||||
usageRecResponse.setNetworkId(identityDao.getIdentityUuid("networks", usageRecord.getNetworkId().toString()));
|
||||
|
||||
} else if(usageRecord.getUsageType() == UsageTypes.VOLUME){
|
||||
//Volume ID
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("volumes", usageRecord.getUsageId().toString()));
|
||||
//Volume Size
|
||||
usageRecResponse.setSize(usageRecord.getSize());
|
||||
//Disk Offering Id
|
||||
if(usageRecord.getOfferingId() != null){
|
||||
usageRecResponse.setOfferingId(identityDao.getIdentityUuid("disk_offering", usageRecord.getOfferingId().toString()));
|
||||
}
|
||||
|
||||
} else if(usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO){
|
||||
//Template/ISO ID
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("vm_template", usageRecord.getUsageId().toString()));
|
||||
//Template/ISO Size
|
||||
usageRecResponse.setSize(usageRecord.getSize());
|
||||
|
||||
} else if(usageRecord.getUsageType() == UsageTypes.SNAPSHOT){
|
||||
//Snapshot ID
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("snapshots", usageRecord.getUsageId().toString()));
|
||||
//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
|
||||
usageRecResponse.setOfferingId(identityDao.getIdentityUuid("network_offerings", usageRecord.getOfferingId().toString()));
|
||||
//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
|
||||
usageRecResponse.setUsageId(identityDao.getIdentityUuid("security_group", usageRecord.getUsageId().toString()));
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
usageRecResponse.setObjectName("usagerecord");
|
||||
usageResponses.add(usageRecResponse);
|
||||
}
|
||||
|
||||
response.setResponses(usageResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,6 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import net.sf.ehcache.Cache;
|
||||
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
@ -47,6 +46,12 @@ public class EntityManagerImpl extends ManagerBase implements EntityManager {
|
||||
GenericDao<? extends T, K> dao = (GenericDao<? extends T, K>)GenericDaoBase.getDao(entityType);
|
||||
return dao.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable> T findByIdIncludingRemoved(Class<T> entityType, K id) {
|
||||
GenericDao<? extends T, K> dao = (GenericDao<? extends T, K>)GenericDaoBase.getDao(entityType);
|
||||
return dao.findByIdIncludingRemoved(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T findByUuid(Class<T> entityType, String uuid) {
|
||||
|
||||
@ -18,26 +18,12 @@ package com.cloud.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.commands.AddTrafficMonitorCmd;
|
||||
import com.cloud.api.commands.DeleteTrafficMonitorCmd;
|
||||
import com.cloud.api.commands.ListTrafficMonitorsCmd;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.network.dao.IPAddressVO;
|
||||
|
||||
import org.apache.cloudstack.api.response.TrafficMonitorResponse;
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface NetworkUsageManager extends Manager {
|
||||
|
||||
Host addTrafficMonitor(AddTrafficMonitorCmd cmd);
|
||||
|
||||
TrafficMonitorResponse getApiResponse(Host trafficMonitor);
|
||||
|
||||
boolean deleteTrafficMonitor(DeleteTrafficMonitorCmd cmd);
|
||||
|
||||
List<HostVO> listTrafficMonitors(ListTrafficMonitorsCmd cmd);
|
||||
|
||||
List<IPAddressVO> listAllocatedDirectIps(long zoneId);
|
||||
|
||||
}
|
||||
|
||||
@ -44,9 +44,6 @@ import com.cloud.agent.api.RecurringNetworkUsageCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupTrafficMonitorCommand;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.api.commands.AddTrafficMonitorCmd;
|
||||
import com.cloud.api.commands.DeleteTrafficMonitorCmd;
|
||||
import com.cloud.api.commands.ListTrafficMonitorsCmd;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
@ -71,6 +68,10 @@ import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceStateAdapter;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.resource.UnableDeleteHostException;
|
||||
|
||||
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.usage.UsageIPAddressVO;
|
||||
import com.cloud.user.AccountManager;
|
||||
@ -93,7 +94,7 @@ import com.cloud.utils.net.MacAddress;
|
||||
|
||||
@Component
|
||||
@Local(value = {NetworkUsageManager.class})
|
||||
public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsageManager, ResourceStateAdapter {
|
||||
public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsageService, NetworkUsageManager, ResourceStateAdapter {
|
||||
public enum NetworkUsageResourceName {
|
||||
TrafficSentinel;
|
||||
}
|
||||
@ -211,17 +212,6 @@ public class NetworkUsageManagerImpl extends ManagerBase implements NetworkUsage
|
||||
return _resourceMgr.listAllHostsInOneZoneByType(Host.Type.TrafficMonitor, zoneId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrafficMonitorResponse getApiResponse(Host trafficMonitor) {
|
||||
Map<String, String> tmDetails = _detailsDao.findDetails(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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
AllocatedIpSearch = _ipAddressDao.createSearchBuilder();
|
||||
|
||||
49
server/src/com/cloud/server/ManagementServerExtImpl.java → server/src/com/cloud/usage/UsageServiceImpl.java
Normal file → Executable file
49
server/src/com/cloud/server/ManagementServerExtImpl.java → server/src/com/cloud/usage/UsageServiceImpl.java
Normal file → Executable file
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.server;
|
||||
package com.cloud.usage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
@ -23,45 +23,59 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.api.commands.GenerateUsageRecordsCmd;
|
||||
import com.cloud.api.commands.GetUsageRecordsCmd;
|
||||
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;
|
||||
import org.apache.cloudstack.usage.UsageService;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.projects.Project;
|
||||
import org.apache.cloudstack.api.response.UsageTypeResponse;
|
||||
|
||||
import com.cloud.usage.UsageJobVO;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.projects.ProjectManager;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageJobDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
public class ManagementServerExtImpl extends ManagementServerImpl implements ManagementServerExt {
|
||||
@Component
|
||||
@Local(value = { UsageService.class })
|
||||
public class UsageServiceImpl extends ManagerBase implements UsageService, Manager {
|
||||
public static final Logger s_logger = Logger.getLogger(UsageServiceImpl.class);
|
||||
|
||||
//ToDo: Move implementation to ManagaerImpl
|
||||
|
||||
@Inject private AccountDao _accountDao;
|
||||
@Inject private DomainDao _domainDao;
|
||||
@Inject private UsageDao _usageDao;
|
||||
@Inject private UsageJobDao _usageJobDao;
|
||||
@Inject private ConfigurationDao _configDao;
|
||||
@Inject private ProjectManager _projectMgr;
|
||||
private TimeZone _usageTimezone;
|
||||
|
||||
public ManagementServerExtImpl() {
|
||||
public UsageServiceImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
Map<String, String> configs = getConfigs();
|
||||
String timeZoneStr = configs.get("usage.aggregation.timezone");
|
||||
String timeZoneStr = _configDao.getValue(Config.UsageAggregationTimezone.toString());
|
||||
if (timeZoneStr == null) {
|
||||
timeZoneStr = "GMT";
|
||||
}
|
||||
@ -195,9 +209,6 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
||||
swap.close();
|
||||
}
|
||||
|
||||
// now that we are done with the records, update the command with the correct timezone so it can write the proper response
|
||||
cmd.setUsageTimezone(getUsageTimezone());
|
||||
|
||||
return usageRecords;
|
||||
}
|
||||
|
||||
@ -206,12 +217,6 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
||||
return _usageTimezone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getCommands() {
|
||||
//TODO: Add api cmd classes
|
||||
return null;
|
||||
}
|
||||
|
||||
private Date computeAdjustedTime(Date initialDate, TimeZone targetTZ, boolean adjustToDayStart) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(initialDate);
|
||||
@ -251,4 +256,6 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
||||
public List<UsageTypeResponse> listUsageTypes() {
|
||||
return UsageTypes.listUsageTypes();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -17,6 +17,7 @@
|
||||
package com.cloud.usage;
|
||||
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.usage.Usage;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -31,7 +32,7 @@ import javax.persistence.TemporalType;
|
||||
|
||||
@Entity
|
||||
@Table(name="cloud_usage")
|
||||
public class UsageVO implements InternalIdentity {
|
||||
public class UsageVO implements Usage, InternalIdentity {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
@ -167,74 +168,92 @@ public class UsageVO implements InternalIdentity {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUsageDisplay() {
|
||||
return usageDisplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUsageType() {
|
||||
return usageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getRawUsage() {
|
||||
return rawUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getVmInstanceId() {
|
||||
return vmInstanceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOfferingId() {
|
||||
return offeringId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTemplateId() {
|
||||
return templateId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getUsageId() {
|
||||
return usageId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
|
||||
@ -26,11 +26,11 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.usage.UsageIPAddressVO;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageIPAddressDao;
|
||||
|
||||
@ -26,11 +26,11 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.usage.UsageLoadBalancerPolicyVO;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageLoadBalancerPolicyDao;
|
||||
|
||||
@ -26,10 +26,10 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsageNetworkOfferingVO;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageNetworkOfferingDao;
|
||||
|
||||
@ -25,9 +25,9 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsageNetworkVO;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageNetworkDao;
|
||||
|
||||
@ -26,10 +26,10 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsagePortForwardingRuleVO;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsagePortForwardingRuleDao;
|
||||
|
||||
@ -26,10 +26,10 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsageSecurityGroupVO;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageSecurityGroupDao;
|
||||
|
||||
@ -26,11 +26,11 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.StorageTypes;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageStorageVO;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageStorageDao;
|
||||
|
||||
@ -26,9 +26,9 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVMInstanceVO;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
|
||||
@ -26,10 +26,10 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsageVPNUserVO;
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
import com.cloud.usage.dao.UsageVPNUserDao;
|
||||
|
||||
@ -26,9 +26,9 @@ import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
|
||||
import com.cloud.usage.UsageServer;
|
||||
import com.cloud.usage.UsageTypes;
|
||||
import com.cloud.usage.UsageVO;
|
||||
import com.cloud.usage.UsageVolumeVO;
|
||||
import com.cloud.usage.dao.UsageDao;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user