diff --git a/api/src/com/cloud/storage/VolumeApiService.java b/api/src/com/cloud/storage/VolumeApiService.java index 4806ae7c06f..351e2bf0611 100644 --- a/api/src/com/cloud/storage/VolumeApiService.java +++ b/api/src/com/cloud/storage/VolumeApiService.java @@ -67,7 +67,7 @@ public interface VolumeApiService { /** * Uploads the volume to secondary storage * - * @param UploadVolumeCmd cmd + * @param UploadVolumeCmdByAdmin cmd * * @return Volume object */ diff --git a/api/src/org/apache/cloudstack/acl/AclEntityType.java b/api/src/org/apache/cloudstack/acl/AclEntityType.java index 1ce3a70dd8f..109c7dcf981 100644 --- a/api/src/org/apache/cloudstack/acl/AclEntityType.java +++ b/api/src/org/apache/cloudstack/acl/AclEntityType.java @@ -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; } diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java index aeb752142b9..f70f6caaf22 100644 --- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java +++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java @@ -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); diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java new file mode 100644 index 00000000000..3634a976c63 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/AttachVolumeCmdByAdmin.java @@ -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"); + } + } +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java new file mode 100644 index 00000000000..5df7481497c --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java @@ -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"); + } + } +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java new file mode 100644 index 00000000000..ab07a786639 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/DetachVolumeCmdByAdmin.java @@ -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"); + } + } +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java new file mode 100644 index 00000000000..a8741fde2b3 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java @@ -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; + } + +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java new file mode 100644 index 00000000000..c58a23384d4 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/MigrateVolumeCmdByAdmin.java @@ -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"); + } + } + +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java new file mode 100644 index 00000000000..21bbdbbc6bf --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/ResizeVolumeCmdByAdmin.java @@ -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"); + } + } +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java new file mode 100644 index 00000000000..f1afc3f5df4 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/UpdateVolumeCmdByAdmin.java @@ -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"); + } + } +} diff --git a/api/src/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java b/api/src/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java new file mode 100644 index 00000000000..e3e0c9b8ade --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/admin/volume/UploadVolumeCmdByAdmin.java @@ -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"); + } + } + + +} diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java index baec44f2d77..eb864badf41 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java @@ -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"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java index e5c7a51b8d2..cd8232e419b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java @@ -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"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java index f2fe0cd7e75..fc68fe13f5b 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java @@ -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"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java index f6bdb3cd855..900cd7554d9 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java @@ -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 response = _queryService.searchForVolumes(this); response.setResponseName(getCommandName()); - this.setResponseObject(response); + setResponseObject(response); } } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java index 61863976930..de5a5559446 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/MigrateVolumeCmd.java @@ -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"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java index 811440d9b84..85bf4332be1 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java @@ -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"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java index d4e3a6c1643..859ad8a8459 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java @@ -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"); } diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java index f9104f7afb4..11eab5f8c17 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java @@ -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"); } diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index c0cb10478f4..3ae7142c571 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -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 newVolumeView(Volume vr){ diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 68514733903..16f3c65ecd4 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -920,9 +920,9 @@ public class ApiResponseHelper implements ResponseGenerator { } @Override - public VolumeResponse createVolumeResponse(Volume volume) { + public VolumeResponse createVolumeResponse(ResponseView view, Volume volume) { List viewVrs = ApiDBUtils.newVolumeView(volume); - List listVrs = ViewResponseHelper.createVolumeResponse(viewVrs.toArray(new VolumeJoinVO[viewVrs.size()])); + List 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); } diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index 37f46325ec8..d436453d2bf 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -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, Integer> result = searchForVolumesInternal(cmd); ListResponse response = new ListResponse(); - List volumeResponses = ViewResponseHelper.createVolumeResponse(result.first().toArray( + ResponseView respView = ResponseView.Restricted; + if (cmd instanceof ListVolumesCmdByAdmin) { + respView = ResponseView.Full; + } + + List 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, Integer> searchForVolumesInternal(ListVolumesCmd cmd) { Account caller = CallContext.current().getCallingAccount(); + List permittedDomains = new ArrayList(); List permittedAccounts = new ArrayList(); + List permittedResources = new ArrayList(); 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 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 domainIdRecursiveListProject = new Ternary( 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 sc = sb.create(); - _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, - listProjectResourcesCriteria); + SearchCriteria aclSc = _volumeJoinDao.createSearchCriteria(); + + // building ACL search criteria + _accountMgr.buildACLViewSearchCriteria(sc, aclSc, isRecursive, permittedDomains, permittedAccounts, permittedResources, listProjectResourcesCriteria); if (keyword != null) { SearchCriteria 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); } diff --git a/server/src/com/cloud/api/query/ViewResponseHelper.java b/server/src/com/cloud/api/query/ViewResponseHelper.java index 0cf8e169c95..7f5168c04c7 100644 --- a/server/src/com/cloud/api/query/ViewResponseHelper.java +++ b/server/src/com/cloud/api/query/ViewResponseHelper.java @@ -266,17 +266,17 @@ public class ViewResponseHelper { return new ArrayList(vrDataList.values()); } - public static List createVolumeResponse(VolumeJoinVO... volumes) { + public static List createVolumeResponse(ResponseView view, VolumeJoinVO... volumes) { Hashtable vrDataList = new Hashtable(); 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); } diff --git a/server/src/com/cloud/api/query/dao/VolumeJoinDao.java b/server/src/com/cloud/api/query/dao/VolumeJoinDao.java index 67509cf5b29..ebcf0bca391 100644 --- a/server/src/com/cloud/api/query/dao/VolumeJoinDao.java +++ b/server/src/com/cloud/api/query/dao/VolumeJoinDao.java @@ -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 { - 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 newVolumeView(Volume vol); diff --git a/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java index fdee69006c6..dfcf0282c8a 100644 --- a/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java +++ b/server/src/com/cloud/api/query/dao/VolumeJoinDaoImpl.java @@ -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 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 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 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 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 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);