Skip to content

Commit

Permalink
add gear_groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bdecoste committed Mar 21, 2013
1 parent 7073708 commit b64d63f
Show file tree
Hide file tree
Showing 19 changed files with 554 additions and 265 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/openshift/client/IApplication.java
Expand Up @@ -419,4 +419,6 @@ public void removeEmbeddedCartridges(ICartridgeConstraint cartridgeConstraint)
public List<String> getEnvironmentProperties() throws OpenShiftSSHOperationException;

public String getCartridge(String cartridgeName) throws OpenShiftException;

public List<IGearGroup> getGearGroups() throws OpenShiftException;
}
24 changes: 24 additions & 0 deletions src/main/java/com/openshift/client/IGear.java
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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 com.openshift.client;

/**
* @author Andre Dietisheim
*/
public interface IGear {

public String getName();

public String getUuid();

public String getState();

}
26 changes: 26 additions & 0 deletions src/main/java/com/openshift/client/IGearGroup.java
@@ -0,0 +1,26 @@
/*******************************************************************************
* 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 com.openshift.client;

import java.util.List;

/**
* @author Andre Dietisheim
*/
public interface IGearGroup {

public String getName();

public List<IGear> getGears();

public String getGearProfile();

}
Expand Up @@ -122,11 +122,13 @@ protected ServiceRequest(String linkName) {
protected <DTO> DTO execute(ServiceParameter... parameters) throws OpenShiftException {
Link link = getLink(linkName);
RestResponse response = getService().request(link, parameters);

// in some cases, there is not response body, just a return code to
// indicate that the operation was successful (e.g.: delete domain)
if (response == null) {
return null;
}

return response.getData();
}

Expand Down
Expand Up @@ -42,14 +42,17 @@
import com.openshift.client.IDomain;
import com.openshift.client.IEmbeddableCartridge;
import com.openshift.client.IEmbeddedCartridge;
import com.openshift.client.IGearGroup;
import com.openshift.client.IGearProfile;
import com.openshift.client.IOpenShiftConnection;
import com.openshift.client.OpenShiftException;
import com.openshift.client.OpenShiftSSHOperationException;
import com.openshift.client.utils.HostUtils;
import com.openshift.client.utils.RFC822DateUtils;
import com.openshift.internal.client.AbstractOpenShiftResource.ServiceRequest;
import com.openshift.internal.client.response.ApplicationResourceDTO;
import com.openshift.internal.client.response.CartridgeResourceDTO;
import com.openshift.internal.client.response.GearGroupDTO;
import com.openshift.internal.client.response.Link;
import com.openshift.internal.client.response.Message;
import com.openshift.internal.client.ssh.ApplicationPortForwarding;
Expand Down Expand Up @@ -81,6 +84,7 @@ public class ApplicationResource extends AbstractOpenShiftResource implements IA
private static final String LINK_REMOVE_ALIAS = "REMOVE_ALIAS";
private static final String LINK_ADD_CARTRIDGE = "ADD_CARTRIDGE";
private static final String LINK_LIST_CARTRIDGES = "LIST_CARTRIDGES";
private static final String LINK_GET_GEAR_GROUPS = "GET_GEAR_GROUPS";

/** The (unique) uuid of this application. */
private final String uuid;
Expand Down Expand Up @@ -131,6 +135,8 @@ public class ApplicationResource extends AbstractOpenShiftResource implements IA
private Session session;

private Map<String, String> embeddedCartridgesInfos;

private List<IGearGroup> gearGroups;

/**
* Constructor...
Expand All @@ -141,7 +147,7 @@ public class ApplicationResource extends AbstractOpenShiftResource implements IA
*/
protected ApplicationResource(ApplicationResourceDTO dto, ICartridge cartridge, DomainResource domain) {
this(dto.getName(), dto.getUuid(), dto.getCreationTime(), dto.getCreationLog(), dto.getApplicationUrl(), dto
.getGitUrl(), dto.getGearProfile(), dto.getApplicationScale(), cartridge, dto
.getGitUrl(), dto.getGearProfile(), dto.getGearGroups(), dto.getApplicationScale(), cartridge, dto
.getAliases(), dto.getEmbeddedCartridgeInfos(), dto.getLinks(), domain);
}

Expand Down Expand Up @@ -172,7 +178,7 @@ protected ApplicationResource(ApplicationResourceDTO dto, ICartridge cartridge,
*/
protected ApplicationResource(final String name, final String uuid, final String creationTime,
final List<Message> creationLog, final String applicationUrl, final String gitUrl,
final IGearProfile gearProfile, final ApplicationScale scale,
final IGearProfile gearProfile, final List<IGearGroup> gearGroups, final ApplicationScale scale,
final ICartridge cartridge, final List<String> aliases, final Map<String, String> embeddedCartridgesInfos,
final Map<String, Link> links, final DomainResource domain) {
super(domain.getService(), links, creationLog);
Expand All @@ -181,6 +187,7 @@ protected ApplicationResource(final String name, final String uuid, final String
this.creationTime = RFC822DateUtils.safeGetDate(creationTime);
this.scale = scale;
this.gearProfile = gearProfile;
this.gearGroups = gearGroups;
this.cartridge = cartridge;
this.applicationUrl = applicationUrl;
this.gitUrl = gitUrl;
Expand All @@ -190,6 +197,41 @@ protected ApplicationResource(final String name, final String uuid, final String
// https://bugzilla.redhat.com/show_bug.cgi?id=812046 is fixed
this.embeddedCartridgesInfos = embeddedCartridgesInfos;
}

public List<IGearGroup> getGearGroups() throws OpenShiftException {
return CollectionUtils.toUnmodifiableCopy(getOrLoadGearGroups());
}

protected List<IGearGroup> getOrLoadGearGroups() throws OpenShiftException {
if (gearGroups == null) {
this.gearGroups = loadGearGroups();
}
return gearGroups;
}

private List<IGearGroup> loadGearGroups() throws OpenShiftException {
List<IGearGroup> gearGroups = new ArrayList<IGearGroup>();
List<GearGroupDTO> gearGroupDTOs = new ListGearGroupsRequest().execute();
for (GearGroupDTO gearGroupDTO : gearGroupDTOs) {
final IGearGroup gearGroup =
new GearGroupResource(gearGroupDTO, this);
gearGroups.add(gearGroup);
}
return gearGroups;
}

private class ListGearGroupsRequest extends ServiceRequest {

public ListGearGroupsRequest() throws OpenShiftException {
super(LINK_GET_GEAR_GROUPS);
}

public List<GearGroupDTO> execute() throws OpenShiftException {
return super
.execute();
}

}

public String getName() {
return name;
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/com/openshift/internal/client/GearGroupResource.java
@@ -0,0 +1,123 @@
/*******************************************************************************
* 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 com.openshift.internal.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;

import javax.xml.datatype.DatatypeConfigurationException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.openshift.client.ApplicationScale;
import com.openshift.client.IApplication;
import com.openshift.client.IApplicationPortForwarding;
import com.openshift.client.ICartridge;
import com.openshift.client.ICartridgeConstraint;
import com.openshift.client.IDomain;
import com.openshift.client.IEmbeddableCartridge;
import com.openshift.client.IEmbeddedCartridge;
import com.openshift.client.IGear;
import com.openshift.client.IGearGroup;
import com.openshift.client.IGearProfile;
import com.openshift.client.IOpenShiftConnection;
import com.openshift.client.OpenShiftException;
import com.openshift.client.OpenShiftSSHOperationException;
import com.openshift.client.utils.HostUtils;
import com.openshift.client.utils.RFC822DateUtils;
import com.openshift.internal.client.AbstractOpenShiftResource.ServiceRequest;
import com.openshift.internal.client.response.ApplicationResourceDTO;
import com.openshift.internal.client.response.CartridgeResourceDTO;
import com.openshift.internal.client.response.GearDTO;
import com.openshift.internal.client.response.GearGroupDTO;
import com.openshift.internal.client.response.Link;
import com.openshift.internal.client.response.Message;
import com.openshift.internal.client.ssh.ApplicationPortForwarding;
import com.openshift.internal.client.utils.Assert;
import com.openshift.internal.client.utils.CollectionUtils;
import com.openshift.internal.client.utils.IOpenShiftJsonConstants;

/**
* The Class Application.
*
* @author André Dietisheim
*/
public class GearGroupResource extends AbstractOpenShiftResource implements IGearGroup {

private static final Logger LOGGER = LoggerFactory.getLogger(GearGroupResource.class);

private String name;
private String gearProfile;
private List<IGear> gears = new ArrayList<IGear>();

/**
* Constructor...
*
* @param dto
* @param cartridge
* @param domain
*/
protected GearGroupResource(GearGroupDTO dto, ApplicationResource app) {
this(dto.getName(), dto.getGearProfile(), dto.getGears(), app);
}

protected GearGroupResource(String name, String gearProfile, List<GearDTO> dtos, ApplicationResource app) {
super(app.getService());
this.name = name;
this.gearProfile = gearProfile;
for (GearDTO gear : dtos) {
gears.add(new GearResource(gear, this));
}
}


@Override
public List<IGear> getGears() {
// TODO Auto-generated method stub
return gears;
}

@Override
public void refresh() throws OpenShiftException {
// TODO Auto-generated method stub

}


@Override
public String getName() {
// TODO Auto-generated method stub
return name;
}

@Override
public String getGearProfile() {
// TODO Auto-generated method stub
return gearProfile;
}
}

0 comments on commit b64d63f

Please sign in to comment.