mirror of https://github.com/apache/cloudstack.git
fix snapshot delete
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
b97f70c116
commit
047595d938
|
|
@ -87,6 +87,7 @@ import org.apache.cloudstack.veeam.api.dto.Job;
|
|||
import org.apache.cloudstack.veeam.api.dto.Network;
|
||||
import org.apache.cloudstack.veeam.api.dto.Nic;
|
||||
import org.apache.cloudstack.veeam.api.dto.Ref;
|
||||
import org.apache.cloudstack.veeam.api.dto.ResourceAction;
|
||||
import org.apache.cloudstack.veeam.api.dto.Snapshot;
|
||||
import org.apache.cloudstack.veeam.api.dto.StorageDomain;
|
||||
import org.apache.cloudstack.veeam.api.dto.Vm;
|
||||
|
|
@ -950,8 +951,8 @@ public class ServerAdapter extends ManagerBase {
|
|||
return VmSnapshotVOToSnapshotConverter.toSnapshot(vo, vm.getUuid());
|
||||
}
|
||||
|
||||
public Snapshot deleteSnapshot(String uuid, boolean async) {
|
||||
Snapshot snapshot = null;
|
||||
public ResourceAction deleteSnapshot(String uuid, boolean async) {
|
||||
ResourceAction action = null;
|
||||
VMSnapshotVO vo = vmSnapshotDao.findByUuid(uuid);
|
||||
if (vo == null) {
|
||||
throw new InvalidParameterValueException("Snapshot with ID " + uuid + " not found");
|
||||
|
|
@ -963,15 +964,15 @@ public class ServerAdapter extends ManagerBase {
|
|||
DeleteVMSnapshotCmd cmd = new DeleteVMSnapshotCmd();
|
||||
ComponentContext.inject(cmd);
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(ApiConstants.ID, vo.getUuid());
|
||||
apiServerService.processAsyncCmd(cmd, params, ctx, serviceUserAccount.first().getId(),
|
||||
serviceUserAccount.second());
|
||||
vo = vmSnapshotDao.findById(vo.getId());
|
||||
if (vo == null) {
|
||||
throw new CloudRuntimeException("Snapshot not found");
|
||||
params.put(ApiConstants.VM_SNAPSHOT_ID, vo.getUuid());
|
||||
ApiServerService.AsyncCmdResult result =
|
||||
apiServerService.processAsyncCmd(cmd, params, ctx, serviceUserAccount.first().getId(),
|
||||
serviceUserAccount.second());
|
||||
AsyncJobJoinVO jobVo = asyncJobJoinDao.findById(result.jobId);
|
||||
if (jobVo == null) {
|
||||
throw new CloudRuntimeException("Failed to find job for snapshot deletion");
|
||||
}
|
||||
UserVmVO vm = userVmDao.findById(vo.getVmId());
|
||||
snapshot = VmSnapshotVOToSnapshotConverter.toSnapshot(vo, vm.getUuid());
|
||||
action = AsyncJobJoinVOToJobConverter.toAction(jobVo);
|
||||
} else {
|
||||
vmSnapshotService.deleteVMSnapshot(vo.getId());
|
||||
}
|
||||
|
|
@ -980,6 +981,6 @@ public class ServerAdapter extends ManagerBase {
|
|||
} finally {
|
||||
CallContext.unregister();
|
||||
}
|
||||
return snapshot;
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import org.apache.cloudstack.veeam.api.dto.DiskAttachment;
|
|||
import org.apache.cloudstack.veeam.api.dto.DiskAttachments;
|
||||
import org.apache.cloudstack.veeam.api.dto.Nic;
|
||||
import org.apache.cloudstack.veeam.api.dto.Nics;
|
||||
import org.apache.cloudstack.veeam.api.dto.ResourceAction;
|
||||
import org.apache.cloudstack.veeam.api.dto.Snapshot;
|
||||
import org.apache.cloudstack.veeam.api.dto.Snapshots;
|
||||
import org.apache.cloudstack.veeam.api.dto.Vm;
|
||||
|
|
@ -417,13 +418,14 @@ public class VmsRouteHandler extends ManagerBase implements RouteHandler {
|
|||
protected void handleDeleteSnapshotById(final String id, final HttpServletRequest req,
|
||||
final HttpServletResponse resp, final Negotiation.OutFormat outFormat, final VeeamControlServlet io)
|
||||
throws IOException {
|
||||
boolean async = Boolean.parseBoolean(req.getParameter("async"));
|
||||
String asyncStr = req.getParameter("async");
|
||||
boolean async = !Boolean.FALSE.toString().equals(asyncStr);
|
||||
try {
|
||||
Snapshot snapshot = serverAdapter.deleteSnapshot(id, async);
|
||||
if (snapshot != null) {
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_ACCEPTED, null, outFormat);
|
||||
ResourceAction action = serverAdapter.deleteSnapshot(id, async);
|
||||
if (action != null) {
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_ACCEPTED, action, outFormat);
|
||||
} else {
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_ACCEPTED, null, outFormat);
|
||||
io.getWriter().write(resp, HttpServletResponse.SC_OK, null, outFormat);
|
||||
}
|
||||
} catch (CloudRuntimeException e) {
|
||||
io.badRequest(resp, e.getMessage(), outFormat);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.apache.cloudstack.veeam.api.JobsRouteHandler;
|
|||
import org.apache.cloudstack.veeam.api.dto.Actions;
|
||||
import org.apache.cloudstack.veeam.api.dto.Job;
|
||||
import org.apache.cloudstack.veeam.api.dto.Ref;
|
||||
import org.apache.cloudstack.veeam.api.dto.ResourceAction;
|
||||
import org.apache.cloudstack.veeam.api.dto.VmAction;
|
||||
|
||||
import com.cloud.api.query.vo.AsyncJobJoinVO;
|
||||
|
|
@ -80,12 +81,22 @@ public class AsyncJobJoinVOToJobConverter {
|
|||
return job;
|
||||
}
|
||||
|
||||
public static VmAction toVmAction(final AsyncJobJoinVO vo, final UserVmJoinVO vm) {
|
||||
VmAction action = new VmAction();
|
||||
protected static void fillAction(final ResourceAction action, final AsyncJobJoinVO vo) {
|
||||
final String basePath = VeeamControlService.ContextPath.value();
|
||||
action.setVm(UserVmJoinVOToVmConverter.toVm(vm, null, null, null));
|
||||
action.setJob(Ref.of(basePath + JobsRouteHandler.BASE_ROUTE + vo.getUuid(), vo.getUuid()));
|
||||
action.setStatus("complete");
|
||||
}
|
||||
|
||||
public static VmAction toVmAction(final AsyncJobJoinVO vo, final UserVmJoinVO vm) {
|
||||
VmAction action = new VmAction();
|
||||
fillAction(action, vo);
|
||||
action.setVm(UserVmJoinVOToVmConverter.toVm(vm, null, null, null));
|
||||
return action;
|
||||
}
|
||||
|
||||
public static ResourceAction toAction(final AsyncJobJoinVO vo) {
|
||||
VmAction action = new VmAction();
|
||||
fillAction(action, vo);
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
// 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.veeam.api.dto;
|
||||
|
||||
public class ResourceAction extends BaseDto {
|
||||
private Ref job;
|
||||
private String status;
|
||||
|
||||
public Ref getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
public void setJob(Ref job) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,21 +17,8 @@
|
|||
|
||||
package org.apache.cloudstack.veeam.api.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class VmAction {
|
||||
private Ref job;
|
||||
public class VmAction extends ResourceAction {
|
||||
private Vm vm;
|
||||
private String status;
|
||||
|
||||
public Ref getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
public void setJob(Ref job) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public Vm getVm() {
|
||||
return vm;
|
||||
|
|
@ -40,12 +27,4 @@ public class VmAction {
|
|||
public void setVm(Vm vm) {
|
||||
this.vm = vm;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue