Skip to content

Commit a129fe4

Browse files
committed
add missing files
1 parent 180cfa1 commit a129fe4

6 files changed

Lines changed: 309 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.api.command.user.snapshot;
20+
21+
import com.cloud.event.EventTypes;
22+
import com.cloud.storage.Snapshot;
23+
import com.cloud.user.Account;
24+
import org.apache.cloudstack.api.APICommand;
25+
import org.apache.cloudstack.api.ApiCommandJobType;
26+
import org.apache.cloudstack.api.ApiConstants;
27+
import org.apache.cloudstack.api.ApiErrorCode;
28+
import org.apache.cloudstack.api.BaseAsyncCmd;
29+
import org.apache.cloudstack.api.BaseCmd;
30+
import org.apache.cloudstack.api.Parameter;
31+
import org.apache.cloudstack.api.ServerApiException;
32+
import org.apache.cloudstack.api.response.SnapshotResponse;
33+
import org.apache.cloudstack.api.response.SuccessResponse;
34+
import org.apache.cloudstack.context.CallContext;
35+
36+
@APICommand(name = "RevertSnapshot", description = "revert a volume snapshot.", responseObject = SnapshotResponse.class)
37+
public class RevertSnapshotCmd extends BaseAsyncCmd {
38+
private static final String s_name = "revertsnapshotresponse";
39+
@Parameter(name= ApiConstants.ID, type= BaseCmd.CommandType.UUID, entityType = SnapshotResponse.class,
40+
required=true, description="The ID of the snapshot")
41+
private Long id;
42+
43+
public Long getId() {
44+
return id;
45+
}
46+
47+
48+
@Override
49+
public String getCommandName() {
50+
return s_name;
51+
}
52+
53+
@Override
54+
public long getEntityOwnerId() {
55+
Snapshot snapshot = _entityMgr.findById(Snapshot.class, getId());
56+
if (snapshot != null) {
57+
return snapshot.getAccountId();
58+
}
59+
60+
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
61+
}
62+
63+
@Override
64+
public String getEventType() {
65+
return EventTypes.EVENT_SNAPSHOT_REVERT;
66+
}
67+
68+
@Override
69+
public String getEventDescription() {
70+
return "revert snapshot: " + getId();
71+
}
72+
73+
public ApiCommandJobType getInstanceType() {
74+
return ApiCommandJobType.Snapshot;
75+
}
76+
77+
public Long getInstanceId() {
78+
return getId();
79+
}
80+
81+
@Override
82+
public void execute(){
83+
CallContext.current().setEventDetails("Snapshot Id: "+getId());
84+
boolean result = _snapshotService.revertSnapshot(getId());
85+
if (result) {
86+
SuccessResponse response = new SuccessResponse(getCommandName());
87+
response.setResponseName(getCommandName());
88+
this.setResponseObject(response);
89+
} else {
90+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revert snapshot");
91+
}
92+
}
93+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.command;
20+
21+
import com.cloud.agent.api.Command;
22+
import com.cloud.agent.api.to.DataTO;
23+
24+
public class ForgetObjectCmd extends Command implements StorageSubSystemCommand {
25+
private DataTO dataTO;
26+
public ForgetObjectCmd(DataTO data) {
27+
this.dataTO = data;
28+
}
29+
30+
public DataTO getDataTO() {
31+
return this.dataTO;
32+
}
33+
@Override
34+
public boolean executeInSequence() {
35+
return false;
36+
}
37+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.command;
20+
21+
import com.cloud.agent.api.Answer;
22+
import com.cloud.agent.api.to.DataTO;
23+
24+
public class IntroduceObjectAnswer extends Answer {
25+
private DataTO dataTO;
26+
public IntroduceObjectAnswer(DataTO dataTO) {
27+
this.dataTO = dataTO;
28+
}
29+
30+
public DataTO getDataTO() {
31+
return this.dataTO;
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.command;
20+
21+
import com.cloud.agent.api.Command;
22+
import com.cloud.agent.api.to.DataTO;
23+
24+
public class IntroduceObjectCmd extends Command implements StorageSubSystemCommand {
25+
private DataTO dataTO;
26+
public IntroduceObjectCmd(DataTO dataTO) {
27+
this.dataTO = dataTO;
28+
}
29+
30+
public DataTO getDataTO() {
31+
return this.dataTO;
32+
}
33+
34+
@Override
35+
public boolean executeInSequence() {
36+
return false;
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.helper;
20+
21+
import com.cloud.agent.api.to.DataTO;
22+
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
23+
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
24+
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
25+
26+
public interface HypervisorHelper {
27+
DataTO introduceObject(DataTO object, Scope scope, Long storeId);
28+
boolean forgetObject(DataTO object, Scope scope, Long storeId);
29+
SnapshotObjectTO takeSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope);
30+
boolean revertSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope);
31+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.storage.helper;
20+
21+
import com.cloud.agent.api.Answer;
22+
import com.cloud.agent.api.to.DataTO;
23+
import com.cloud.utils.exception.CloudRuntimeException;
24+
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
25+
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
26+
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
27+
import org.apache.cloudstack.storage.command.ForgetObjectCmd;
28+
import org.apache.cloudstack.storage.command.IntroduceObjectAnswer;
29+
import org.apache.cloudstack.storage.command.IntroduceObjectCmd;
30+
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
31+
import org.apache.log4j.Logger;
32+
33+
import javax.inject.Inject;
34+
35+
public class HypervisorHelperImpl implements HypervisorHelper {
36+
private static final Logger s_logger = Logger.getLogger(HypervisorHelperImpl.class);
37+
@Inject
38+
EndPointSelector selector;
39+
40+
@Override
41+
public DataTO introduceObject(DataTO object, Scope scope, Long storeId) {
42+
EndPoint ep = selector.select(scope, storeId);
43+
IntroduceObjectCmd cmd = new IntroduceObjectCmd(object);
44+
Answer answer = ep.sendMessage(cmd);
45+
if (answer == null || !answer.getResult()) {
46+
String errMsg = answer == null ? null : answer.getDetails();
47+
throw new CloudRuntimeException("Failed to introduce object, due to " + errMsg);
48+
}
49+
IntroduceObjectAnswer introduceObjectAnswer = (IntroduceObjectAnswer)answer;
50+
return introduceObjectAnswer.getDataTO();
51+
}
52+
53+
@Override
54+
public boolean forgetObject(DataTO object, Scope scope, Long storeId) {
55+
EndPoint ep = selector.select(scope, storeId);
56+
ForgetObjectCmd cmd = new ForgetObjectCmd(object);
57+
Answer answer = ep.sendMessage(cmd);
58+
if (answer == null || !answer.getResult()) {
59+
String errMsg = answer == null ? null : answer.getDetails();
60+
if (errMsg != null) {
61+
s_logger.debug("Failed to forget object: " + errMsg);
62+
}
63+
return false;
64+
}
65+
return true;
66+
}
67+
68+
@Override
69+
public SnapshotObjectTO takeSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope) {
70+
return null; //To change body of implemented methods use File | Settings | File Templates.
71+
}
72+
73+
@Override
74+
public boolean revertSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope) {
75+
return false; //To change body of implemented methods use File | Settings | File Templates.
76+
}
77+
}

0 commit comments

Comments
 (0)