Skip to content

Commit bcd66c6

Browse files
committed
built readyforshutdown api
1 parent ba65b51 commit bcd66c6

4 files changed

Lines changed: 152 additions & 4 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
19+
package org.apache.cloudstack.api.command.admin.shutdown;
20+
21+
import org.apache.log4j.Logger;
22+
23+
import org.apache.cloudstack.api.APICommand;
24+
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.acl.RoleType;
26+
import org.apache.cloudstack.api.response.ReadyForShutdownCmdResponse;
27+
28+
@APICommand(name = "readyforshutdown", description = "checks whether cloudstack is ready for shutdown or not", responseObject = ReadyForShutdownCmdResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
29+
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
30+
31+
public class ReadyForShutdownCmd extends BaseCmd {
32+
public static final Logger s_logger = Logger.getLogger(ReadyForShutdownCmd.class.getName());
33+
public static final String s_name = "readyforshutdown";
34+
35+
/////////////////////////////////////////////////////
36+
/////////////// API Implementation///////////////////
37+
/////////////////////////////////////////////////////
38+
39+
@Override
40+
public String getCommandName() {
41+
return s_name;
42+
}
43+
44+
@Override
45+
public long getEntityOwnerId() {
46+
return 0;
47+
}
48+
49+
@Override
50+
public void execute() {
51+
52+
ReadyForShutdownCmdResponse response = _queryService.isReadyForShutdown(this);
53+
response.setResponseName(getCommandName());
54+
this.setResponseObject(response);
55+
}
56+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.response;
19+
20+
import org.apache.cloudstack.api.ApiConstants;
21+
import org.apache.cloudstack.api.BaseResponse;
22+
import org.apache.cloudstack.api.EntityReference;
23+
import org.apache.cloudstack.api.command.admin.shutdown.ReadyForShutdownCmd;
24+
import com.cloud.serializer.Param;
25+
26+
27+
@SuppressWarnings("unused")
28+
@EntityReference(value=ReadyForShutdownCmd.class)
29+
public class ReadyForShutdownCmdResponse extends BaseResponse{
30+
31+
32+
@SerializedName(ApiConstants.ID) @Param(description = "the ID of my resource")
33+
private String id;
34+
@SerializedName(ApiConstants.IS_ASYNC) @Param(description= "true if api is asynchronous")
35+
private Boolean isAsync;
36+
@SerializedName("readyforshutdown") @Param(description= "To check whether CloudStack is ready for shutdown ")
37+
private String readyforshutdown;
38+
public ReadyForShutdownCmdResponse()
39+
{
40+
this.isAsync = false;
41+
}
42+
public void setAsync(Boolean isAsync) {
43+
this.isAsync = isAsync;
44+
}
45+
public boolean getAsync(){
46+
return isAsync;
47+
}
48+
49+
public void setId(String id)
50+
{
51+
52+
this.id = id;
53+
54+
}
55+
}

api/src/main/java/org/apache/cloudstack/query/QueryService.java

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.command.admin.resource.icon.ListResourceIconCmd;
2828
import org.apache.cloudstack.api.command.admin.router.GetRouterHealthCheckResultsCmd;
2929
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
30+
import org.apache.cloudstack.api.command.admin.shutdown.ReadyForShutdownCmd;
3031
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
3132
import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStoresCmd;
3233
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
@@ -67,6 +68,7 @@
6768
import org.apache.cloudstack.api.response.ProjectAccountResponse;
6869
import org.apache.cloudstack.api.response.ProjectInvitationResponse;
6970
import org.apache.cloudstack.api.response.ProjectResponse;
71+
import org.apache.cloudstack.api.response.ReadyForShutdownCmdResponse;
7072
import org.apache.cloudstack.api.response.ResourceDetailResponse;
7173
import org.apache.cloudstack.api.response.ResourceIconResponse;
7274
import org.apache.cloudstack.api.response.ResourceTagResponse;
@@ -152,6 +154,8 @@ public interface QueryService {
152154

153155
ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd);
154156

157+
ReadyForShutdownCmdResponse isReadyForShutdown(ReadyForShutdownCmd cmd);
158+
155159
ListResponse<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd);
156160

157161
ListResponse<ServiceOfferingResponse> searchForServiceOfferings(ListServiceOfferingsCmd cmd);

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

100644100755
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
import com.cloud.vm.dao.VMInstanceDao;
268268

269269
@Component
270-
public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements QueryService, Configurable {
270+
public class QueryManagerImpl<ReadyForShutdownCmd, ReadyForShutdownCmdResponse> extends MutualExclusiveIdsManagerBase implements QueryService, Configurable {
271271

272272
public static final Logger s_logger = Logger.getLogger(QueryManagerImpl.class);
273273

@@ -2311,7 +2311,7 @@ private Pair<List<DomainJoinVO>, Integer> searchForDomainsInternal(ListDomainsCm
23112311

23122312
return _domainJoinDao.searchAndCount(sc, searchFilter);
23132313
}
2314-
2314+
23152315
@Override
23162316
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd) {
23172317
Pair<List<AccountJoinVO>, Integer> result = searchForAccountsInternal(cmd);
@@ -2457,15 +2457,45 @@ private Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccount
24572457
}
24582458
}
24592459

2460-
return _accountJoinDao.searchAndCount(sc, searchFilter);
2460+
return _accountJoinDao.searchAndCount(sc, searchFilter);
24612461
}
2462+
2463+
2464+
@Override
2465+
public ReadyForShutdownCmdResponse isReadyForShutdown(ReadyForShutdownCmd cmd){
24622466

2463-
@Override
2467+
Pair<List<AsyncJobJoinVO>, Integer> result = pendingasyncjob(cmd);
2468+
2469+
//add additional steps if required
2470+
Integer count = result.second();
2471+
if (count.intValue == 0){
2472+
return true;
2473+
}
2474+
else{
2475+
return false;
2476+
}
2477+
2478+
}
2479+
2480+
private Pair<List<AsyncJobJoinVO>, Integer> pendingasyncjob(ReadyForShutdownCmd cmd)
2481+
{
2482+
Filter searchFilter = new Filter(AsyncJobJoinVO.class, "id", true, null, null);
2483+
SearchBuilder<AsyncJobJoinVO> sb = _jobJoinDao.createSearchBuilder();
2484+
2485+
sb.and("jobstatus", sb.entity.getJobStatus(),SearchCriteria.Op.NULL); //can be broken into 2 steps incase more apt i.e. sb.and("jobstatus", sb.entity.getjobstatus(), SearchCriteria.Op.EQ)
2486+
SearchCriteria<AsyncJobJoinVO> sc = sb.create();
2487+
return _jobJoinDao.searchAndCount(sc.searchFilter);
2488+
}
2489+
2490+
2491+
@Override
24642492
public ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd) {
2493+
24652494
Pair<List<AsyncJobJoinVO>, Integer> result = searchForAsyncJobsInternal(cmd);
24662495
ListResponse<AsyncJobResponse> response = new ListResponse<AsyncJobResponse>();
24672496
List<AsyncJobResponse> jobResponses = ViewResponseHelper.createAsyncJobResponse(result.first().toArray(new AsyncJobJoinVO[result.first().size()]));
24682497
response.setResponses(jobResponses, result.second());
2498+
24692499
return response;
24702500
}
24712501

@@ -2535,6 +2565,9 @@ private Pair<List<AsyncJobJoinVO>, Integer> searchForAsyncJobsInternal(ListAsync
25352565
return _jobJoinDao.searchAndCount(sc, searchFilter);
25362566
}
25372567

2568+
2569+
2570+
25382571
@Override
25392572
public ListResponse<StoragePoolResponse> searchForStoragePools(ListStoragePoolsCmd cmd) {
25402573
Pair<List<StoragePoolJoinVO>, Integer> result = searchForStoragePoolsInternal(cmd);

0 commit comments

Comments
 (0)