Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

}
}
4 changes: 4 additions & 0 deletions api/src/main/java/org/apache/cloudstack/query/QueryService.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -152,6 +154,8 @@ public interface QueryService {

ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd);

ReadyForShutdownCmdResponse isReadyForShutdown(ReadyForShutdownCmd cmd);

ListResponse<DiskOfferingResponse> searchForDiskOfferings(ListDiskOfferingsCmd cmd);

ListResponse<ServiceOfferingResponse> searchForServiceOfferings(ListServiceOfferingsCmd cmd);
Expand Down
41 changes: 37 additions & 4 deletions server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
import com.cloud.vm.dao.VMInstanceDao;

@Component
public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements QueryService, Configurable {
public class QueryManagerImpl<ReadyForShutdownCmd, ReadyForShutdownCmdResponse> extends MutualExclusiveIdsManagerBase implements QueryService, Configurable {

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

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

return _domainJoinDao.searchAndCount(sc, searchFilter);
}

@Override
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd) {
Pair<List<AccountJoinVO>, Integer> result = searchForAccountsInternal(cmd);
Expand Down Expand Up @@ -2457,15 +2457,45 @@ private Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccount
}
}

return _accountJoinDao.searchAndCount(sc, searchFilter);
return _accountJoinDao.searchAndCount(sc, searchFilter);
}


@Override
public ReadyForShutdownCmdResponse isReadyForShutdown(ReadyForShutdownCmd cmd){

@Override
Pair<List<AsyncJobJoinVO>, Integer> result = pendingasyncjob(cmd);

//add additional steps if required
Integer count = result.second();
if (count.intValue == 0){
return true;
}
else{
return false;
}

}

private Pair<List<AsyncJobJoinVO>, Integer> pendingasyncjob(ReadyForShutdownCmd cmd)
{
Filter searchFilter = new Filter(AsyncJobJoinVO.class, "id", true, null, null);
SearchBuilder<AsyncJobJoinVO> 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<AsyncJobJoinVO> sc = sb.create();
return _jobJoinDao.searchAndCount(sc.searchFilter);
}


@Override
public ListResponse<AsyncJobResponse> searchForAsyncJobs(ListAsyncJobsCmd cmd) {

Pair<List<AsyncJobJoinVO>, Integer> result = searchForAsyncJobsInternal(cmd);
ListResponse<AsyncJobResponse> response = new ListResponse<AsyncJobResponse>();
List<AsyncJobResponse> jobResponses = ViewResponseHelper.createAsyncJobResponse(result.first().toArray(new AsyncJobJoinVO[result.first().size()]));
response.setResponses(jobResponses, result.second());

return response;
}

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




@Override
public ListResponse<StoragePoolResponse> searchForStoragePools(ListStoragePoolsCmd cmd) {
Pair<List<StoragePoolJoinVO>, Integer> result = searchForStoragePoolsInternal(cmd);
Expand Down