You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/10/07 20:30:37 UTC
[12/27] git commit: updated refs/heads/ui-restyle to 205f22b
add missing files
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a129fe4e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a129fe4e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a129fe4e
Branch: refs/heads/ui-restyle
Commit: a129fe4e66202486145b1a61cc64e8573f59980c
Parents: 180cfa1
Author: Edison Su <su...@gmail.com>
Authored: Fri Oct 4 14:17:49 2013 -0700
Committer: Edison Su <su...@gmail.com>
Committed: Fri Oct 4 14:17:49 2013 -0700
----------------------------------------------------------------------
.../user/snapshot/RevertSnapshotCmd.java | 93 ++++++++++++++++++++
.../storage/command/ForgetObjectCmd.java | 37 ++++++++
.../storage/command/IntroduceObjectAnswer.java | 33 +++++++
.../storage/command/IntroduceObjectCmd.java | 38 ++++++++
.../storage/helper/HypervisorHelper.java | 31 +++++++
.../storage/helper/HypervisorHelperImpl.java | 77 ++++++++++++++++
6 files changed, 309 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a129fe4e/api/src/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java
new file mode 100644
index 0000000..946eebd
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java
@@ -0,0 +1,93 @@
+/*
+ * 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.user.snapshot;
+
+import com.cloud.event.EventTypes;
+import com.cloud.storage.Snapshot;
+import com.cloud.user.Account;
+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.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SnapshotResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+
+@APICommand(name = "RevertSnapshot", description = "revert a volume snapshot.", responseObject = SnapshotResponse.class)
+public class RevertSnapshotCmd extends BaseAsyncCmd {
+ private static final String s_name = "revertsnapshotresponse";
+ @Parameter(name= ApiConstants.ID, type= BaseCmd.CommandType.UUID, entityType = SnapshotResponse.class,
+ required=true, description="The ID of the snapshot")
+ private Long id;
+
+ public Long getId() {
+ return id;
+ }
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Snapshot snapshot = _entityMgr.findById(Snapshot.class, getId());
+ if (snapshot != null) {
+ return snapshot.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_SNAPSHOT_REVERT;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "revert snapshot: " + getId();
+ }
+
+ public ApiCommandJobType getInstanceType() {
+ return ApiCommandJobType.Snapshot;
+ }
+
+ public Long getInstanceId() {
+ return getId();
+ }
+
+ @Override
+ public void execute(){
+ CallContext.current().setEventDetails("Snapshot Id: "+getId());
+ boolean result = _snapshotService.revertSnapshot(getId());
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revert snapshot");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a129fe4e/core/src/org/apache/cloudstack/storage/command/ForgetObjectCmd.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/ForgetObjectCmd.java b/core/src/org/apache/cloudstack/storage/command/ForgetObjectCmd.java
new file mode 100644
index 0000000..58fb780
--- /dev/null
+++ b/core/src/org/apache/cloudstack/storage/command/ForgetObjectCmd.java
@@ -0,0 +1,37 @@
+/*
+ * 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.storage.command;
+
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.to.DataTO;
+
+public class ForgetObjectCmd extends Command implements StorageSubSystemCommand {
+ private DataTO dataTO;
+ public ForgetObjectCmd(DataTO data) {
+ this.dataTO = data;
+ }
+
+ public DataTO getDataTO() {
+ return this.dataTO;
+ }
+ @Override
+ public boolean executeInSequence() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a129fe4e/core/src/org/apache/cloudstack/storage/command/IntroduceObjectAnswer.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/IntroduceObjectAnswer.java b/core/src/org/apache/cloudstack/storage/command/IntroduceObjectAnswer.java
new file mode 100644
index 0000000..03c74b8
--- /dev/null
+++ b/core/src/org/apache/cloudstack/storage/command/IntroduceObjectAnswer.java
@@ -0,0 +1,33 @@
+/*
+ * 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.storage.command;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.to.DataTO;
+
+public class IntroduceObjectAnswer extends Answer {
+ private DataTO dataTO;
+ public IntroduceObjectAnswer(DataTO dataTO) {
+ this.dataTO = dataTO;
+ }
+
+ public DataTO getDataTO() {
+ return this.dataTO;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a129fe4e/core/src/org/apache/cloudstack/storage/command/IntroduceObjectCmd.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/IntroduceObjectCmd.java b/core/src/org/apache/cloudstack/storage/command/IntroduceObjectCmd.java
new file mode 100644
index 0000000..1aabed2
--- /dev/null
+++ b/core/src/org/apache/cloudstack/storage/command/IntroduceObjectCmd.java
@@ -0,0 +1,38 @@
+/*
+ * 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.storage.command;
+
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.to.DataTO;
+
+public class IntroduceObjectCmd extends Command implements StorageSubSystemCommand {
+ private DataTO dataTO;
+ public IntroduceObjectCmd(DataTO dataTO) {
+ this.dataTO = dataTO;
+ }
+
+ public DataTO getDataTO() {
+ return this.dataTO;
+ }
+
+ @Override
+ public boolean executeInSequence() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a129fe4e/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelper.java b/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelper.java
new file mode 100644
index 0000000..40ced1d
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelper.java
@@ -0,0 +1,31 @@
+/*
+ * 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.storage.helper;
+
+import com.cloud.agent.api.to.DataTO;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
+import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
+import org.apache.cloudstack.storage.to.SnapshotObjectTO;
+
+public interface HypervisorHelper {
+ DataTO introduceObject(DataTO object, Scope scope, Long storeId);
+ boolean forgetObject(DataTO object, Scope scope, Long storeId);
+ SnapshotObjectTO takeSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope);
+ boolean revertSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a129fe4e/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java b/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java
new file mode 100644
index 0000000..81e6f7c
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java
@@ -0,0 +1,77 @@
+/*
+ * 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.storage.helper;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.to.DataTO;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
+import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
+import org.apache.cloudstack.storage.command.ForgetObjectCmd;
+import org.apache.cloudstack.storage.command.IntroduceObjectAnswer;
+import org.apache.cloudstack.storage.command.IntroduceObjectCmd;
+import org.apache.cloudstack.storage.to.SnapshotObjectTO;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+public class HypervisorHelperImpl implements HypervisorHelper {
+ private static final Logger s_logger = Logger.getLogger(HypervisorHelperImpl.class);
+ @Inject
+ EndPointSelector selector;
+
+ @Override
+ public DataTO introduceObject(DataTO object, Scope scope, Long storeId) {
+ EndPoint ep = selector.select(scope, storeId);
+ IntroduceObjectCmd cmd = new IntroduceObjectCmd(object);
+ Answer answer = ep.sendMessage(cmd);
+ if (answer == null || !answer.getResult()) {
+ String errMsg = answer == null ? null : answer.getDetails();
+ throw new CloudRuntimeException("Failed to introduce object, due to " + errMsg);
+ }
+ IntroduceObjectAnswer introduceObjectAnswer = (IntroduceObjectAnswer)answer;
+ return introduceObjectAnswer.getDataTO();
+ }
+
+ @Override
+ public boolean forgetObject(DataTO object, Scope scope, Long storeId) {
+ EndPoint ep = selector.select(scope, storeId);
+ ForgetObjectCmd cmd = new ForgetObjectCmd(object);
+ Answer answer = ep.sendMessage(cmd);
+ if (answer == null || !answer.getResult()) {
+ String errMsg = answer == null ? null : answer.getDetails();
+ if (errMsg != null) {
+ s_logger.debug("Failed to forget object: " + errMsg);
+ }
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public SnapshotObjectTO takeSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public boolean revertSnapshot(SnapshotObjectTO snapshotObjectTO, Scope scope) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}