1+ // Licensed to the Apache Software Foundation (ASF) under one
2+ // or more contributor license agreements. See the NOTICE file
3+ // distributed with this work for additional information
4+ // regarding copyright ownership. The ASF licenses this file
5+ // to you under the Apache License, Version 2.0 (the
6+ // "License"); you may not use this file except in compliance
7+ // with the License. You may obtain a copy of the License at
8+ //
9+ // http://www.apache.org/licenses/LICENSE-2.0
10+ //
11+ // Unless required by applicable law or agreed to in writing,
12+ // software distributed under the License is distributed on an
13+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ // KIND, either express or implied. See the License for the
15+ // specific language governing permissions and limitations
16+ // under the License.
17+
18+ package org .apache .cloudstack .api .command .admin .resource ;
19+
20+ import com .cloud .exception .ConcurrentOperationException ;
21+ import com .cloud .exception .InsufficientCapacityException ;
22+ import com .cloud .exception .NetworkRuleConflictException ;
23+ import com .cloud .exception .ResourceAllocationException ;
24+ import com .cloud .exception .ResourceUnavailableException ;
25+ import com .cloud .resource .RollingMaintenanceService ;
26+ import com .cloud .utils .Pair ;
27+ import org .apache .cloudstack .acl .RoleType ;
28+ import org .apache .cloudstack .api .APICommand ;
29+ import org .apache .cloudstack .api .ApiConstants ;
30+ import org .apache .cloudstack .api .BaseCmd ;
31+ import org .apache .cloudstack .api .Parameter ;
32+ import org .apache .cloudstack .api .ServerApiException ;
33+ import org .apache .cloudstack .api .response .ClusterResponse ;
34+ import org .apache .cloudstack .api .response .HostResponse ;
35+ import org .apache .cloudstack .api .response .PodResponse ;
36+ import org .apache .cloudstack .api .response .RollingMaintenanceResponse ;
37+ import org .apache .cloudstack .api .response .ZoneResponse ;
38+ import org .apache .cloudstack .context .CallContext ;
39+ import org .apache .log4j .Logger ;
40+
41+ import javax .inject .Inject ;
42+
43+ @ APICommand (name = StartRollingMaintenanceCmd .APINAME , description = "Start rolling maintenance" ,
44+ responseObject = RollingMaintenanceResponse .class ,
45+ requestHasSensitiveInfo = false , responseHasSensitiveInfo = false ,
46+ authorized = {RoleType .Admin })
47+ public class StartRollingMaintenanceCmd extends BaseCmd {
48+
49+ @ Inject
50+ RollingMaintenanceService rollingMaintenanceService ;
51+
52+ public static final Logger s_logger = Logger .getLogger (StartRollingMaintenanceCmd .class .getName ());
53+
54+ public static final String APINAME = "startRollingMaintenance" ;
55+
56+ /////////////////////////////////////////////////////
57+ //////////////// API parameters /////////////////////
58+ /////////////////////////////////////////////////////
59+
60+ @ Parameter (name = ApiConstants .POD_ID , type = CommandType .UUID ,
61+ entityType = PodResponse .class , description = "the ID of the pod to start maintenance on" )
62+ private Long podId ;
63+
64+ @ Parameter (name = ApiConstants .CLUSTER_ID , type = CommandType .UUID ,
65+ entityType = ClusterResponse .class , description = "the ID of the cluster to start maintenance on" )
66+ private Long clusterId ;
67+
68+ @ Parameter (name = ApiConstants .ZONE_ID , type = CommandType .UUID ,
69+ entityType = ZoneResponse .class , description = "the ID of the zone to start maintenance on" )
70+ private Long zoneId ;
71+
72+ @ Parameter (name = ApiConstants .HOST_ID , type = CommandType .UUID ,
73+ entityType = HostResponse .class , description = "the ID of the host to start maintenance on" )
74+ private Long hostId ;
75+
76+ @ Parameter (name = ApiConstants .FORCED , type = CommandType .BOOLEAN ,
77+ description = "if rolling mechanism should continue in case of an error" )
78+ private Boolean forced ;
79+
80+ @ Parameter (name = ApiConstants .PAYLOAD , type = CommandType .STRING ,
81+ description = "the command to execute while hosts are on maintenance" )
82+ private String payload ;
83+
84+ @ Parameter (name = ApiConstants .TIMEOUT , type = CommandType .INTEGER ,
85+ description = "optional operation timeout (in seconds) that overrides the global timeout setting" )
86+ private Integer timeout ;
87+
88+ /////////////////////////////////////////////////////
89+ /////////////////// Accessors ///////////////////////
90+ /////////////////////////////////////////////////////
91+
92+ public Long getPodId () {
93+ return podId ;
94+ }
95+
96+ public Long getClusterId () {
97+ return clusterId ;
98+ }
99+
100+ public Long getZoneId () {
101+ return zoneId ;
102+ }
103+
104+ public Long getHostId () {
105+ return hostId ;
106+ }
107+
108+ public Boolean getForced () {
109+ return forced != null && forced ;
110+ }
111+
112+ public String getPayload () {
113+ return payload ;
114+ }
115+
116+ public Integer getTimeout () {
117+ return timeout ;
118+ }
119+
120+ /////////////////////////////////////////////////////
121+ /////////////// API Implementation///////////////////
122+ /////////////////////////////////////////////////////
123+
124+ @ Override
125+ public void execute () throws ResourceUnavailableException , InsufficientCapacityException , ServerApiException , ConcurrentOperationException , ResourceAllocationException , NetworkRuleConflictException {
126+ Pair <Boolean , String > result = rollingMaintenanceService .startRollingMaintenance (this );
127+ RollingMaintenanceResponse response = new RollingMaintenanceResponse (result .first (), result .second ());
128+ response .setResponseName (getCommandName ());
129+ response .setObjectName ("rollingmaintenance" );
130+ this .setResponseObject (response );
131+ }
132+
133+ @ Override
134+ public String getCommandName () {
135+ return APINAME .toLowerCase () + BaseCmd .RESPONSE_SUFFIX ;
136+ }
137+
138+ @ Override
139+ public long getEntityOwnerId () {
140+ return CallContext .current ().getCallingAccountId ();
141+ }
142+ }
0 commit comments