Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/java/com/openshift/client/IApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.openshift.client.cartridge.ICartridge;
import com.openshift.client.cartridge.IDeployedStandaloneCartridge;
import com.openshift.client.cartridge.IEmbeddableCartridge;
import com.openshift.client.cartridge.IEmbeddedCartridge;
import com.openshift.client.cartridge.IStandaloneCartridge;
import com.openshift.internal.client.ApplicationResource;

/**
* @author André Dietisheim
* @author Syed Iqbal
* @author Martes G Wigglesworth
* @author Jeff Cantrill
*/
public interface IApplication extends IOpenShiftResource {

Expand Down Expand Up @@ -67,9 +68,11 @@ public interface IApplication extends IOpenShiftResource {
* @return the initial git url
*/
public String getInitialGitUrl();

/**
* Returns the deployment type for this application. Either "binary" or "git" currently.
* Returns the deployment type for this application. Either "binary" or
* "git" currently.
*
* @return "binary" or "git"
*/
public String getDeploymentType();
Expand Down Expand Up @@ -105,7 +108,7 @@ public interface IApplication extends IOpenShiftResource {
* @return the cartridge of this application
*
*/
public IStandaloneCartridge getCartridge();
public IDeployedStandaloneCartridge getCartridge();

/**
* Adds the given embeddable cartridge to this application.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/openshift/client/IGearGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

public interface IGearGroup {

public static final int NO_ADDITIONAL_GEAR_STORAGE = -1;

/**
* Returns the uuid of this gear groups.
*
Expand Down Expand Up @@ -43,4 +45,12 @@ public interface IGearGroup {
* @return the gears
*/
public Collection<ICartridge> getCartridges();

/**
* Returns the additional storage configured for this gear group in gigabytes
*
* @return the additional storage value
*/
public int getAdditionalStorage();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2014 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 com.openshift.client.cartridge;

import com.openshift.client.IGearGroup;

/**
* Represents a standalone cartridge that has been deployed as opposed to IStandaloneCartridge
* which really represents the metadata about a standalone cartridge
*
* @author Jeff Cantrill
* @author Andre Dietisheim
*/
public interface IDeployedStandaloneCartridge extends IStandaloneCartridge{

/**
* set the additional gear storage for the cartridge to the given
* size.
*
* @param size The total additional gear storage for the cartridge
* in gigabytes
*/
public void setAdditionalGearStorage(int size);

/**
* Returns the additional gear storage for this cartridge
* @return
*/
public int getAdditionalGearStorage();

/**
* Returns the gear group that this cartridge is deployed on
* @return
*/
public IGearGroup getGearGroup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,19 @@
******************************************************************************/
package com.openshift.client.cartridge;

import java.net.URL;

import com.openshift.client.IApplication;
import com.openshift.client.IOpenShiftResource;
import com.openshift.client.OpenShiftException;
import com.openshift.internal.client.response.CartridgeResourceProperties;

/**
* Interface to designate a cartridge that has been added and configured
*
* @author André Dietisheim
* @author Jeff Cantrill
*/
public interface IEmbeddedCartridge extends IOpenShiftResource, IEmbeddableCartridge {

/**
* The url at which this cartridge may be reached
*
* @return the url for this cartridge
* @throws OpenShiftException
*/
public URL getUrl() throws OpenShiftException;

/**
* Destroys this cartridge (and removes it from the list of existing cartridges)
*
Expand All @@ -52,4 +44,13 @@ public interface IEmbeddedCartridge extends IOpenShiftResource, IEmbeddableCartr
* @return the resource properties
*/
public CartridgeResourceProperties getProperties();

/**
* set the additional gear storage for the cartridge to the given
* size.
*
* @param size The total additional gear storage for the cartridge
* in gigabytes
*/
public void setAdditionalGearStorage(int size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import com.openshift.internal.client.CartridgeType;
import com.openshift.internal.client.cartridge.BaseCartridge;


/**
* A cartridge that is available on the openshift server. This class is no enum
* since we dont know all available types and they may change at any time.
*
* @author André Dietisheim
* @author Jeff Cantrill
*/
public class StandaloneCartridge extends BaseCartridge implements IStandaloneCartridge {

Expand Down Expand Up @@ -56,8 +56,39 @@ public StandaloneCartridge(String name, URL url, String displayName, String desc
super(name, url, displayName, description);
}

public StandaloneCartridge(String name, URL url, String displayName, String description) {
this(name, url, displayName, description, false);
}

@Override
public CartridgeType getType() {
return CartridgeType.STANDALONE;
}
}

@Override
public boolean equals(Object obj) {
if (!(IStandaloneCartridge.class.isAssignableFrom(obj.getClass()))) {
return super.equals(obj);
}

IStandaloneCartridge otherCartridge = (IStandaloneCartridge) obj;
// shortcut: downloadable cartridges get their name only when
// they're deployed thus should equal on url only
if (isDownloadable()) {
if (otherCartridge.isDownloadable()) {
if (getUrl() == null) {
return otherCartridge.getUrl() == null;
}
return getUrl().equals(otherCartridge.getUrl());
}
}
if (getName() == null) {
if (otherCartridge.getName() != null) {
return false;
}
} else if (!getName().equals(otherCartridge.getName())) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@
import com.openshift.client.OpenShiftException;
import com.openshift.client.OpenShiftSSHOperationException;
import com.openshift.client.cartridge.ICartridge;
import com.openshift.client.cartridge.IDeployedStandaloneCartridge;
import com.openshift.client.cartridge.IEmbeddableCartridge;
import com.openshift.client.cartridge.IEmbeddedCartridge;
import com.openshift.client.cartridge.IStandaloneCartridge;
import com.openshift.client.cartridge.StandaloneCartridge;
import com.openshift.client.utils.HostUtils;
import com.openshift.client.utils.RFC822DateUtils;
import com.openshift.internal.client.httpclient.request.StringParameter;
Expand All @@ -73,6 +72,7 @@
* @author André Dietisheim
* @author Syed Iqbal
* @author Martes G Wigglesworth
* @author Jeff Cantrill
*/
public class ApplicationResource extends AbstractOpenShiftResource implements IApplication {

Expand Down Expand Up @@ -107,7 +107,7 @@ public class ApplicationResource extends AbstractOpenShiftResource implements IA
private Date creationTime;

/** The cartridge (application type/framework) of this application. */
private IStandaloneCartridge cartridge;
private IDeployedStandaloneCartridge cartridge;

/** The scalability enablement. */
private ApplicationScale scale;
Expand Down Expand Up @@ -235,7 +235,7 @@ public String getUUID() {
}

@Override
public IStandaloneCartridge getCartridge() {
public IDeployedStandaloneCartridge getCartridge() {
return cartridge;
}

Expand Down Expand Up @@ -449,7 +449,7 @@ private void updateCartridges(Map<String, CartridgeResourceDTO> cartridgeDTOByNa
for (CartridgeResourceDTO cartridgeDTO : cartridgeDTOByName.values()) {
switch(cartridgeDTO.getType()) {
case STANDALONE:
createStandaloneCartrdige(cartridgeDTO);
createStandaloneCartridge(cartridgeDTO);
break;
case EMBEDDED:
addOrUpdateEmbeddedCartridge(cartridgeDTO.getName(), cartridgeDTO);
Expand All @@ -460,13 +460,8 @@ private void updateCartridges(Map<String, CartridgeResourceDTO> cartridgeDTOByNa
}
}

private void createStandaloneCartrdige(CartridgeResourceDTO cartridgeDTO) {
this.cartridge = new StandaloneCartridge(
cartridgeDTO.getName(),
cartridgeDTO.getUrl(),
cartridgeDTO.getDisplayName(),
cartridgeDTO.getDescription(),
cartridgeDTO.getObsolete());
private void createStandaloneCartridge(CartridgeResourceDTO dto) {
this.cartridge = new StandaloneCartridgeResource(dto,this);
}

private void addOrUpdateEmbeddedCartridge(String name, CartridgeResourceDTO cartridgeDTO) {
Expand Down Expand Up @@ -544,13 +539,37 @@ public void removeEmbeddedCartridges(Collection<IEmbeddableCartridge> cartridges
}
}

@Override
public Collection<IGearGroup> getGearGroups() throws OpenShiftException {
// this collection is not cached so we always have the latest info
// about the gear groups consumed by this application.
loadGearGroups();
return gearGroups;
}

public IGearGroup getGearGroup(ICartridge cartridge) throws OpenShiftException {
// this collection is not cached so we always have the latest info
// about the gear groups consumed by this application.
loadGearGroups();
return getGearGroup(cartridge, gearGroups);
}

public IGearGroup getGearGroup(ICartridge cartridge, Collection<IGearGroup> gearGroups) {
if (cartridge == null
|| gearGroups == null) {
return null;
}

for (IGearGroup gearGroup : gearGroups) {
for (ICartridge groupCartridge : gearGroup.getCartridges()) {
if (cartridge.equals(cartridge)) {
return gearGroup;
}
}
}
return null;
}

private Collection<IGearGroup> loadGearGroups() throws OpenShiftException {
List<IGearGroup> gearGroups = new ArrayList<IGearGroup>();
Collection<GearGroupResourceDTO> dtos = new GetGearGroupsRequest().execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import com.openshift.client.cartridge.EmbeddableCartridge;
import com.openshift.client.cartridge.IEmbeddableCartridge;
import com.openshift.client.cartridge.IEmbeddedCartridge;
import com.openshift.internal.client.httpclient.request.Parameter;
import com.openshift.internal.client.response.CartridgeResourceDTO;
import com.openshift.internal.client.response.CartridgeResourceProperties;
import com.openshift.internal.client.utils.IOpenShiftJsonConstants;

/**
* A cartridge that is embedded into an application.
Expand All @@ -28,6 +30,7 @@
public class EmbeddedCartridgeResource extends AbstractOpenShiftResource implements IEmbeddedCartridge {

private static final String LINK_DELETE_CARTRIDGE = "DELETE";
private static final String LINK_UPDATE_CARTRIDGE = "UPDATE";

private final String name;
private String displayName;
Expand Down Expand Up @@ -98,6 +101,16 @@ protected void update(CartridgeResourceDTO dto) {
setLinks(dto.getLinks());
}

/**
* Update the additional gear storage for this cartridge to the given value
*
* @param size The total size of storage in gigabytes for the gear
*/
@Override
public void setAdditionalGearStorage(int size) {
new UpdateCartridgeRequest().execute(new Parameter(IOpenShiftJsonConstants.PROPERTY_ADDITIONAL_GEAR_STORAGE, String.valueOf(size)));

}
/**
* Refreshes the content of this embedded cartridge. Causes all embedded
* cartridges of the same application to get updated.
Expand Down Expand Up @@ -137,18 +150,24 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (!(IEmbeddableCartridge.class.isAssignableFrom(obj.getClass())))
}
if (!(IEmbeddableCartridge.class.isAssignableFrom(obj.getClass()))) {
return false;
}
IEmbeddableCartridge other = (IEmbeddableCartridge) obj;
if (name == null) {
if (other.getName() != null)
if (other.getName() != null) {
return false;
} else if (!name.equals(other.getName()))
}
}
if (!name.equals(other.getName())) {
return false;
}
return true;
}

Expand All @@ -170,4 +189,9 @@ private DeleteCartridgeRequest() {
super(LINK_DELETE_CARTRIDGE);
}
}
private class UpdateCartridgeRequest extends ServiceRequest {
private UpdateCartridgeRequest() {
super(LINK_UPDATE_CARTRIDGE);
}
}
}
Loading