|
1 | | -package com.cloud.api.commands; |
2 | | - |
3 | | -import com.cloud.api.BaseCmd; |
4 | | -import com.cloud.api.ServerApiException; |
5 | | -import com.cloud.exception.ConcurrentOperationException; |
6 | | -import com.cloud.exception.InsufficientCapacityException; |
7 | | -import com.cloud.exception.NetworkRuleConflictException; |
8 | | -import com.cloud.exception.ResourceAllocationException; |
9 | | -import com.cloud.exception.ResourceUnavailableException; |
10 | | - |
11 | | -public class GetCiscoVSMByClusterIdCmd extends BaseCmd { |
12 | | - |
13 | | - @Override |
14 | | - public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { |
15 | | - // TODO Auto-generated method stub |
16 | | - |
17 | | - } |
18 | | - |
19 | | - @Override |
20 | | - public String getCommandName() { |
21 | | - // TODO Auto-generated method stub |
22 | | - return null; |
23 | | - } |
24 | | - |
25 | | - @Override |
26 | | - public long getEntityOwnerId() { |
27 | | - // TODO Auto-generated method stub |
28 | | - return 0; |
29 | | - } |
30 | | - |
31 | | - public long getClusterId() { |
32 | | - // TODO Auto-generated method stub |
33 | | - return 0; |
34 | | - } |
35 | | - |
36 | | -} |
| 1 | +/** |
| 2 | + * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This software is licensed under the GNU General Public License v3 or later. |
| 5 | + * |
| 6 | + * It is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or any later version. |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +package com.cloud.api.commands; |
| 20 | + |
| 21 | +import org.apache.log4j.Logger; |
| 22 | +import com.cloud.api.ApiConstants; |
| 23 | +import com.cloud.api.BaseAsyncCmd; |
| 24 | +import com.cloud.api.BaseCmd; |
| 25 | +import com.cloud.api.IdentityMapper; |
| 26 | +import com.cloud.api.Implementation; |
| 27 | +import com.cloud.api.Parameter; |
| 28 | +import com.cloud.api.PlugService; |
| 29 | +import com.cloud.api.ServerApiException; |
| 30 | +import com.cloud.api.response.CiscoNexusVSMResponse; |
| 31 | +import com.cloud.exception.ConcurrentOperationException; |
| 32 | +import com.cloud.exception.InsufficientCapacityException; |
| 33 | +import com.cloud.exception.InvalidParameterValueException; |
| 34 | +import com.cloud.exception.ResourceAllocationException; |
| 35 | +import com.cloud.exception.ResourceUnavailableException; |
| 36 | +import com.cloud.network.CiscoNexusVSMDeviceVO; |
| 37 | +import com.cloud.network.element.CiscoNexusVSMElementService; |
| 38 | +import com.cloud.user.UserContext; |
| 39 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 40 | + |
| 41 | +@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves a Cisco Nexus 1000v Virtual Switch Manager device associated with a Cluster") |
| 42 | +public class GetCiscoVSMByClusterIdCmd extends BaseCmd { |
| 43 | + |
| 44 | + public static final Logger s_logger = Logger.getLogger(GetCiscoVSMByClusterIdCmd.class.getName()); |
| 45 | + private static final String s_name = "getciscovsmbyclusteridcmdresponse"; |
| 46 | + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; |
| 47 | + |
| 48 | + ///////////////////////////////////////////////////// |
| 49 | + //////////////// API parameters ///////////////////// |
| 50 | + ///////////////////////////////////////////////////// |
| 51 | + |
| 52 | + @IdentityMapper(entityTableName="cluster") |
| 53 | + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required = true, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.") |
| 54 | + private long id; |
| 55 | + |
| 56 | + ///////////////////////////////////////////////////// |
| 57 | + /////////////////// Accessors /////////////////////// |
| 58 | + ///////////////////////////////////////////////////// |
| 59 | + |
| 60 | + public long getClusterId() { |
| 61 | + return id; |
| 62 | + } |
| 63 | + |
| 64 | + ///////////////////////////////////////////////////// |
| 65 | + /////////////// API Implementation/////////////////// |
| 66 | + ///////////////////////////////////////////////////// |
| 67 | + |
| 68 | + // NOTE- The uuid that is sent in during the invocation of the API AddCiscoNexusVSM() |
| 69 | + // automagically gets translated to the corresponding db id before this execute() method |
| 70 | + // is invoked. That's the reason why we don't have any uuid-dbid translation code here. |
| 71 | + @Override |
| 72 | + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { |
| 73 | + try { |
| 74 | + CiscoNexusVSMDeviceVO vsmDeviceVO = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this); |
| 75 | + if (vsmDeviceVO != null) { |
| 76 | + CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMResponse(vsmDeviceVO); |
| 77 | + response.setObjectName("cisconexusvsm"); |
| 78 | + response.setResponseName(getCommandName()); |
| 79 | + this.setResponseObject(response); |
| 80 | + } else { |
| 81 | + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error."); |
| 82 | + } |
| 83 | + } catch (InvalidParameterValueException invalidParamExcp) { |
| 84 | + throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); |
| 85 | + } catch (CloudRuntimeException runtimeExcp) { |
| 86 | + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public String getCommandName() { |
| 92 | + return s_name; |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public long getEntityOwnerId() { |
| 97 | + return UserContext.current().getCaller().getId(); |
| 98 | + } |
| 99 | +} |
0 commit comments