mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Separate all volume related APIs to two Cmd classes based on two
response views.
This commit is contained in:
parent
f3ef86d296
commit
015d06e7fc
@ -67,7 +67,7 @@ public interface VolumeApiService {
|
||||
/**
|
||||
* Uploads the volume to secondary storage
|
||||
*
|
||||
* @param UploadVolumeCmd cmd
|
||||
* @param UploadVolumeCmdByAdmin cmd
|
||||
*
|
||||
* @return Volume object
|
||||
*/
|
||||
|
||||
@ -2,5 +2,6 @@ package org.apache.cloudstack.acl;
|
||||
|
||||
public enum AclEntityType {
|
||||
// currently supported entity, to be added one by one after we support acl on the entity
|
||||
VM;
|
||||
VM,
|
||||
VOLUME;
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ public interface ResponseGenerator {
|
||||
|
||||
ZoneResponse createZoneResponse(DataCenter dataCenter, Boolean showCapacities);
|
||||
|
||||
VolumeResponse createVolumeResponse(Volume volume);
|
||||
VolumeResponse createVolumeResponse(ResponseView view, Volume volume);
|
||||
|
||||
InstanceGroupResponse createInstanceGroupResponse(InstanceGroup group);
|
||||
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "attachVolume", description = "Attaches a disk volume to a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Full)
|
||||
public class AttachVolumeCmdByAdmin extends AttachVolumeCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AttachVolumeCmdByAdmin.class.getName());
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId()+" VmId: "+getVirtualMachineId());
|
||||
Volume result = _volumeService.attachVolumeToVM(this);
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Full)
|
||||
public class CreateVolumeCmdByAdmin extends CreateVolumeCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateVolumeCmdByAdmin.class.getName());
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
CallContext.current().setEventDetails("Volume Id: "+getEntityId()+((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
|
||||
Volume volume = _volumeService.createVolume(this);
|
||||
if (volume != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
|
||||
//FIXME - have to be moved to ApiResponseHelper
|
||||
if (getSnapshotId() != null) {
|
||||
Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
|
||||
if (snap != null) {
|
||||
response.setSnapshotId(snap.getUuid()); // if the volume was
|
||||
// created from a
|
||||
// snapshot,
|
||||
// snapshotId will
|
||||
// be set so we pass
|
||||
// it back in the
|
||||
// response
|
||||
}
|
||||
}
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "detachVolume", description = "Detaches a disk volume from a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Full)
|
||||
public class DetachVolumeCmdByAdmin extends DetachVolumeCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(DetachVolumeCmdByAdmin.class.getName());
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId()+" VmId: "+getVirtualMachineId());
|
||||
Volume result = _volumeService.detachVolumeFromVM(this);
|
||||
if (result != null){
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
|
||||
response.setResponseName("volume");
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
|
||||
import org.apache.cloudstack.api.response.PodResponse;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
|
||||
|
||||
|
||||
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Full)
|
||||
public class ListVolumesCmdByAdmin extends ListVolumesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListVolumesCmdByAdmin.class.getName());
|
||||
|
||||
@Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class,
|
||||
description="the pod id the disk volume belongs to")
|
||||
private Long podId;
|
||||
|
||||
|
||||
@Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.UUID, entityType=StoragePoolResponse.class,
|
||||
description="the ID of the storage pool, available to ROOT admin only", since="4.3", authorized = { RoleType.Admin })
|
||||
private Long storageId;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Override
|
||||
public Long getPodId() {
|
||||
return podId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long getStorageId() {
|
||||
return storageId;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
|
||||
@APICommand(name = "migrateVolume", description = "Migrate volume", responseObject = VolumeResponse.class, since = "3.0.0", responseView = ResponseView.Full)
|
||||
public class MigrateVolumeCmdByAdmin extends MigrateVolumeCmd {
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
Volume result;
|
||||
|
||||
result = _volumeService.migrateVolume(this);
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
|
||||
@APICommand(name = "resizeVolume", description = "Resizes a volume", responseObject = VolumeResponse.class, responseView = ResponseView.Full)
|
||||
public class ResizeVolumeCmdByAdmin extends ResizeVolumeCmd {
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceAllocationException{
|
||||
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G");
|
||||
Volume volume = _volumeService.resizeVolume(this);
|
||||
if (volume != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
|
||||
//FIXME - have to be moved to ApiResponseHelper
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.UpdateVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class, responseView = ResponseView.Full)
|
||||
public class UpdateVolumeCmdByAdmin extends UpdateVolumeCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId());
|
||||
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume());
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
// 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.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.NetworkRuleConflictException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "uploadVolume", description = "Uploads a data disk.", responseObject = VolumeResponse.class, responseView = ResponseView.Full)
|
||||
public class UploadVolumeCmdByAdmin extends UploadVolumeCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UploadVolumeCmdByAdmin.class.getName());
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException,
|
||||
InsufficientCapacityException, ServerApiException,
|
||||
ConcurrentOperationException, ResourceAllocationException,
|
||||
NetworkRuleConflictException {
|
||||
|
||||
Volume volume = _volumeService.uploadVolume(this);
|
||||
if (volume != null){
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload volume");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -16,24 +16,25 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@APICommand(name = "attachVolume", description="Attaches a disk volume to a virtual machine.", responseObject=VolumeResponse.class)
|
||||
@APICommand(name = "attachVolume", description = "Attaches a disk volume to a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted)
|
||||
public class AttachVolumeCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AttachVolumeCmd.class.getName());
|
||||
private static final String s_name = "attachvolumeresponse";
|
||||
@ -90,10 +91,12 @@ public class AttachVolumeCmd extends BaseAsyncCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.Volume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstanceId() {
|
||||
return getId();
|
||||
}
|
||||
@ -122,9 +125,9 @@ public class AttachVolumeCmd extends BaseAsyncCmd {
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId()+" VmId: "+getVirtualMachineId());
|
||||
Volume result = _volumeService.attachVolumeToVM(this);
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume");
|
||||
}
|
||||
|
||||
@ -16,12 +16,15 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
@ -31,14 +34,12 @@ import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "createVolume", responseObject=VolumeResponse.class, description="Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.")
|
||||
@APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Restricted)
|
||||
public class CreateVolumeCmd extends BaseAsyncCreateCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(CreateVolumeCmd.class.getName());
|
||||
private static final String s_name = "createvolumeresponse";
|
||||
@ -175,10 +176,10 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException{
|
||||
|
||||
Volume volume = this._volumeService.allocVolume(this);
|
||||
Volume volume = _volumeService.allocVolume(this);
|
||||
if (volume != null) {
|
||||
this.setEntityId(volume.getId());
|
||||
this.setEntityUuid(volume.getUuid());
|
||||
setEntityId(volume.getId());
|
||||
setEntityUuid(volume.getUuid());
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create volume");
|
||||
}
|
||||
@ -189,7 +190,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
|
||||
CallContext.current().setEventDetails("Volume Id: "+getEntityId()+((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
|
||||
Volume volume = _volumeService.createVolume(this);
|
||||
if (volume != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
|
||||
//FIXME - have to be moved to ApiResponseHelper
|
||||
if (getSnapshotId() != null) {
|
||||
Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
|
||||
@ -204,7 +205,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
|
||||
}
|
||||
}
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
|
||||
}
|
||||
|
||||
@ -16,25 +16,26 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
||||
@APICommand(name = "detachVolume", description="Detaches a disk volume from a virtual machine.", responseObject=VolumeResponse.class)
|
||||
@APICommand(name = "detachVolume", description = "Detaches a disk volume from a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted)
|
||||
public class DetachVolumeCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(DetachVolumeCmd.class.getName());
|
||||
private static final String s_name = "detachvolumeresponse";
|
||||
@ -83,10 +84,12 @@ public class DetachVolumeCmd extends BaseAsyncCmd {
|
||||
return "volume";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.Volume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstanceId() {
|
||||
return getId();
|
||||
}
|
||||
@ -133,9 +136,9 @@ public class DetachVolumeCmd extends BaseAsyncCmd {
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId()+" VmId: "+getVirtualMachineId());
|
||||
Volume result = _volumeService.detachVolumeFromVM(this);
|
||||
if (result != null){
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
|
||||
response.setResponseName("volume");
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach volume");
|
||||
}
|
||||
|
||||
@ -16,12 +16,15 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.PodResponse;
|
||||
@ -29,11 +32,10 @@ import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
@APICommand(name = "listVolumes", description="Lists all volumes.", responseObject=VolumeResponse.class)
|
||||
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted)
|
||||
public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName());
|
||||
|
||||
@ -129,6 +131,6 @@ public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
|
||||
public void execute(){
|
||||
ListResponse<VolumeResponse> response = _queryService.searchForVolumes(this);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,17 +21,17 @@ import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
|
||||
@APICommand(name = "migrateVolume", description="Migrate volume", responseObject=VolumeResponse.class, since="3.0.0")
|
||||
@APICommand(name = "migrateVolume", description = "Migrate volume", responseObject = VolumeResponse.class, since = "3.0.0", responseView = ResponseView.Restricted)
|
||||
public class MigrateVolumeCmd extends BaseAsyncCmd {
|
||||
private static final String s_name = "migratevolumeresponse";
|
||||
|
||||
@ -102,9 +102,9 @@ public class MigrateVolumeCmd extends BaseAsyncCmd {
|
||||
|
||||
result = _volumeService.migrateVolume(this);
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
|
||||
}
|
||||
|
||||
@ -16,19 +16,20 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.DiskOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
@ -38,7 +39,7 @@ import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
|
||||
@APICommand(name="resizeVolume", description="Resizes a volume", responseObject=VolumeResponse.class)
|
||||
@APICommand(name = "resizeVolume", description = "Resizes a volume", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted)
|
||||
public class ResizeVolumeCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ResizeVolumeCmd.class.getName());
|
||||
|
||||
@ -137,10 +138,10 @@ public class ResizeVolumeCmd extends BaseAsyncCmd {
|
||||
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G");
|
||||
Volume volume = _volumeService.resizeVolume(this);
|
||||
if (volume != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
|
||||
//FIXME - have to be moved to ApiResponseHelper
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
|
||||
}
|
||||
|
||||
@ -16,23 +16,25 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "updateVolume", description="Updates the volume.", responseObject=VolumeResponse.class)
|
||||
@APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted)
|
||||
public class UpdateVolumeCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateVolumeCmd.class.getName());
|
||||
private static final String s_name = "updatevolumeresponse";
|
||||
@ -90,10 +92,12 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiCommandJobType getInstanceType() {
|
||||
return ApiCommandJobType.Volume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getInstanceId() {
|
||||
return getId();
|
||||
}
|
||||
@ -117,7 +121,7 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
|
||||
StringBuilder desc = new StringBuilder("Updating volume: ");
|
||||
desc.append(getId()).append(" with");
|
||||
if (getPath() != null) {
|
||||
desc.append(" path " + getPath());
|
||||
desc.append(" path " + getPath());
|
||||
}
|
||||
if (getStorageId() != null) {
|
||||
desc.append(", storage id " + getStorageId());
|
||||
@ -134,9 +138,9 @@ public class UpdateVolumeCmd extends BaseAsyncCmd {
|
||||
CallContext.current().setEventDetails("Volume Id: "+getId());
|
||||
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume());
|
||||
if (result != null) {
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
|
||||
}
|
||||
|
||||
@ -16,21 +16,21 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.volume;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.ApiErrorCode;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.BaseCmd.CommandType;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
@ -39,7 +39,7 @@ import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
@APICommand(name = "uploadVolume", description="Uploads a data disk.", responseObject=VolumeResponse.class)
|
||||
@APICommand(name = "uploadVolume", description = "Uploads a data disk.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted)
|
||||
public class UploadVolumeCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(UploadVolumeCmd.class.getName());
|
||||
private static final String s_name = "uploadvolumeresponse";
|
||||
@ -77,7 +77,7 @@ public class UploadVolumeCmd extends BaseAsyncCmd {
|
||||
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
|
||||
description="Upload volume for the project")
|
||||
private Long projectId;
|
||||
private Long projectId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
@ -112,7 +112,7 @@ public class UploadVolumeCmd extends BaseAsyncCmd {
|
||||
}
|
||||
|
||||
public String getImageStoreUuid() {
|
||||
return this.imageStoreUuid;
|
||||
return imageStoreUuid;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -127,9 +127,9 @@ public class UploadVolumeCmd extends BaseAsyncCmd {
|
||||
|
||||
Volume volume = _volumeService.uploadVolume(this);
|
||||
if (volume != null){
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
|
||||
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload volume");
|
||||
}
|
||||
|
||||
@ -1560,13 +1560,13 @@ public class ApiDBUtils {
|
||||
return _hostJoinDao.newHostView(vr);
|
||||
}
|
||||
|
||||
public static VolumeResponse newVolumeResponse(VolumeJoinVO vr) {
|
||||
return _volJoinDao.newVolumeResponse(vr);
|
||||
public static VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO vr) {
|
||||
return _volJoinDao.newVolumeResponse(view, vr);
|
||||
}
|
||||
|
||||
|
||||
public static VolumeResponse fillVolumeDetails(VolumeResponse vrData, VolumeJoinVO vr){
|
||||
return _volJoinDao.setVolumeResponse(vrData, vr);
|
||||
public static VolumeResponse fillVolumeDetails(ResponseView view, VolumeResponse vrData, VolumeJoinVO vr) {
|
||||
return _volJoinDao.setVolumeResponse(view, vrData, vr);
|
||||
}
|
||||
|
||||
public static List<VolumeJoinVO> newVolumeView(Volume vr){
|
||||
|
||||
@ -920,9 +920,9 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeResponse createVolumeResponse(Volume volume) {
|
||||
public VolumeResponse createVolumeResponse(ResponseView view, Volume volume) {
|
||||
List<VolumeJoinVO> viewVrs = ApiDBUtils.newVolumeView(volume);
|
||||
List<VolumeResponse> listVrs = ViewResponseHelper.createVolumeResponse(viewVrs.toArray(new VolumeJoinVO[viewVrs.size()]));
|
||||
List<VolumeResponse> listVrs = ViewResponseHelper.createVolumeResponse(view, viewVrs.toArray(new VolumeJoinVO[viewVrs.size()]));
|
||||
assert listVrs != null && listVrs.size() == 1 : "There should be one volume returned";
|
||||
return listVrs.get(0);
|
||||
}
|
||||
|
||||
@ -51,6 +51,7 @@ import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStore
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
|
||||
import org.apache.cloudstack.api.command.admin.vm.ListVMsCmdByAdmin;
|
||||
import org.apache.cloudstack.api.command.admin.volume.ListVolumesCmdByAdmin;
|
||||
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
|
||||
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
|
||||
@ -1614,7 +1615,12 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
Pair<List<VolumeJoinVO>, Integer> result = searchForVolumesInternal(cmd);
|
||||
ListResponse<VolumeResponse> response = new ListResponse<VolumeResponse>();
|
||||
|
||||
List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(result.first().toArray(
|
||||
ResponseView respView = ResponseView.Restricted;
|
||||
if (cmd instanceof ListVolumesCmdByAdmin) {
|
||||
respView = ResponseView.Full;
|
||||
}
|
||||
|
||||
List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(respView, result.first().toArray(
|
||||
new VolumeJoinVO[result.first().size()]));
|
||||
response.setResponses(volumeResponses, result.second());
|
||||
return response;
|
||||
@ -1623,7 +1629,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
private Pair<List<VolumeJoinVO>, Integer> searchForVolumesInternal(ListVolumesCmd cmd) {
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
List<Long> permittedDomains = new ArrayList<Long>();
|
||||
List<Long> permittedAccounts = new ArrayList<Long>();
|
||||
List<Long> permittedResources = new ArrayList<Long>();
|
||||
|
||||
Long id = cmd.getId();
|
||||
Long vmInstanceId = cmd.getVirtualMachineId();
|
||||
@ -1631,20 +1639,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
String keyword = cmd.getKeyword();
|
||||
String type = cmd.getType();
|
||||
Map<String, String> tags = cmd.getTags();
|
||||
boolean isRootAdmin = _accountMgr.isRootAdmin(caller.getType());
|
||||
Long storageId = cmd.getStorageId();
|
||||
|
||||
Long zoneId = cmd.getZoneId();
|
||||
Long podId = null;
|
||||
if (_accountMgr.isAdmin(caller.getType())) {
|
||||
podId = cmd.getPodId();
|
||||
}
|
||||
Long podId = cmd.getPodId();
|
||||
|
||||
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(
|
||||
cmd.getDomainId(), cmd.isRecursive(), null);
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false);
|
||||
Long domainId = domainIdRecursiveListProject.first();
|
||||
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedDomains, permittedAccounts, permittedResources,
|
||||
domainIdRecursiveListProject, cmd.listAll(), false, "listVolumes");
|
||||
// Long domainId = domainIdRecursiveListProject.first();
|
||||
Boolean isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
Filter searchFilter = new Filter(VolumeJoinVO.class, "created", false, cmd.getStartIndex(),
|
||||
@ -1659,8 +1663,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
// number of
|
||||
// records with
|
||||
// pagination
|
||||
_accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
|
||||
|
||||
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
|
||||
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||
@ -1675,7 +1678,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
// display UserVM volumes only
|
||||
sb.and().op("type", sb.entity().getVmType(), SearchCriteria.Op.NIN);
|
||||
sb.or("nulltype", sb.entity().getVmType(), SearchCriteria.Op.NULL);
|
||||
if(!isRootAdmin){
|
||||
if (!(cmd instanceof ListVolumesCmdByAdmin)) {
|
||||
sb.and("displayVolume", sb.entity().isDisplayVolume(), SearchCriteria.Op.EQ);
|
||||
}
|
||||
sb.cp();
|
||||
@ -1683,8 +1686,10 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
|
||||
// now set the SC criteria...
|
||||
SearchCriteria<VolumeJoinVO> sc = sb.create();
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts,
|
||||
listProjectResourcesCriteria);
|
||||
SearchCriteria<VolumeJoinVO> aclSc = _volumeJoinDao.createSearchCriteria();
|
||||
|
||||
// building ACL search criteria
|
||||
_accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria);
|
||||
|
||||
if (keyword != null) {
|
||||
SearchCriteria<VolumeJoinVO> ssc = _volumeJoinDao.createSearchCriteria();
|
||||
@ -1732,7 +1737,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
|
||||
sc.setParameters("storageId", storageId);
|
||||
}
|
||||
|
||||
if(!isRootAdmin){
|
||||
if (!(cmd instanceof ListVolumesCmdByAdmin)) {
|
||||
sc.setParameters("displayVolume", 1);
|
||||
}
|
||||
|
||||
|
||||
@ -266,17 +266,17 @@ public class ViewResponseHelper {
|
||||
return new ArrayList<HostForMigrationResponse>(vrDataList.values());
|
||||
}
|
||||
|
||||
public static List<VolumeResponse> createVolumeResponse(VolumeJoinVO... volumes) {
|
||||
public static List<VolumeResponse> createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) {
|
||||
Hashtable<Long, VolumeResponse> vrDataList = new Hashtable<Long, VolumeResponse>();
|
||||
for (VolumeJoinVO vr : volumes) {
|
||||
VolumeResponse vrData = vrDataList.get(vr.getId());
|
||||
if ( vrData == null ){
|
||||
// first time encountering this volume
|
||||
vrData = ApiDBUtils.newVolumeResponse(vr);
|
||||
vrData = ApiDBUtils.newVolumeResponse(view, vr);
|
||||
}
|
||||
else{
|
||||
// update tags
|
||||
vrData = ApiDBUtils.fillVolumeDetails(vrData, vr);
|
||||
vrData = ApiDBUtils.fillVolumeDetails(view, vrData, vr);
|
||||
}
|
||||
vrDataList.put(vr.getId(), vrData);
|
||||
}
|
||||
|
||||
@ -18,18 +18,18 @@ package com.cloud.api.query.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
|
||||
|
||||
import com.cloud.api.query.vo.VolumeJoinVO;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface VolumeJoinDao extends GenericDao<VolumeJoinVO, Long> {
|
||||
|
||||
VolumeResponse newVolumeResponse(VolumeJoinVO vol);
|
||||
VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO vol);
|
||||
|
||||
VolumeResponse setVolumeResponse(VolumeResponse volData, VolumeJoinVO vol);
|
||||
VolumeResponse setVolumeResponse(ResponseView view, VolumeResponse volData, VolumeJoinVO vol);
|
||||
|
||||
List<VolumeJoinVO> newVolumeView(Volume vol);
|
||||
|
||||
|
||||
@ -22,13 +22,14 @@ import java.util.List;
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.query.vo.ResourceTagJoinVO;
|
||||
@ -40,7 +41,6 @@ import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
@ -70,14 +70,14 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
|
||||
volIdSearch.and("id", volIdSearch.entity().getId(), SearchCriteria.Op.EQ);
|
||||
volIdSearch.done();
|
||||
|
||||
this._count = "select count(distinct id) from volume_view WHERE ";
|
||||
_count = "select count(distinct id) from volume_view WHERE ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeResponse newVolumeResponse(VolumeJoinVO volume) {
|
||||
public VolumeResponse newVolumeResponse(ResponseView view, VolumeJoinVO volume) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
|
||||
VolumeResponse volResponse = new VolumeResponse();
|
||||
@ -118,9 +118,11 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
|
||||
volResponse.setSize(volume.getVolumeStoreSize());
|
||||
volResponse.setCreated(volume.getCreatedOnStore());
|
||||
|
||||
if (_accountMgr.isRootAdmin(caller.getId())
|
||||
|| caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)
|
||||
// if (_accountMgr.isRootAdmin(caller.getId())
|
||||
// || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)
|
||||
if (view == ResponseView.Full) {
|
||||
volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getFormat()).toString());
|
||||
}
|
||||
if (volume.getDownloadState() != Status.DOWNLOADED) {
|
||||
String volumeStatus = "Processing";
|
||||
if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
|
||||
@ -147,7 +149,8 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
|
||||
}
|
||||
}
|
||||
|
||||
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN){
|
||||
// if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN){
|
||||
if (view == ResponseView.Full) {
|
||||
volResponse.setPath(volume.getPath());
|
||||
}
|
||||
|
||||
@ -180,7 +183,8 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
|
||||
}
|
||||
|
||||
// return hypervisor and storage pool info for ROOT and Resource domain only
|
||||
if (_accountMgr.isRootAdmin(caller.getId()) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
// if (_accountMgr.isRootAdmin(caller.getId()) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
if (view == ResponseView.Full) {
|
||||
if (volume.getState() != Volume.State.UploadOp && volume.getHypervisorType() != null) {
|
||||
volResponse.setHypervisor(volume.getHypervisorType().toString());
|
||||
}
|
||||
@ -229,7 +233,7 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeResponse setVolumeResponse(VolumeResponse volData, VolumeJoinVO vol) {
|
||||
public VolumeResponse setVolumeResponse(ResponseView view, VolumeResponse volData, VolumeJoinVO vol) {
|
||||
long tag_id = vol.getTagId();
|
||||
if (tag_id > 0) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user