Author: adietish
Date: 2010-12-08 12:07:45 -0500 (Wed, 08 Dec 2010)
New Revision: 27243
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudElementJob.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudJob.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudJob.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetImagesCommand.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetInstancesCommand.java
Log:
[JBIDE-7594] started scheduling rules. need further refinement.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-08 17:00:00
UTC (rev 27242)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-08 17:07:45
UTC (rev 27243)
@@ -1,5 +1,10 @@
2010-12-08 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/core/job/AbstractCloudElementJob.java:
+ * src/org/jboss/tools/deltacloud/core/job/AbstractCloudJob.java:
+ * src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java:
+ * src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java:
+ [JBIDE-7594] started scheduling rules. need further refinement.
* src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getImage):
[JBIDE-7834] implemented #getLastImage(id) that queries the local cache and the server
(fallback),
removed #getImage(String id), #loadImage(String imageId), removed #findInstanceById
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/META-INF/MANIFEST.MF
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/META-INF/MANIFEST.MF 2010-12-08
17:00:00 UTC (rev 27242)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/META-INF/MANIFEST.MF 2010-12-08
17:07:45 UTC (rev 27243)
@@ -13,7 +13,8 @@
Export-Package:
org.apache.http.client.methods;x-friends:="org.jboss.tools.deltacloud.test",
org.jboss.tools.deltacloud.core;x-friends:="org.jboss.tools.deltacloud.ui,org.jboss.tools.deltacloud.test",
org.jboss.tools.deltacloud.core.client;x-friends:="org.jboss.tools.deltacloud.test,org.jboss.tools.deltacloud.ui",
-
org.jboss.tools.deltacloud.core.client.request;x-friends:="org.jboss.tools.deltacloud.test"
+
org.jboss.tools.deltacloud.core.client.request;x-friends:="org.jboss.tools.deltacloud.test",
+ org.jboss.tools.deltacloud.core.job
Bundle-ClassPath: .,
lib/apache-mime4j-0.6.jar,
lib/commons-codec-1.3.jar,
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudJob.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudJob.java 2010-12-08
17:00:00 UTC (rev 27242)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudJob.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.deltacloud.core;
-
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.jobs.Job;
-import org.jboss.tools.common.log.StatusFactory;
-
-/**
- * @author André Dietisheim
- */
-public abstract class AbstractCloudJob extends Job {
-
- public AbstractCloudJob(String name) {
- super(name);
- // setUser(true);
- }
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- monitor.beginTask(getName(), IProgressMonitor.UNKNOWN);
- monitor.worked(1);
- try {
- return doRun(monitor);
- } catch (Exception e) {
- // TODO: internationalize strings
- return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
- MessageFormat.format("Could not {0}", getName()));
- }
- }
-
- protected abstract IStatus doRun(IProgressMonitor monitor) throws Exception;
-
-}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetImagesCommand.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetImagesCommand.java 2010-12-08
17:00:00 UTC (rev 27242)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetImagesCommand.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -15,6 +15,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudJob;
/**
* @author Andre Dietisheim
@@ -28,7 +29,7 @@
public void execute() {
// TODO: internationalize strings
new AbstractCloudJob(
- MessageFormat.format("Get images from cloud {0}", getCloud().getName())) {
+ MessageFormat.format("Get images from cloud {0}", getCloud().getName()),
getCloud()) {
@Override
protected IStatus doRun(IProgressMonitor monitor) throws DeltaCloudException {
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetInstancesCommand.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetInstancesCommand.java 2010-12-08
17:00:00 UTC (rev 27242)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/GetInstancesCommand.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -15,6 +15,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudJob;
/**
* @author Andre Dietisheim
@@ -28,7 +29,7 @@
public void execute() {
// TODO: internationalize strings
new AbstractCloudJob(
- MessageFormat.format("Get instances from cloud {0}", getCloud().getName()))
{
+ MessageFormat.format("Get instances from cloud {0}", getCloud().getName()),
getCloud()) {
@Override
protected IStatus doRun(IProgressMonitor monitor) throws DeltaCloudException {
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudElementJob.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudElementJob.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudElementJob.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.job;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+
+/**
+ * @author André Dietisheim
+ */
+public abstract class AbstractCloudElementJob extends AbstractCloudJob {
+
+ public static enum CLOUDELEMENT {
+ IMAGES, INSTANCES
+ }
+
+ private CLOUDELEMENT cloudElement;
+
+ public AbstractCloudElementJob(String name, DeltaCloud cloud, CLOUDELEMENT cloudElement)
{
+ super(name, cloud);
+ this.cloudElement = cloudElement;
+ // setUser(true);
+ }
+
+ protected abstract IStatus doRun(IProgressMonitor monitor) throws Exception;
+
+ @Override
+ protected ISchedulingRule getSchedulingRule() {
+ return new CloudElementSchedulingRule(getCloud(), cloudElement);
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudElementJob.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudJob.java
(from rev 27205,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/AbstractCloudJob.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudJob.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudJob.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.job;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.tools.common.log.StatusFactory;
+import org.jboss.tools.deltacloud.core.Activator;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+
+/**
+ * @author André Dietisheim
+ */
+public abstract class AbstractCloudJob extends Job {
+
+ private DeltaCloud cloud;
+
+ public AbstractCloudJob(String name, DeltaCloud cloud) {
+ super(name);
+ this.cloud = cloud;
+ // setUser(true);
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ ISchedulingRule rule = getSchedulingRule();
+ Job.getJobManager().beginRule(rule, monitor);
+ monitor.beginTask(getName(), IProgressMonitor.UNKNOWN);
+ monitor.worked(1);
+ try {
+ return doRun(monitor);
+ } catch (Exception e) {
+ // TODO: internationalize strings
+ return StatusFactory.getInstance(IStatus.ERROR, Activator.PLUGIN_ID,
+ MessageFormat.format("Could not {0}", getName()));
+ } finally {
+ Job.getJobManager().endRule(rule);
+ }
+ }
+
+ protected DeltaCloud getCloud() {
+ return cloud;
+ }
+
+ protected abstract IStatus doRun(IProgressMonitor monitor) throws Exception;
+
+ protected ISchedulingRule getSchedulingRule() {
+ return new CloudSchedulingRule(cloud);
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/AbstractCloudJob.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.job;
+
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.job.AbstractCloudElementJob.CLOUDELEMENT;
+
+/**
+ * A scheduling rule for jobs that prevents 2 jobs from running on the same
+ * cloud instance.
+ *
+ * @author André Dietisheim
+ */
+public class CloudElementSchedulingRule extends CloudSchedulingRule {
+
+ private CLOUDELEMENT element;
+
+ public CloudElementSchedulingRule(DeltaCloud cloud, CLOUDELEMENT element) {
+ super(cloud);
+ this.element = element;
+ }
+
+ @Override
+ public boolean contains(ISchedulingRule rule) {
+ return rule == this;
+ }
+
+ @Override
+ public boolean isConflicting(ISchedulingRule rule) {
+ return super.isConflicting(rule)
+ && isOnSameElement(rule);
+ }
+
+ private boolean isOnSameElement(ISchedulingRule rule) {
+ return rule.getClass().isAssignableFrom(CloudElementSchedulingRule.class)
+ && ((CloudElementSchedulingRule) rule).getCloudElement().equals(element);
+ }
+
+ private CLOUDELEMENT getCloudElement() {
+ return element;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudElementSchedulingRule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java 2010-12-08
17:07:45 UTC (rev 27243)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.job;
+
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+
+/**
+ * A scheduling rule for jobs that prevents 2 jobs from running on the same
+ * cloud instance.
+ *
+ * @author André Dietisheim
+ */
+public class CloudSchedulingRule implements ISchedulingRule {
+
+ private DeltaCloud cloud;
+
+ public CloudSchedulingRule(DeltaCloud cloud) {
+ this.cloud = cloud;
+ }
+
+ @Override
+ public boolean contains(ISchedulingRule rule) {
+ return rule == this;
+ }
+
+ @Override
+ public boolean isConflicting(ISchedulingRule rule) {
+ return isOnSameCloud(rule);
+ }
+
+ private boolean isOnSameCloud(ISchedulingRule rule) {
+ if (isCloudRule(rule)) {
+ CloudSchedulingRule cloudRule = (CloudSchedulingRule) rule;
+ return cloud.equals(cloudRule.getCloud());
+ } else {
+ return false;
+ }
+ }
+
+ private boolean isCloudRule(ISchedulingRule rule) {
+ return rule.getClass().isAssignableFrom(CloudSchedulingRule.class);
+ }
+
+ private DeltaCloud getCloud() {
+ return cloud;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/job/CloudSchedulingRule.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain