Author: adietish
Date: 2012-05-15 16:22:31 -0400 (Tue, 15 May 2012)
New Revision: 41032
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgeStrategy.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategyAdapter.java
trunk/openshift/tests/org.jboss.tools.openshift.express.test/src/org/jboss/tools/openshift/express/test/EmbedCartridgeStrategyTest.java
Removed:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java
trunk/openshift/tests/org.jboss.tools.openshift.express.test/META-INF/MANIFEST.MF
Log:
[JBIDE-10852] implemented generic strategy to handle all the different dependency aspects
(simple if/else approach was getting very messy). Implemented unit-test for embed
cartridge strategy
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2012-05-15
20:22:31 UTC (rev 41032)
@@ -54,7 +54,8 @@
org.jboss.tools.common.ui.preferencevalue,
org.jboss.tools.common.ui.ssh
Bundle-Vendor: %Bundle-Vendor.0
-Export-Package:
org.jboss.tools.openshift.express.internal.core.behaviour;x-friends:="org.jboss.tools.openshift.express.test",
+Export-Package:
org.jboss.tools.openshift.express.internal.core;x-friends:="org.jboss.tools.openshift.express.test",
+
org.jboss.tools.openshift.express.internal.core.behaviour;x-friends:="org.jboss.tools.openshift.express.test",
org.jboss.tools.openshift.express.internal.ui;x-friends:="org.jboss.tools.openshift.express.test",
org.jboss.tools.openshift.express.internal.ui.behaviour;x-friends:="org.jboss.tools.openshift.express.test",
org.jboss.tools.openshift.express.internal.ui.console;x-friends:="org.jboss.tools.openshift.express.test",
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgeStrategy.java
(from rev 40985,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgeStrategy.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgeStrategy.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -0,0 +1,250 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.openshift.express.internal.core;
+
+import java.net.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.openshift.client.IApplication;
+import com.openshift.client.ICartridge;
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.OpenShiftException;
+
+/**
+ * A UI strategy that is able to add and remove embedded cartridges while
+ * fullfilling requirements and resolving conflicts (ex. mutual exclusivity
+ * etc.)
+ * <p>
+ * TODO: replaced this manual code by a generic dependency-tree analysis
+ * mechanism as soon as OpenShift completed design of cartridge metamodel
+ *
+ * @author Andre Dietisheim
+ */
+public class EmbedCartridgeStrategy {
+
+ private static final EmbeddableCartridgeRelations[] dependencies =
+ new EmbeddableCartridgeRelations[] {
+ new EmbeddableCartridgeRelations(IEmbeddableCartridge.JENKINS_14,
+ null, null, ICartridge.JENKINS_14),
+ new EmbeddableCartridgeRelations(IEmbeddableCartridge.PHPMYADMIN_34,
+ null, IEmbeddableCartridge.MYSQL_51, null),
+ new EmbeddableCartridgeRelations(IEmbeddableCartridge.ROCKMONGO_11,
+ null, IEmbeddableCartridge.MONGODB_20, null),
+ new EmbeddableCartridgeRelations(IEmbeddableCartridge._10GEN_MMS_AGENT_01,
+ null, IEmbeddableCartridge.MONGODB_20, null),
+ new EmbeddableCartridgeRelations(IEmbeddableCartridge.POSTGRESQL_84,
+ IEmbeddableCartridge.MYSQL_51, null, null),
+ new EmbeddableCartridgeRelations(IEmbeddableCartridge.MYSQL_51,
+ IEmbeddableCartridge.POSTGRESQL_84, null, null),
+ };
+
+ private Map<IEmbeddableCartridge, EmbeddableCartridgeRelations>
dependenciesByCartridge;
+ private HashMap<IEmbeddableCartridge, Set<IEmbeddableCartridge>>
dependantsByCartridge;
+
+ private IApplication application;
+
+ public EmbedCartridgeStrategy(IApplication application) {
+ this.application = application;
+ initDependencyMaps(dependencies);
+ }
+
+ private void initDependencyMaps(EmbeddableCartridgeRelations... dependencies) {
+ this.dependenciesByCartridge = new HashMap<IEmbeddableCartridge,
EmbeddableCartridgeRelations>();
+
+ this.dependantsByCartridge = new HashMap<IEmbeddableCartridge,
Set<IEmbeddableCartridge>>();
+ for (EmbeddableCartridgeRelations dependency : dependencies) {
+ dependenciesByCartridge.put(dependency.getSubject(), dependency);
+ Set<IEmbeddableCartridge> dependants = getDependants(dependency);
+ dependants.add(dependency.getSubject());
+ }
+ }
+
+ private Set<IEmbeddableCartridge> getDependants(EmbeddableCartridgeRelations
relation) {
+ Set<IEmbeddableCartridge> dependants =
dependantsByCartridge.get(relation.getRequired());
+ if (dependants == null) {
+ dependantsByCartridge.put(
+ relation.getRequired(),
+ dependants = new HashSet<IEmbeddableCartridge>());
+ }
+ return dependants;
+ }
+
+ public EmbeddableCartridgeDiff add(IEmbeddableCartridge cartridge,
Set<IEmbeddableCartridge> currentCartridges)
+ throws OpenShiftException, SocketTimeoutException {
+ EmbeddableCartridgeDiff cartridgeDiff = new EmbeddableCartridgeDiff(cartridge);
+ add(cartridge, currentCartridges, cartridgeDiff);
+ return cartridgeDiff;
+ }
+
+ private void add(IEmbeddableCartridge cartridge, Set<IEmbeddableCartridge>
currentCartridges,
+ EmbeddableCartridgeDiff diff)
+ throws OpenShiftException, SocketTimeoutException {
+ EmbeddableCartridgeRelations relation = dependenciesByCartridge.get(cartridge);
+ if (relation == null) {
+ return;
+ }
+ removeConflicting(currentCartridges, diff, relation);
+ addRequired(currentCartridges, diff, relation.getRequired());
+ addRequiredApplication(diff, relation);
+ }
+
+ private void addRequired(Set<IEmbeddableCartridge> currentCartridges,
EmbeddableCartridgeDiff diff,
+ IEmbeddableCartridge requiredCartridge) throws OpenShiftException,
+ SocketTimeoutException {
+ if (requiredCartridge != null
+ && !currentCartridges.contains(requiredCartridge)) {
+ // recurse
+ add(requiredCartridge, currentCartridges, diff);
+ diff.addAddition(requiredCartridge);
+ }
+ }
+
+ private void addRequiredApplication(EmbeddableCartridgeDiff diff,
+ EmbeddableCartridgeRelations relation) throws OpenShiftException {
+ if (relation.getRequiredApplication() != null
+ &&
!application.getDomain().hasApplicationByCartridge(relation.getRequiredApplication())) {
+ diff.addApplicationAddition(relation.getRequiredApplication());
+ }
+ }
+
+ private void removeConflicting(Set<IEmbeddableCartridge> currentCartridges,
EmbeddableCartridgeDiff cartridgeDiff,
+ EmbeddableCartridgeRelations relation) throws OpenShiftException,
SocketTimeoutException {
+ IEmbeddableCartridge conflictingCartridge = relation.getConflicting();
+ if (conflictingCartridge != null) {
+ remove(conflictingCartridge, currentCartridges, cartridgeDiff);
+ if (currentCartridges.contains(conflictingCartridge)) {
+ cartridgeDiff.addRemoval(conflictingCartridge);
+ }
+ }
+ }
+
+ public EmbeddableCartridgeDiff remove(IEmbeddableCartridge cartridge,
Set<IEmbeddableCartridge> currentCartridges)
+ throws OpenShiftException, SocketTimeoutException {
+ EmbeddableCartridgeDiff cartridgeDiff = new EmbeddableCartridgeDiff(cartridge);
+ remove(cartridge, currentCartridges, cartridgeDiff);
+ return cartridgeDiff;
+ }
+
+ private void remove(IEmbeddableCartridge cartridge, Set<IEmbeddableCartridge>
currentCartridges,
+ EmbeddableCartridgeDiff cartridgeDiff)
+ throws OpenShiftException, SocketTimeoutException {
+ Set<IEmbeddableCartridge> dependantCartridges =
dependantsByCartridge.get(cartridge);
+ if (dependantCartridges == null) {
+ return;
+ }
+ for (IEmbeddableCartridge dependantCartridge : dependantCartridges) {
+ if (currentCartridges.contains(dependantCartridge)) {
+ remove(dependantCartridge, currentCartridges, cartridgeDiff);
+ cartridgeDiff.addRemoval(dependantCartridge);
+ }
+ }
+ }
+
+ private static class EmbeddableCartridgeRelations {
+
+ private IEmbeddableCartridge conflicting;
+ private IEmbeddableCartridge required;
+ private IEmbeddableCartridge subject;
+ private ICartridge requiredApplication;
+
+ protected EmbeddableCartridgeRelations(IEmbeddableCartridge cartridge,
+ IEmbeddableCartridge conflicting, IEmbeddableCartridge required, ICartridge
requiredApplication) {
+ this.subject = cartridge;
+ this.conflicting = conflicting;
+ this.required = required;
+ this.requiredApplication = requiredApplication;
+ }
+
+ protected IEmbeddableCartridge getSubject() {
+ return subject;
+ }
+
+ protected IEmbeddableCartridge getConflicting() {
+ return conflicting;
+ }
+
+ protected IEmbeddableCartridge getRequired() {
+ return required;
+ }
+
+ protected ICartridge getRequiredApplication() {
+ return requiredApplication;
+ }
+
+ }
+
+ public static class EmbeddableCartridgeDiff {
+
+ private List<IEmbeddableCartridge> removals;
+ private List<IEmbeddableCartridge> additions;
+ private List<ICartridge> applicationAdditions;
+ private IEmbeddableCartridge cartridge;
+
+ protected EmbeddableCartridgeDiff(IEmbeddableCartridge cartridge) {
+ this.cartridge = cartridge;
+ this.removals = new ArrayList<IEmbeddableCartridge>();
+ this.additions = new ArrayList<IEmbeddableCartridge>();
+ this.applicationAdditions = new ArrayList<ICartridge>();
+ }
+
+ public IEmbeddableCartridge getCartridge() {
+ return cartridge;
+ }
+
+ public List<IEmbeddableCartridge> getAdditions() {
+ return additions;
+ }
+
+ public boolean hasAdditions() {
+ return getAdditions().size() > 0;
+ }
+
+ protected void addAddition(IEmbeddableCartridge cartridge) {
+ additions.add(cartridge);
+ }
+
+ public List<IEmbeddableCartridge> getRemovals() {
+ return removals;
+ }
+
+ public boolean hasRemovals() {
+ return getRemovals().size() > 0;
+ }
+
+ protected void addRemoval(IEmbeddableCartridge cartridge) {
+ removals.add(cartridge);
+ }
+
+ protected void addApplicationAddition(ICartridge applicationType) {
+ applicationAdditions.add(applicationType);
+ }
+
+ public List<ICartridge> getApplicationAdditions() {
+ return applicationAdditions;
+ }
+
+ public boolean hasApplicationAdditions() {
+ return getApplicationAdditions().size() > 0;
+ }
+
+ public boolean hasChanges() {
+ return hasApplicationAdditions()
+ || hasRemovals()
+ || hasAdditions();
+ }
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgeStrategy.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/EmbedCartridgesOperation.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -16,9 +16,6 @@
import java.util.Comparator;
import java.util.List;
-import org.eclipse.core.databinding.observable.Diffs;
-import org.eclipse.core.databinding.observable.list.ListDiff;
-import org.eclipse.core.databinding.observable.list.ListDiffEntry;
import org.eclipse.core.runtime.IProgressMonitor;
import com.openshift.client.IApplication;
@@ -43,26 +40,23 @@
* Embeds and removes cartridges from the given application so that it
* matches the given list of enabled cartridges.
*
- * @param enabledCartridges
+ * @param selectedCartridges
* @param monitor
* @return
* @throws SocketTimeoutException
* @throws OpenShiftException
*/
- public List<IEmbeddedCartridge> execute(final List<IEmbeddableCartridge>
enabledCartridges,
+ public List<IEmbeddedCartridge> execute(final List<IEmbeddableCartridge>
selectedCartridges,
final IProgressMonitor monitor)
throws SocketTimeoutException, OpenShiftException {
- if (enabledCartridges == null) {
+ if (selectedCartridges == null) {
return Collections.emptyList();
}
List<IEmbeddableCartridge> cartridgesToAdd = new
ArrayList<IEmbeddableCartridge>();
List<IEmbeddableCartridge> cartridgesToRemove = new
ArrayList<IEmbeddableCartridge>();
- computeAdditionsAndRemovals(
- cartridgesToAdd,
- cartridgesToRemove,
- enabledCartridges,
- application.getEmbeddedCartridges());
+ computeRemovals(selectedCartridges, application.getEmbeddedCartridges(),
cartridgesToRemove);
+ computeAdditions(selectedCartridges, application.getEmbeddedCartridges(),
cartridgesToAdd);
removeEmbeddedCartridges(cartridgesToRemove, application);
final List<IEmbeddedCartridge> addedCartridges =
addEmbeddedCartridges(cartridgesToAdd, application);
@@ -70,7 +64,7 @@
}
private void removeEmbeddedCartridges(List<IEmbeddableCartridge>
cartridgesToRemove, final IApplication application)
- throws OpenShiftException,SocketTimeoutException {
+ throws OpenShiftException, SocketTimeoutException {
if (cartridgesToRemove.isEmpty()) {
return;
}
@@ -93,20 +87,24 @@
return application.addEmbeddableCartridges(cartridgesToAdd);
}
- private void computeAdditionsAndRemovals(List<IEmbeddableCartridge>
addedCartridges,
- List<IEmbeddableCartridge> removedCartridges, List<IEmbeddableCartridge>
selectedCartridges,
- List<IEmbeddedCartridge> embeddedCartidges)
- throws OpenShiftException, SocketTimeoutException {
- ListDiff listDiff = Diffs.computeListDiff(embeddedCartidges, selectedCartridges);
- for (ListDiffEntry entry : listDiff.getDifferences()) {
- if (entry.isAddition()) {
- addedCartridges.add((IEmbeddableCartridge) entry.getElement());
- } else {
- removedCartridges.add((IEmbeddableCartridge) entry.getElement());
+ private void computeAdditions(List<IEmbeddableCartridge> selectedCartridges,
+ List<IEmbeddedCartridge> embeddedCartridges, List<IEmbeddableCartridge>
addedCartridges) {
+ for (IEmbeddableCartridge cartridge : selectedCartridges){
+ if (!embeddedCartridges.contains(cartridge)){
+ addedCartridges.add(cartridge);
}
}
}
+ private void computeRemovals(List<IEmbeddableCartridge> selectedCartridges,
+ List<IEmbeddedCartridge> embeddedCartridges, List<IEmbeddableCartridge>
removedCartridges) {
+ for (IEmbeddableCartridge cartridge : embeddedCartridges){
+ if (!selectedCartridges.contains(cartridge)){
+ removedCartridges.add(cartridge);
+ }
+ }
+ }
+
private static class CartridgeAddRemovePriorityComparator implements
Comparator<IEmbeddableCartridge> {
@Override
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/utils/StringUtils.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -31,6 +31,19 @@
|| value.length() == 0;
}
+ public static <T> String toString(List<T> elements) {
+ return toString(elements, new ToStringConverter<T>() {
+
+ @Override
+ public String toString(T object) {
+ if (object == null) {
+ return null;
+ }
+ return String.valueOf(object);
+ }
+ });
+ }
+
public static <T> String toString(List<T> elements,
ToStringConverter<T> converter) {
StringBuilder builder = new StringBuilder();
for(int i = 0; i < elements.size(); i++) {
@@ -42,7 +55,7 @@
}
return builder.toString();
}
-
+
public static interface ToStringConverter<T> {
public String toString(T object);
}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPage.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -16,7 +16,6 @@
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
-import org.eclipse.core.databinding.UpdateSetStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.observable.list.IObservableList;
@@ -334,14 +333,12 @@
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(1,
2).hint(400, 250)
.applyTo(tableContainer);
this.viewer = createTable(tableContainer);
- viewer.addCheckStateListener(new EmbedCartridgeStrategy(pageModel, this));
+ viewer.addCheckStateListener(new EmbedCartridgeStrategyAdapter(pageModel, this));
dbc.bindSet(
ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
BeanProperties.set(
ApplicationConfigurationWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
- .observe(pageModel),
- new UpdateSetStrategy(UpdateSetStrategy.POLICY_NEVER),
- null);
+ .observe(pageModel));
this.checkAllButton = new Button(newAppEmbeddableCartridgesGroup, SWT.PUSH);
checkAllButton.setText("&Select All");
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationConfigurationWizardPageModel.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -337,7 +337,7 @@
if (application != null) {
setApplicationName(application.getName());
setSelectedCartridge(application.getCartridge());
- setSelectedEmbeddableCartridges(new
HashSet<IEmbeddableCartridge>(application.getEmbeddedCartridges()));
+ setSelectedEmbeddableCartridges(application.getEmbeddedCartridges());
setSelectedGearProfile(application.getGearProfile());
setScale(application.getApplicationScale());
wizardModel.setApplication(application);
@@ -397,6 +397,10 @@
return wizardModel.getSelectedEmbeddableCartridges();
}
+ protected void setSelectedEmbeddableCartridges(List<? extends
IEmbeddableCartridge> cartridges) {
+ setSelectedEmbeddableCartridges(cartridges);
+ }
+
public void setSelectedEmbeddableCartridges(Set<IEmbeddableCartridge>
selectedEmbeddableCartridges) {
firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES,
wizardModel.getSelectedEmbeddableCartridges(),
@@ -407,11 +411,6 @@
return getSelectedEmbeddableCartridges().contains(cartridge);
}
- @Override
- public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException {
- return getUser().hasApplicationOfType(cartridge);
- }
-
public boolean hasApplication(String applicationName) throws SocketTimeoutException,
OpenShiftException {
return getUser().hasApplication(applicationName);
}
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategy.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -1,289 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.openshift.express.internal.ui.wizard;
-
-import java.net.SocketTimeoutException;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IInputValidator;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.wizard.IWizardContainer;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.widgets.Shell;
-import org.jboss.tools.common.ui.WizardUtils;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
-
-import com.openshift.client.IApplication;
-import com.openshift.client.ICartridge;
-import com.openshift.client.IEmbeddableCartridge;
-import com.openshift.client.OpenShiftException;
-
-/**
- * A UI strategy that is able to add and remove embedded cartridges while
- * fullfilling requirements and resolving conflicts (ex. mutual exclusivity
- * etc.)
- * <p>
- * TODO: replaced this manual code by a generic dependency-tree analysis
- * mechanism as soon as OpenShift completed design of cartridge metamodel
- *
- * @author Andre Dietisheim
- */
-public class EmbedCartridgeStrategy implements ICheckStateListener {
-
- private IEmbedCartridgesWizardPageModel pageModel;
- private IWizardPage wizardPage;
-
- public EmbedCartridgeStrategy(IEmbedCartridgesWizardPageModel pageModel, IWizardPage
wizardPage) {
- this.wizardPage = wizardPage;
- this.pageModel = pageModel;
- }
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent event) {
- try {
- IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
- if (event.getChecked()) {
- addCartridge(cartridge);
- } else {
- removeCartridge(cartridge);
- }
- } catch (OpenShiftException e) {
- OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
- } catch (SocketTimeoutException e) {
- OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
- }
- }
-
- private void addCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
- if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
- addPhpMyAdmin();
- } else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
- addJenkins(cartridge);
- } else if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
- addMySql();
- } else if (IEmbeddableCartridge.POSTGRESQL_84.equals(cartridge)) {
- addPostgreSql();
- } else if (IEmbeddableCartridge.ROCKMONGO_11.equals(cartridge)) {
- addRockMongo();
- } else if (IEmbeddableCartridge._10GEN_MMS_AGENT_01.equals(cartridge)) {
- add10gen();
- } else {
- pageModel.selectEmbeddedCartridges(cartridge);
- }
- }
-
- private void removeCartridge(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException {
- if (IEmbeddableCartridge.MYSQL_51.equals(cartridge)) {
- removeMySQL();
- } else if (IEmbeddableCartridge.MONGODB_20.equals(cartridge)) {
- removeMongoDb();
- } else {
- pageModel.unselectEmbeddedCartridges(cartridge);
- }
- }
-
- private void addJenkins(final IEmbeddableCartridge cartridge) throws
OpenShiftException,
- SocketTimeoutException {
- if (pageModel.hasApplicationOfType(ICartridge.JENKINS_14)) {
- pageModel.getSelectedEmbeddableCartridges().add(cartridge);
- } else {
- final JenkinsApplicationDialog dialog = new JenkinsApplicationDialog(getShell());
- if (dialog.open() == Dialog.OK) {
- createJenkinsApplication(cartridge, dialog.getValue());
- } else {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.JENKINS_14);
- }
- }
- }
-
- private void createJenkinsApplication(final IEmbeddableCartridge cartridge, final String
name) {
- try {
- WizardUtils.runInWizard(new Job(NLS.bind("Creating jenkins application
\"{0}\"...", name)) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- IApplication jenkinsApplication = pageModel.createJenkinsApplication(name,
monitor);
- pageModel.selectEmbeddedCartridges(cartridge);
- openLogDialog(jenkinsApplication);
- return Status.OK_STATUS;
- } catch (Exception e) {
- try {
- pageModel.selectEmbeddedCartridges(cartridge);
- } catch (Exception ex) {
- OpenShiftUIActivator.log(ex);
- }
- return OpenShiftUIActivator.createErrorStatus("Could not create jenkins
application", e);
- }
- }
-
- }, getContainer());
- } catch (Exception e) {
- // ignore
- }
- }
-
- private void addPhpMyAdmin() throws OpenShiftException, SocketTimeoutException {
- if (!pageModel.isSelected(IEmbeddableCartridge.MYSQL_51)) {
- if (MessageDialog.openQuestion(getShell(), "Embed phpMyAdmin Cartridge",
- "To embed phpMyAdmin, you'd also have to embed MySQL. \n\nAlso embed
MySQL?")) {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
- private void addMySql()
- throws OpenShiftException, SocketTimeoutException {
- if (pageModel.isSelected(IEmbeddableCartridge.POSTGRESQL_84)) {
- if (MessageDialog
- .openQuestion(getShell(), "Remove PostgreSQL Cartridge",
- "MySQL and PostgreSQL are mutually exclusive. To embed MySQL, you have to
remove PostgreSQL. \n\nRemove PostgreSQL?")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- }
-
- private void addPostgreSql()
- throws OpenShiftException, SocketTimeoutException {
- if (pageModel.isSelected(IEmbeddableCartridge.MYSQL_51)) {
- if (MessageDialog
- .openQuestion(getShell(), "Remove MySQL Cartridge",
- "MySQL and PostgreSQL are mutually exclusive. To embed PostgreSQL, you have
to remove MySQL.\n\nRemove MySQL?")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.POSTGRESQL_84);
- }
- }
-
- private void removeMySQL() throws OpenShiftException, SocketTimeoutException {
- if (pageModel.isSelected(IEmbeddableCartridge.PHPMYADMIN_34)) {
- if (MessageDialog
- .openQuestion(getShell(), "Remove phpmyadmin cartridge",
- "If you remove the mysql cartridge, you'd also have to remove
phpmyadmin.\n\nRemove phpMyAdmin and MySQL?")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- } else {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MYSQL_51);
- }
- }
-
- private void addRockMongo() throws OpenShiftException, SocketTimeoutException {
- if (!pageModel.isSelected(IEmbeddableCartridge.MONGODB_20)) {
- if (MessageDialog.openQuestion(getShell(), "Embed MongoDB Cartridge",
- "To embed RockMongo, you'd also have to embed MongoDB. \n\nAlso embed
MongoDB?")) {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
- private void removeMongoDb() throws OpenShiftException, SocketTimeoutException {
- boolean removeMongoDb = true;
- if (pageModel.isSelected(IEmbeddableCartridge.ROCKMONGO_11)) {
- if (MessageDialog.openQuestion(getShell(), "Remove MongoDB cartridge",
- "If you remove the MongoDB cartridge, you'd also have to remove
RockMongo.")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.ROCKMONGO_11);
- } else {
- removeMongoDb = false;
- }
- }
-
- if (removeMongoDb // mongo to be removed?
- && pageModel.isSelected(IEmbeddableCartridge._10GEN_MMS_AGENT_01)) {
- if (MessageDialog.openQuestion(getShell(), "Remove MongoDB cartridge",
- "If you remove the MongoDB cartridge, you'd also have to remove 10gen MMS
agent.")) {
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
- } else {
- removeMongoDb = false;
- }
- }
-
- if (removeMongoDb) { // mongo to be removed?
- pageModel.unselectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- }
- }
-
- private void add10gen() throws OpenShiftException, SocketTimeoutException {
- if (!pageModel.isSelected(IEmbeddableCartridge.MONGODB_20)) {
- if (MessageDialog.openQuestion(getShell(), "Embed 10gen Cartridge",
- "To embed 10gen cartridge, you'd also have to embed MongoDB. \n\nAlso embed
MongoDB?")) {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.MONGODB_20);
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
- }
- } else {
- pageModel.selectEmbeddedCartridges(IEmbeddableCartridge.PHPMYADMIN_34);
- }
- }
-
- private Shell getShell() {
- return wizardPage.getControl().getShell();
- }
-
- private IWizardContainer getContainer() {
- return wizardPage.getWizard().getContainer();
- }
-
- private void openLogDialog(final IApplication application) {
- wizardPage.getControl().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- new CreationLogDialog(getShell(), application).open();
- }
- });
- }
-
- private static class JenkinsApplicationDialog extends InputDialog {
-
- public JenkinsApplicationDialog(Shell shell) {
- super(
- shell,
- "New Jenkins application",
- "To embed Jenkins into your application, you first have to create a separate
Jenkins application. "
- + "Please provide a name for this new Jenkins application (lower-case letters
and digits only):"
- , null, new JenkinsNameValidator());
- }
-
- private static class JenkinsNameValidator implements IInputValidator {
-
- @Override
- public String isValid(String input) {
- if (StringUtils.isEmpty(input)) {
- return "You have to provide a name for the jenkins application";
- }
-
- if (!StringUtils.isAlphaNumeric(input)) {
- return "The name may only contain lower-case letters and digits.";
- }
- return null;
- }
- }
- }
-}
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategyAdapter.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategyAdapter.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategyAdapter.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.openshift.express.internal.ui.wizard;
+
+import java.net.SocketTimeoutException;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.internal.core.EmbedCartridgeStrategy;
+import
org.jboss.tools.openshift.express.internal.core.EmbedCartridgeStrategy.EmbeddableCartridgeDiff;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
+import
org.jboss.tools.openshift.express.internal.ui.utils.StringUtils.ToStringConverter;
+
+import com.openshift.client.IApplication;
+import com.openshift.client.ICartridge;
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.OpenShiftException;
+
+/**
+ * A UI strategy that is able to add and remove embedded cartridges while
+ * fullfilling requirements and resolving conflicts (ex. mutual exclusivity
+ * etc.)
+ * <p>
+ * TODO: replaced this manual code by a generic dependency-tree analysis
+ * mechanism as soon as OpenShift completed design of cartridge metamodel
+ *
+ * @author Andre Dietisheim
+ */
+public class EmbedCartridgeStrategyAdapter implements ICheckStateListener {
+
+ private IEmbedCartridgesWizardPageModel pageModel;
+ private IWizardPage wizardPage;
+
+ public EmbedCartridgeStrategyAdapter(IEmbedCartridgesWizardPageModel pageModel,
IWizardPage wizardPage) {
+ this.wizardPage = wizardPage;
+ this.pageModel = pageModel;
+ }
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ try {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
+ EmbeddableCartridgeDiff diff = null;
+ EmbedCartridgeStrategy embedCartridgeStrategy = new
EmbedCartridgeStrategy(pageModel.getApplication());
+ diff = createEmbeddableCartridgeDiff(event.getChecked(), cartridge,
embedCartridgeStrategy);
+
+ if (diff.hasChanges()) {
+ if (MessageDialog
+ .openQuestion(getShell(),
+ NLS.bind("{0} Cartridges", event.getChecked() ? "Add" :
"Remove"),
+ createEmbeddingOperationMessage(event.getChecked(), diff))) {
+ createApplications(diff.getApplicationAdditions());
+ unselectEmbeddableCartridges(diff.getRemovals());
+ selectEmbeddableCartridges(diff.getAdditions());
+ } else {
+ if (event.getChecked()) {
+ pageModel.unselectEmbeddedCartridges(cartridge);
+ } else {
+ pageModel.selectEmbeddedCartridges(cartridge);
+ }
+ }
+ }
+
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
+ } catch (SocketTimeoutException e) {
+ OpenShiftUIActivator.log("Could not process embeddable cartridges", e);
+ }
+ }
+
+ private EmbeddableCartridgeDiff createEmbeddableCartridgeDiff(
+ boolean add, IEmbeddableCartridge cartridge, EmbedCartridgeStrategy
embedCartridgeStrategy)
+ throws OpenShiftException, SocketTimeoutException {
+ if (add) {
+ return embedCartridgeStrategy.add(cartridge,
pageModel.getSelectedEmbeddableCartridges());
+ } else {
+ return embedCartridgeStrategy.remove(cartridge,
pageModel.getSelectedEmbeddableCartridges());
+ }
+ }
+
+ private String createEmbeddingOperationMessage(boolean adding,
EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(NLS.bind("If you want {0} {1}, you also have to:", adding ?
"add" : "remove",
+ new EmbeddableCartridgeToStringConverter().toString(diff.getCartridge())));
+ if (diff.hasApplicationAdditions()) {
+ builder.append(NLS.bind("\n- Create {0}",
+ StringUtils.toString(diff.getApplicationAdditions(), new
CartridgeToStringConverter())));
+ }
+ if (diff.hasRemovals()) {
+ builder.append(NLS.bind("\n- Remove {0}",
+ StringUtils.toString(diff.getRemovals(), new
EmbeddableCartridgeToStringConverter())));
+ }
+ if (diff.hasAdditions()) {
+ builder.append(NLS.bind("\n- Add {0}",
+ StringUtils.toString(diff.getAdditions(), new
EmbeddableCartridgeToStringConverter())));
+ }
+ builder.append("\n\nShall we proceed with these modifications?");
+ return builder.toString();
+ }
+
+ private void unselectEmbeddableCartridges(List<IEmbeddableCartridge> removals)
throws SocketTimeoutException,
+ OpenShiftException {
+ for (IEmbeddableCartridge embeddableCartridge : removals) {
+ pageModel.unselectEmbeddedCartridges(embeddableCartridge);
+ }
+ }
+
+ private void selectEmbeddableCartridges(List<IEmbeddableCartridge> additions)
throws SocketTimeoutException,
+ OpenShiftException {
+ for (IEmbeddableCartridge embeddableCartridge : additions) {
+ pageModel.selectEmbeddedCartridges(embeddableCartridge);
+ }
+ }
+
+ private void createApplications(List<ICartridge> applicationAdditions) {
+ for (ICartridge cartridge : applicationAdditions) {
+ if (!ICartridge.JENKINS_14.equals(cartridge)) {
+ throw new UnsupportedOperationException("only jenkins applications may currently
be created.");
+ }
+ createJenkinsApplication(cartridge);
+ }
+ }
+
+ private void createJenkinsApplication(final ICartridge cartridge) {
+ final String name = openJenkinsApplicationDialog();
+ try {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application
\"{0}\"...", name)) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ IApplication application = pageModel.createJenkinsApplication(name, monitor);
+ openLogDialog(application);
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ try {
+ // TODO: unselect failed embeddable cartridge
+ // pageModel.unselectEmbeddedCartridges(cartridge);
+ } catch (Exception ex) {
+ OpenShiftUIActivator.log(ex);
+ }
+ return OpenShiftUIActivator.createErrorStatus("Could not create application
{0}", e);
+ }
+ }
+
+ }, getContainer());
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ private String openJenkinsApplicationDialog() {
+ final JenkinsApplicationDialog dialog = new JenkinsApplicationDialog(getShell());
+ if (dialog.open() != Dialog.OK) {
+ return null;
+ }
+ return dialog.getValue();
+ }
+
+ private Shell getShell() {
+ return wizardPage.getControl().getShell();
+ }
+
+ private IWizardContainer getContainer() {
+ return wizardPage.getWizard().getContainer();
+ }
+
+ private void openLogDialog(final IApplication application) {
+ wizardPage.getControl().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ new CreationLogDialog(getShell(), application).open();
+ }
+ });
+ }
+
+ private static class JenkinsApplicationDialog extends InputDialog {
+
+ public JenkinsApplicationDialog(Shell shell) {
+ super(
+ shell,
+ "New Jenkins application",
+ "To embed Jenkins into your application, you first have to create a separate
Jenkins application. "
+ + "Please provide a name for this new Jenkins application (lower-case letters
and digits only):"
+ , null, new JenkinsNameValidator());
+ }
+
+ private static class JenkinsNameValidator implements IInputValidator {
+
+ @Override
+ public String isValid(String input) {
+ if (StringUtils.isEmpty(input)) {
+ return "You have to provide a name for the jenkins application";
+ }
+
+ if (!StringUtils.isAlphaNumeric(input)) {
+ return "The name may only contain lower-case letters and digits.";
+ }
+ return null;
+ }
+ }
+ }
+
+ private static class EmbeddableCartridgeToStringConverter implements
ToStringConverter<IEmbeddableCartridge> {
+
+ @Override
+ public String toString(IEmbeddableCartridge cartridge) {
+ if (cartridge == null) {
+ return null;
+ }
+ return cartridge.getName();
+ }
+ }
+
+ private static class CartridgeToStringConverter implements
ToStringConverter<ICartridge> {
+
+ @Override
+ public String toString(ICartridge cartridge) {
+ if (cartridge == null) {
+ return null;
+ }
+ return cartridge.getName();
+ }
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeStrategyAdapter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -19,7 +19,6 @@
import java.util.concurrent.TimeUnit;
import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.UpdateSetStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -71,7 +70,7 @@
Group embedGroup = new Group(parent, SWT.NONE);
embedGroup.setText("Embeddable Cartridges");
GridDataFactory.fillDefaults()
- .hint(200, 200).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(embedGroup);
+ .hint(200, 300).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(embedGroup);
GridLayoutFactory.fillDefaults()
.numColumns(3).margins(6, 6).applyTo(embedGroup);
@@ -79,15 +78,12 @@
this.viewer = createTable(tableContainer);
GridDataFactory.fillDefaults()
.span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
-// viewer.addCheckStateListener(new EmbedCartridgeStrategy(viewer, pageModel, this));
dbc.bindSet(
ViewerProperties.checkedElements(IEmbeddableCartridge.class).observe(viewer),
BeanProperties.set(
EmbedCartridgeWizardPageModel.PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES)
- .observe(pageModel),
- new UpdateSetStrategy(UpdateSetStrategy.POLICY_NEVER),
- null);
- viewer.addCheckStateListener(new EmbedCartridgeStrategy(pageModel, this));
+ .observe(pageModel));;
+ viewer.addCheckStateListener(new EmbedCartridgeStrategyAdapter(pageModel, this));
// hiding buttons for now:
https://issues.jboss.org/browse/JBIDE-10399
// Button checkAllButton = new Button(embedGroup, SWT.PUSH);
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -12,7 +12,6 @@
import java.net.SocketTimeoutException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -54,7 +53,7 @@
|| application.getEmbeddedCartridges() == null) {
return;
}
- selectedCartridges.addAll(application.getEmbeddedCartridges());
+ setSelectedEmbeddableCartridges(application.getEmbeddedCartridges());
}
public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws
OpenShiftException, SocketTimeoutException {
@@ -80,14 +79,16 @@
return selectedCartridges;
}
- public void setSelectedEmbeddableCartridges(Set<IEmbeddableCartridge> cartridges)
throws SocketTimeoutException, OpenShiftException {
- setSelectedEmbeddableCartridges(cartridges);
+ protected void setSelectedEmbeddableCartridges(List<? extends
IEmbeddableCartridge> cartridges) throws SocketTimeoutException, OpenShiftException {
+ setSelectedEmbeddableCartridges(new HashSet<IEmbeddableCartridge>(cartridges));
}
-
- protected void setSelectedEmbeddedCartridges(Collection<IEmbeddedCartridge>
cartridges) throws SocketTimeoutException, OpenShiftException {
- Set<IEmbeddableCartridge> oldValue = getSelectedEmbeddableCartridges();
- selectedCartridges.clear();
- selectedCartridges.addAll(cartridges);
+
+ public void setSelectedEmbeddableCartridges(Set<IEmbeddableCartridge> cartridges)
throws SocketTimeoutException, OpenShiftException {
+ Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
+ if (cartridges != selectedCartridges) {
+ selectedCartridges.clear();
+ selectedCartridges.addAll(cartridges);
+ }
firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
selectedCartridges);
}
@@ -99,6 +100,7 @@
return wizardModel.getUser().hasApplicationOfType(cartridge);
}
+ @Override
public IApplication getApplication() {
return wizardModel.getApplication();
}
@@ -106,23 +108,21 @@
@Override
public void selectEmbeddedCartridges(IEmbeddableCartridge cartridge)
throws OpenShiftException,SocketTimeoutException {
- Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
getSelectedEmbeddableCartridges().add(cartridge);
- firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
getSelectedEmbeddableCartridges());
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, null,
getSelectedEmbeddableCartridges());
}
@Override
public void unselectEmbeddedCartridges(IEmbeddableCartridge cartridge)
throws OpenShiftException,SocketTimeoutException {
- Set<IEmbeddableCartridge> oldValue = new
HashSet<IEmbeddableCartridge>(getSelectedEmbeddableCartridges());
getSelectedEmbeddableCartridges().remove(cartridge);
- firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, oldValue,
getSelectedEmbeddableCartridges());
+ firePropertyChange(PROPERTY_SELECTED_EMBEDDABLE_CARTRIDGES, null,
getSelectedEmbeddableCartridges());
}
public Set<IEmbeddableCartridge> refreshSelectedEmbeddedCartridges()
throws OpenShiftException, SocketTimeoutException {
getApplication().refresh();
- setSelectedEmbeddedCartridges(getApplication().getEmbeddedCartridges());
+ setSelectedEmbeddableCartridges(getApplication().getEmbeddedCartridges());
return getSelectedEmbeddableCartridges();
}
@@ -138,12 +138,7 @@
return new EmbedCartridgesOperation(getApplication())
.execute(new ArrayList<IEmbeddableCartridge>(selectedCartridges), null);
}
-
- @Override
- public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException {
- return wizardModel.getUser().hasApplicationOfType(cartridge);
- }
-
+
public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException {
IApplication application =
new CreateApplicationOperation(wizardModel.getUser()).execute(
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/IEmbedCartridgesWizardPageModel.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -16,7 +16,6 @@
import org.eclipse.core.runtime.IProgressMonitor;
import com.openshift.client.IApplication;
-import com.openshift.client.ICartridge;
import com.openshift.client.IEmbeddableCartridge;
import com.openshift.client.OpenShiftException;
@@ -37,8 +36,8 @@
public boolean isSelected(IEmbeddableCartridge cartridge) throws OpenShiftException,
SocketTimeoutException;
- public boolean hasApplicationOfType(ICartridge cartridge) throws SocketTimeoutException,
OpenShiftException;
-
+ public IApplication getApplication();
+
public IApplication createJenkinsApplication(String name, IProgressMonitor monitor)
throws OpenShiftException;
}
\ No newline at end of file
Modified:
trunk/openshift/tests/org.jboss.tools.openshift.express.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.express.test/META-INF/MANIFEST.MF 2012-05-15
19:59:04 UTC (rev 41031)
+++
trunk/openshift/tests/org.jboss.tools.openshift.express.test/META-INF/MANIFEST.MF 2012-05-15
20:22:31 UTC (rev 41032)
@@ -5,8 +5,10 @@
Bundle-Version: 2.3.0.qualifier
Bundle-Vendor: JBoss by Red Hat
Require-Bundle: org.jboss.tools.openshift.express.ui;bundle-version="2.3.0",
+ org.jboss.tools.openshift.express.client;bundle-version="2.3.0",
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)",
org.eclipse.core.filesystem;bundle-version="1.3.100",
- org.junit;bundle-version="[4.8.2,5.0.0)"
+ org.junit;bundle-version="[4.8.2,5.0.0)",
+ com.jcraft.jsch;bundle-version="[0.1.44,1.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Added:
trunk/openshift/tests/org.jboss.tools.openshift.express.test/src/org/jboss/tools/openshift/express/test/EmbedCartridgeStrategyTest.java
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.express.test/src/org/jboss/tools/openshift/express/test/EmbedCartridgeStrategyTest.java
(rev 0)
+++
trunk/openshift/tests/org.jboss.tools.openshift.express.test/src/org/jboss/tools/openshift/express/test/EmbedCartridgeStrategyTest.java 2012-05-15
20:22:31 UTC (rev 41032)
@@ -0,0 +1,630 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.test;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.tools.openshift.express.internal.core.EmbedCartridgeStrategy;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.jcraft.jsch.Session;
+import com.openshift.client.ApplicationScale;
+import com.openshift.client.IApplication;
+import com.openshift.client.IApplicationGear;
+import com.openshift.client.IApplicationPortForwarding;
+import com.openshift.client.ICartridge;
+import com.openshift.client.IDomain;
+import com.openshift.client.IEmbeddableCartridge;
+import com.openshift.client.IEmbeddedCartridge;
+import com.openshift.client.IGearProfile;
+import com.openshift.client.IUser;
+import com.openshift.client.OpenShiftException;
+import com.openshift.client.OpenShiftSSHOperationException;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class EmbedCartridgeStrategyTest {
+
+ private EmbedCartridgeStrategy embedStrategy;
+ private DomainFake domainFake;
+
+ @Before
+ public void setUp() throws SocketTimeoutException, OpenShiftException {
+ this.domainFake = new DomainFake();
+ IApplication applicationFake = domainFake.createApplication("adietish",
ICartridge.JBOSSAS_7);
+ this.embedStrategy = new EmbedCartridgeStrategy(applicationFake);
+ }
+
+ @Test
+ public void shouldNotAddMySql() throws SocketTimeoutException, OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges = new
HashSet<IEmbeddableCartridge>();
+ currentCartridges.add(IEmbeddableCartridge.MYSQL_51);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.MYSQL_51, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.MYSQL_51, diff.getCartridge());
+ assertFalse(diff.hasAdditions());
+ assertFalse(diff.hasRemovals());
+ assertFalse(diff.hasApplicationAdditions());
+ }
+
+ @Test
+ public void shouldAddMySql() throws SocketTimeoutException, OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges =
Collections.<IEmbeddableCartridge>emptySet();
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.MYSQL_51, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.MYSQL_51, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 0);
+ }
+
+ @Test
+ public void shouldAddPhpMyAdminAndMySql() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges =
Collections.<IEmbeddableCartridge>emptySet();
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.PHPMYADMIN_34, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.PHPMYADMIN_34, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 1);
+ assertEquals(IEmbeddableCartridge.MYSQL_51, diff.getAdditions().get(0));
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 0);
+ }
+
+ @Test
+ public void shouldRemovePhpMyAdmin() throws SocketTimeoutException, OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges = new
HashSet<IEmbeddableCartridge>();
+ currentCartridges.add(IEmbeddableCartridge.MYSQL_51);
+ currentCartridges.add(IEmbeddableCartridge.PHPMYADMIN_34);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.remove(IEmbeddableCartridge.PHPMYADMIN_34, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.PHPMYADMIN_34, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 0);
+ }
+
+ @Test
+ public void shouldRemovePhpMyAdminAndMySql() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges = new
HashSet<IEmbeddableCartridge>();
+ currentCartridges.add(IEmbeddableCartridge.MYSQL_51);
+ currentCartridges.add(IEmbeddableCartridge.PHPMYADMIN_34);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.remove(IEmbeddableCartridge.MYSQL_51, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.MYSQL_51, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 1);
+ assertTrue(diff.getRemovals().contains(IEmbeddableCartridge.PHPMYADMIN_34));
+ }
+
+ @Test
+ public void shouldRemovePostgresAndAddMySql() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges = new
HashSet<IEmbeddableCartridge>();
+ currentCartridges.add(IEmbeddableCartridge.POSTGRESQL_84);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.MYSQL_51, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.MYSQL_51, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 1);
+ assertEquals(IEmbeddableCartridge.POSTGRESQL_84, diff.getRemovals().get(0));
+ }
+
+ @Test
+ public void shouldRemovePostgresAndAddPhpMyAdminAndMySql() throws
SocketTimeoutException, OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges = new
HashSet<IEmbeddableCartridge>();
+ currentCartridges.add(IEmbeddableCartridge.POSTGRESQL_84);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.PHPMYADMIN_34, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.PHPMYADMIN_34, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 1);
+ assertEquals(IEmbeddableCartridge.MYSQL_51, diff.getAdditions().get(0));
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 1);
+ assertEquals(IEmbeddableCartridge.POSTGRESQL_84, diff.getRemovals().get(0));
+ }
+
+ @Test
+ public void shouldAddRockmongoAndMongoDb() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges =
Collections.<IEmbeddableCartridge>emptySet();
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.ROCKMONGO_11, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.ROCKMONGO_11, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 1);
+ assertEquals(IEmbeddableCartridge.MONGODB_20, diff.getAdditions().get(0));
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 0);
+ }
+
+ @Test
+ public void shouldRemoveRockmongoAnd10genAndMongoDb() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges = new
HashSet<IEmbeddableCartridge>();
+ currentCartridges.add(IEmbeddableCartridge.MONGODB_20);
+ currentCartridges.add(IEmbeddableCartridge.ROCKMONGO_11);
+ currentCartridges.add(IEmbeddableCartridge._10GEN_MMS_AGENT_01);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.remove(IEmbeddableCartridge.MONGODB_20, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.MONGODB_20, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 2);
+ assertTrue(diff.getRemovals().contains(IEmbeddableCartridge.ROCKMONGO_11));
+ assertTrue(diff.getRemovals().contains(IEmbeddableCartridge._10GEN_MMS_AGENT_01));
+ }
+
+ @Test
+ public void shouldNotAddJenkinsApplication() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges =
Collections.<IEmbeddableCartridge>emptySet();
+ domainFake.createApplication("adietish", ICartridge.JENKINS_14);
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.JENKINS_14, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.JENKINS_14, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 0);
+ assertNotNull(diff.getApplicationAdditions());
+ assertTrue(diff.getApplicationAdditions().size() == 0);
+ }
+
+ @Test
+ public void shouldAddJenkinsApplication() throws SocketTimeoutException,
OpenShiftException{
+ // given
+ Set<IEmbeddableCartridge> currentCartridges =
Collections.<IEmbeddableCartridge>emptySet();
+
+ // when
+ EmbedCartridgeStrategy.EmbeddableCartridgeDiff diff =
embedStrategy.add(IEmbeddableCartridge.JENKINS_14, currentCartridges);
+
+ // then
+ assertEquals(IEmbeddableCartridge.JENKINS_14, diff.getCartridge());
+ assertNotNull(diff.getAdditions());
+ assertTrue(diff.getAdditions().size() == 0);
+ assertNotNull(diff.getRemovals());
+ assertTrue(diff.getRemovals().size() == 0);
+ assertNotNull(diff.getApplicationAdditions());
+ assertTrue(diff.getApplicationAdditions().size() == 1);
+ assertTrue(diff.getApplicationAdditions().contains(ICartridge.JENKINS_14));
+ }
+
+ private static final class ApplicationFake implements IApplication {
+
+ private ICartridge cartridge;
+ private IDomain domain;
+
+ public ApplicationFake(ICartridge cartridge, IDomain domain) {
+ this.cartridge = cartridge;
+ this.domain = domain;
+ }
+
+ @Override
+ public String getCreationLog() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasCreationLog() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getName() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getUUID() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getGitUrl() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getApplicationUrl() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ApplicationScale getApplicationScale() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IGearProfile getGearProfile() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getHealthCheckUrl() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ICartridge getCartridge() {
+ return cartridge;
+ }
+
+ @Override
+ public IEmbeddedCartridge addEmbeddableCartridge(IEmbeddableCartridge cartridge)
+ throws OpenShiftException,SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IEmbeddedCartridge>
addEmbeddableCartridges(List<IEmbeddableCartridge> cartridge)
+ throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IEmbeddedCartridge> getEmbeddedCartridges() throws
OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasEmbeddedCartridge(IEmbeddableCartridge cartridge)
+ throws OpenShiftException,SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasEmbeddedCartridge(String cartridgeName) throws OpenShiftException,
SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IEmbeddedCartridge getEmbeddedCartridge(String cartridgeName)
+ throws OpenShiftException,SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IEmbeddedCartridge getEmbeddedCartridge(IEmbeddableCartridge cartridge)
+ throws OpenShiftException,SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeEmbeddedCartridge(IEmbeddableCartridge cartridge) throws
OpenShiftException,
+ SocketTimeoutException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public List<IApplicationGear> getGears() throws OpenShiftException,
SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Date getCreationTime() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void destroy() throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void start() throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void restart() throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void stop() throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void stop(boolean force) throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean waitForAccessible(long timeout) throws OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IDomain getDomain() {
+ return domain;
+ }
+
+ @Override
+ public void exposePort() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void concealPort() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void showPort() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void scaleDown() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void scaleUp() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void addAlias(String string) throws SocketTimeoutException, OpenShiftException
{
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<String> getAliases() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasAlias(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void removeAlias(String alias) throws SocketTimeoutException, OpenShiftException
{
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void refresh() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasSSHSession() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isPortFowardingStarted() throws OpenShiftSSHOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IApplicationPortForwarding> getForwardablePorts() throws
OpenShiftSSHOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IApplicationPortForwarding> startPortForwarding() throws
OpenShiftSSHOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IApplicationPortForwarding> stopPortForwarding() throws
OpenShiftSSHOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IApplicationPortForwarding> refreshForwardablePorts() throws
OpenShiftSSHOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<String> getEnvironmentProperties() throws
OpenShiftSSHOperationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setSSHSession(Session session) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Session getSSHSession() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private static final class DomainFake implements IDomain {
+
+ private List<IApplication> applications;
+
+ public DomainFake() {
+ this.applications = new ArrayList<IApplication>();
+ }
+
+ @Override
+ public String getCreationLog() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasCreationLog() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void refresh() throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getId() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getSuffix() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void rename(String id) throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IUser getUser() throws SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void destroy() throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void destroy(boolean force) throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean waitForAccessible(long timeout) throws OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IApplication createApplication(String name, ICartridge cartridge,
ApplicationScale scale,
+ IGearProfile gearProfile) throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IApplication createApplication(String name, ICartridge cartridge,
ApplicationScale scale)
+ throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IApplication createApplication(String name, ICartridge cartridge, IGearProfile
gearProfile)
+ throws OpenShiftException, SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IApplication createApplication(String name, ICartridge cartridge) {
+ IApplication application = new ApplicationFake(cartridge, this);
+ applications.add(application);
+ return application;
+ }
+
+ @Override
+ public List<IApplication> getApplications() throws OpenShiftException,
SocketTimeoutException {
+ return applications;
+ }
+
+ @Override
+ public List<String> getAvailableCartridgeNames() throws OpenShiftException,
SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IApplication getApplicationByName(String name) throws OpenShiftException,
SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean hasApplicationByName(String name) throws OpenShiftException,
SocketTimeoutException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<IApplication> getApplicationsByCartridge(ICartridge cartridge) throws
OpenShiftException {
+ List<IApplication> matchingApplications = new ArrayList<IApplication>();
+ for (IApplication application : applications) {
+ if (cartridge.equals(application.getCartridge())) {
+ matchingApplications.add(application);
+ break;
+ }
+ }
+ return matchingApplications;
+ }
+
+ @Override
+ public boolean hasApplicationByCartridge(ICartridge cartridge) throws
OpenShiftException {
+ return getApplicationsByCartridge(cartridge).size() > 0;
+ }
+
+ @Override
+ public List<IGearProfile> getAvailableGearProfiles() throws
SocketTimeoutException, OpenShiftException {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
Property changes on:
trunk/openshift/tests/org.jboss.tools.openshift.express.test/src/org/jboss/tools/openshift/express/test/EmbedCartridgeStrategyTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain