diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/shutdown/ReadyForShutdownCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/shutdown/ReadyForShutdownCmd.java new file mode 100644 index 000000000000..e9d84937c26a --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/shutdown/ReadyForShutdownCmd.java @@ -0,0 +1,56 @@ +// 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.shutdown; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.response.ReadyForShutdownCmdResponse; + +@APICommand(name = "readyforshutdown", description = "checks whether cloudstack is ready for shutdown or not", responseObject = ReadyForShutdownCmdResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, +authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) + +public class ReadyForShutdownCmd extends BaseCmd { +public static final Logger s_logger = Logger.getLogger(ReadyForShutdownCmd.class.getName()); +public static final String s_name = "readyforshutdown"; + +///////////////////////////////////////////////////// +/////////////// API Implementation/////////////////// +///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; +} + +@Override + public long getEntityOwnerId() { + return 0; +} + +@Override + public void execute() { + + ReadyForShutdownCmdResponse response = _queryService.isReadyForShutdown(this); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } +} \ No newline at end of file diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ReadyForShutdownCmdResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ReadyForShutdownCmdResponse.java new file mode 100644 index 000000000000..8a7a744ea7c9 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/ReadyForShutdownCmdResponse.java @@ -0,0 +1,55 @@ +// 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.response; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.EntityReference; +import org.apache.cloudstack.api.command.admin.shutdown.ReadyForShutdownCmd; +import com.cloud.serializer.Param; + + +@SuppressWarnings("unused") +@EntityReference(value=ReadyForShutdownCmd.class) +public class ReadyForShutdownCmdResponse extends BaseResponse{ + + + @SerializedName(ApiConstants.ID) @Param(description = "the ID of my resource") + private String id; + @SerializedName(ApiConstants.IS_ASYNC) @Param(description= "true if api is asynchronous") + private Boolean isAsync; + @SerializedName("readyforshutdown") @Param(description= "To check whether CloudStack is ready for shutdown ") + private String readyforshutdown; +public ReadyForShutdownCmdResponse() + { + this.isAsync = false; + } +public void setAsync(Boolean isAsync) { + this.isAsync = isAsync; + } +public boolean getAsync(){ + return isAsync; + } + +public void setId(String id) + { + + this.id = id; + + } +} \ No newline at end of file diff --git a/api/src/main/java/org/apache/cloudstack/query/QueryService.java b/api/src/main/java/org/apache/cloudstack/query/QueryService.java old mode 100644 new mode 100755 index 231e0f2cbd18..918785f35af5 --- a/api/src/main/java/org/apache/cloudstack/query/QueryService.java +++ b/api/src/main/java/org/apache/cloudstack/query/QueryService.java @@ -27,6 +27,7 @@ import org.apache.cloudstack.api.command.admin.resource.icon.ListResourceIconCmd; import org.apache.cloudstack.api.command.admin.router.GetRouterHealthCheckResultsCmd; import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd; +import org.apache.cloudstack.api.command.admin.shutdown.ReadyForShutdownCmd; import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd; import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStoresCmd; import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd; @@ -67,6 +68,7 @@ import org.apache.cloudstack.api.response.ProjectAccountResponse; import org.apache.cloudstack.api.response.ProjectInvitationResponse; import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ReadyForShutdownCmdResponse; import org.apache.cloudstack.api.response.ResourceDetailResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; import org.apache.cloudstack.api.response.ResourceTagResponse; @@ -152,6 +154,8 @@ public interface QueryService { ListResponse searchForAsyncJobs(ListAsyncJobsCmd cmd); + ReadyForShutdownCmdResponse isReadyForShutdown(ReadyForShutdownCmd cmd); + ListResponse searchForDiskOfferings(ListDiskOfferingsCmd cmd); ListResponse searchForServiceOfferings(ListServiceOfferingsCmd cmd); diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java old mode 100644 new mode 100755 index 2f8ca01516d4..04608bf31ffe --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -267,7 +267,7 @@ import com.cloud.vm.dao.VMInstanceDao; @Component -public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements QueryService, Configurable { +public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements QueryService, Configurable { public static final Logger s_logger = Logger.getLogger(QueryManagerImpl.class); @@ -2311,7 +2311,7 @@ private Pair, Integer> searchForDomainsInternal(ListDomainsCm return _domainJoinDao.searchAndCount(sc, searchFilter); } - + @Override public ListResponse searchForAccounts(ListAccountsCmd cmd) { Pair, Integer> result = searchForAccountsInternal(cmd); @@ -2457,15 +2457,45 @@ private Pair, Integer> searchForAccountsInternal(ListAccount } } - return _accountJoinDao.searchAndCount(sc, searchFilter); + return _accountJoinDao.searchAndCount(sc, searchFilter); } + + + @Override + public ReadyForShutdownCmdResponse isReadyForShutdown(ReadyForShutdownCmd cmd){ - @Override + Pair, Integer> result = pendingasyncjob(cmd); + + //add additional steps if required + Integer count = result.second(); +if (count.intValue == 0){ + return true; +} +else{ + return false; +} + +} + + private Pair, Integer> pendingasyncjob(ReadyForShutdownCmd cmd) + { + Filter searchFilter = new Filter(AsyncJobJoinVO.class, "id", true, null, null); + SearchBuilder sb = _jobJoinDao.createSearchBuilder(); + + 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) + SearchCriteria sc = sb.create(); + return _jobJoinDao.searchAndCount(sc.searchFilter); + } + + + @Override public ListResponse searchForAsyncJobs(ListAsyncJobsCmd cmd) { + Pair, Integer> result = searchForAsyncJobsInternal(cmd); ListResponse response = new ListResponse(); List jobResponses = ViewResponseHelper.createAsyncJobResponse(result.first().toArray(new AsyncJobJoinVO[result.first().size()])); response.setResponses(jobResponses, result.second()); + return response; } @@ -2535,6 +2565,9 @@ private Pair, Integer> searchForAsyncJobsInternal(ListAsync return _jobJoinDao.searchAndCount(sc, searchFilter); } + + + @Override public ListResponse searchForStoragePools(ListStoragePoolsCmd cmd) { Pair, Integer> result = searchForStoragePoolsInternal(cmd);