[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-11-16 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/cloudstack/pull/798


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-09-18 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/798#discussion_r79315858
  
--- Diff: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
 ---
@@ -1464,4 +1448,55 @@ private String deleteDir(String dir) {
 private static String getVolumeRelativeDirInSecStroage(long volumeId) {
 return "volumes/" + volumeId;
 }
+
+/**
+ * This method is to check if a given TaskInfo Object is valid( and 
has name and entity name assigned).It return true if TaskInfo Object is valid 
and false otherwise.
+ *
+ * @param TaskInfo
+ *info
+ * @return boolean(true or false)
+ **/
+private boolean isvalidTaskInfoObj(TaskInfo info){
+return !(info == null || info.getEntityName() == null || 
info.getName() == null);
+}
+
+/**
+ * This method waits for tasks running on vm to complete
+ *
+ * @param vmNameName of the vm
+ * @param taskName  Name of the task
+ * @param context   Task context object
+ * 
+ * @return boolean(true or false)   True if it waited for tasks to 
finish and false when there are no tasks running on the Vm.
+ **/
+ 
+private boolean waitForRunningTaskOnVM(String vmName, String taskName, 
VmwareContext context) throws Exception {
+try {
+ManagedObjectReference taskmgr = 
context.getServiceContent().getTaskManager();
+List tasks = 
context.getVimClient().getDynamicProperty(taskmgr, "recentTask");
+
+for (ManagedObjectReference taskMor : tasks) {
+TaskInfo info = 
(TaskInfo)(context.getVimClient().getDynamicProperty(taskMor, "info"));
+
+if (!isvalidTaskInfoObj(info)) {
+continue;
+}
+
+if (info.getEntityName().equals(vmName) && 
info.getName().equalsIgnoreCase(taskName)) {
+if (!(info.getState().equals(TaskInfoState.SUCCESS) || 
info.getState().equals(TaskInfoState.ERROR))) {
+s_logger.debug("There is already a task: " + 
taskName + " running for VM: " + vmName + ", wait for it");
+// wait if there is already similar VM task running
+context.getVimClient().waitForTask(taskMor);
+return true;
+}
+}
+}
+
+return false;
+} catch (Exception e) {
--- End diff --

Why are all checked and unchecked exceptions being caught here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-09-18 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/798#discussion_r79315873
  
--- Diff: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
 ---
@@ -1464,4 +1448,55 @@ private String deleteDir(String dir) {
 private static String getVolumeRelativeDirInSecStroage(long volumeId) {
 return "volumes/" + volumeId;
 }
+
+/**
+ * This method is to check if a given TaskInfo Object is valid( and 
has name and entity name assigned).It return true if TaskInfo Object is valid 
and false otherwise.
+ *
+ * @param TaskInfo
+ *info
+ * @return boolean(true or false)
+ **/
+private boolean isvalidTaskInfoObj(TaskInfo info){
+return !(info == null || info.getEntityName() == null || 
info.getName() == null);
+}
+
+/**
+ * This method waits for tasks running on vm to complete
+ *
+ * @param vmNameName of the vm
+ * @param taskName  Name of the task
+ * @param context   Task context object
+ * 
+ * @return boolean(true or false)   True if it waited for tasks to 
finish and false when there are no tasks running on the Vm.
+ **/
+ 
+private boolean waitForRunningTaskOnVM(String vmName, String taskName, 
VmwareContext context) throws Exception {
+try {
+ManagedObjectReference taskmgr = 
context.getServiceContent().getTaskManager();
+List tasks = 
context.getVimClient().getDynamicProperty(taskmgr, "recentTask");
+
+for (ManagedObjectReference taskMor : tasks) {
+TaskInfo info = 
(TaskInfo)(context.getVimClient().getDynamicProperty(taskMor, "info"));
+
+if (!isvalidTaskInfoObj(info)) {
+continue;
+}
+
+if (info.getEntityName().equals(vmName) && 
info.getName().equalsIgnoreCase(taskName)) {
+if (!(info.getState().equals(TaskInfoState.SUCCESS) || 
info.getState().equals(TaskInfoState.ERROR))) {
+s_logger.debug("There is already a task: " + 
taskName + " running for VM: " + vmName + ", wait for it");
+// wait if there is already similar VM task running
+context.getVimClient().waitForTask(taskMor);
+return true;
+}
+}
+}
+
+return false;
+} catch (Exception e) {
+String msg = "Failed to check running task: " + taskName + " 
for vm: " + vmName + " due to " + e.getMessage();
+s_logger.error(msg, e);
+throw new Exception(msg);
--- End diff --

`Exception` is a generic type, and, generally, should not be thrown.  I 
would recommend `IllegalStateException` here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-09-18 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/798#discussion_r79315898
  
--- Diff: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
 ---
@@ -1464,4 +1448,55 @@ private String deleteDir(String dir) {
 private static String getVolumeRelativeDirInSecStroage(long volumeId) {
 return "volumes/" + volumeId;
 }
+
+/**
+ * This method is to check if a given TaskInfo Object is valid( and 
has name and entity name assigned).It return true if TaskInfo Object is valid 
and false otherwise.
+ *
+ * @param TaskInfo
+ *info
+ * @return boolean(true or false)
+ **/
+private boolean isvalidTaskInfoObj(TaskInfo info){
+return !(info == null || info.getEntityName() == null || 
info.getName() == null);
+}
+
+/**
+ * This method waits for tasks running on vm to complete
+ *
+ * @param vmNameName of the vm
+ * @param taskName  Name of the task
+ * @param context   Task context object
+ * 
+ * @return boolean(true or false)   True if it waited for tasks to 
finish and false when there are no tasks running on the Vm.
+ **/
+ 
+private boolean waitForRunningTaskOnVM(String vmName, String taskName, 
VmwareContext context) throws Exception {
+try {
+ManagedObjectReference taskmgr = 
context.getServiceContent().getTaskManager();
+List tasks = 
context.getVimClient().getDynamicProperty(taskmgr, "recentTask");
+
+for (ManagedObjectReference taskMor : tasks) {
+TaskInfo info = 
(TaskInfo)(context.getVimClient().getDynamicProperty(taskMor, "info"));
+
+if (!isvalidTaskInfoObj(info)) {
+continue;
+}
+
+if (info.getEntityName().equals(vmName) && 
info.getName().equalsIgnoreCase(taskName)) {
+if (!(info.getState().equals(TaskInfoState.SUCCESS) || 
info.getState().equals(TaskInfoState.ERROR))) {
+s_logger.debug("There is already a task: " + 
taskName + " running for VM: " + vmName + ", wait for it");
--- End diff --

Please wrap this statement in an `if (s_logger.isDebugEnabled())` check.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-09-18 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/798#discussion_r79315948
  
--- Diff: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
 ---
@@ -1464,4 +1448,55 @@ private String deleteDir(String dir) {
 private static String getVolumeRelativeDirInSecStroage(long volumeId) {
 return "volumes/" + volumeId;
 }
+
+/**
+ * This method is to check if a given TaskInfo Object is valid( and 
has name and entity name assigned).It return true if TaskInfo Object is valid 
and false otherwise.
+ *
+ * @param TaskInfo
+ *info
+ * @return boolean(true or false)
+ **/
+private boolean isvalidTaskInfoObj(TaskInfo info){
--- End diff --

Why is this method necessary?  It is a one line boolean result that is 
called from one place.  It seems to obfuscate more than clarify.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-09-18 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/798#discussion_r79315938
  
--- Diff: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
 ---
@@ -1464,4 +1448,55 @@ private String deleteDir(String dir) {
 private static String getVolumeRelativeDirInSecStroage(long volumeId) {
 return "volumes/" + volumeId;
 }
+
+/**
+ * This method is to check if a given TaskInfo Object is valid( and 
has name and entity name assigned).It return true if TaskInfo Object is valid 
and false otherwise.
+ *
+ * @param TaskInfo
+ *info
+ * @return boolean(true or false)
+ **/
+private boolean isvalidTaskInfoObj(TaskInfo info){
+return !(info == null || info.getEntityName() == null || 
info.getName() == null);
--- End diff --

Please check `info.getEntityName()` and `info.getName()` with 
StringUtils.isBlank() rather than a simple `null` check.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] cloudstack pull request #798: CLOUDSTACK-8830 - [Vmware] VM snapshot fails f...

2016-09-18 Thread jburwell
Github user jburwell commented on a diff in the pull request:

https://github.com/apache/cloudstack/pull/798#discussion_r79315920
  
--- Diff: 
plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java
 ---
@@ -1464,4 +1448,55 @@ private String deleteDir(String dir) {
 private static String getVolumeRelativeDirInSecStroage(long volumeId) {
 return "volumes/" + volumeId;
 }
+
+/**
+ * This method is to check if a given TaskInfo Object is valid( and 
has name and entity name assigned).It return true if TaskInfo Object is valid 
and false otherwise.
+ *
+ * @param TaskInfo
+ *info
+ * @return boolean(true or false)
+ **/
+private boolean isvalidTaskInfoObj(TaskInfo info){
+return !(info == null || info.getEntityName() == null || 
info.getName() == null);
+}
+
+/**
+ * This method waits for tasks running on vm to complete
+ *
+ * @param vmNameName of the vm
+ * @param taskName  Name of the task
+ * @param context   Task context object
+ * 
+ * @return boolean(true or false)   True if it waited for tasks to 
finish and false when there are no tasks running on the Vm.
+ **/
+ 
+private boolean waitForRunningTaskOnVM(String vmName, String taskName, 
VmwareContext context) throws Exception {
--- End diff --

Throwing `Exception` is an anti-pattern and should be avoided.  Either 
throw a custom checked exception with contextual information and transform all 
checked exceptions to unchecked.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---