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
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private Map<String, String> getTypeMappings(String apiVersion){
if(typeMappings.isEmpty()){
//OpenShift endpoints
final String version = StringUtils.defaultIfEmpty(apiVersion, getOpenShiftAPIVersion());
final String osEndpoint = String.format("%s/%s", OpenShiftAPIVersion.v1beta3.toString().equals(version) ? OS_API_LEGACY_ENDPOINT : OS_API_ENDPOINT, version);
final String osEndpoint = String.format("%s/%s", OS_API_ENDPOINT, version);
typeMappings.put(ResourceKind.BUILD, osEndpoint);
typeMappings.put(ResourceKind.BUILD_CONFIG, osEndpoint);
typeMappings.put(ResourceKind.DEPLOYMENT_CONFIG, osEndpoint);
Expand All @@ -422,7 +422,6 @@ private Map<String, String> getTypeMappings(String apiVersion){
typeMappings.put(ResourceKind.TEMPLATE, osEndpoint);
typeMappings.put(ResourceKind.USER, osEndpoint);
//not real kinds
typeMappings.put(ResourceKind.TEMPLATE_CONFIG, osEndpoint);
typeMappings.put(ResourceKind.PROCESSED_TEMPLATES, osEndpoint);

//Kubernetes endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Jeff Cantrill
*/
public enum KubernetesAPIVersion implements APIModelVersion{
@Deprecated
v1beta3(2),
v1(3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Jeff Cantrill
*/
public enum OpenShiftAPIVersion implements APIModelVersion{
@Deprecated
v1beta3(2),
v1(3);

Expand Down
36 changes: 2 additions & 34 deletions src/main/java/com/openshift/internal/restclient/URLBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class URLBuilder {
kindMap.put(ResourceKind.SECRET, "secrets");
kindMap.put(ResourceKind.SERVICE_ACCOUNT, "serviceaccounts");

kindMap.put(ResourceKind.TEMPLATE_CONFIG, "templateconfig");//mechanism for processing templates pre v1beta3
kindMap.put(ResourceKind.PROCESSED_TEMPLATES, "processedtemplates");//mechanism for processing templates
}

Expand All @@ -81,7 +80,6 @@ public class URLBuilder {

private String namespace;
private String subResource;
private boolean watch;

URLBuilder(URL baseUrl, Map<String, String> typeMappings, IResource resource) {
this(baseUrl, typeMappings);
Expand All @@ -95,11 +93,7 @@ public class URLBuilder {

URLBuilder namespace(String namespace){
if(StringUtils.isBlank(namespace)) return this;
if(typeMappingIsForV1Beta1()) {
addParmeter("namespace", namespace);
}else {
this.namespace = namespace;
}
this.namespace = namespace;
return this;
}

Expand Down Expand Up @@ -145,11 +139,7 @@ URL build() {
if (kind == null)
throw new RuntimeException(
"Unable to build a URL because the ResourceKind is unknown");
if(typeMappingIsForV1Beta1()) {
buildWithNamespaceAsQueryParam(url);
}else {
buildWithNamespaceInPath(url);
}
buildWithNamespaceInPath(url);

try {
if(LOG.isDebugEnabled()) {
Expand All @@ -161,12 +151,6 @@ URL build() {
}
}


private boolean typeMappingIsForV1Beta1() {
String mapping = typeMappings.get(kind);
return mapping.contains("v1beta1");
}

private void buildWithNamespaceInPath(StringBuilder url) {
url.append("/")
.append(typeMappings.get(kind));
Expand All @@ -184,22 +168,6 @@ private void buildWithNamespaceInPath(StringBuilder url) {
url = appendParameters(url);
}

private URL buildWithNamespaceAsQueryParam(StringBuilder url) {
url.append("/")
.append(typeMappings.get(kind)).append("/")
.append(kindMap.get(kind));
if (name != null) {
url.append("/").append(name);
}
url = appendParameters(url);
try {
LOG.debug(String.format("Built url: %s", url.toString()));
return new URL(url.toString());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

private StringBuilder appendParameters(StringBuilder url) {
if (!params.isEmpty()) {
url.append(IHttpClient.QUESTION_MARK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public List<IServicePort> getPorts() {

private List<IServicePort> getPorts(boolean modifiable) {
List<IServicePort> ports = new ArrayList<>();
if(get(SERVICE_PORT).getType() == ModelType.UNDEFINED) return ports;
if(!get(SERVICE_PORT).isDefined()) return ports;
for (ModelNode node : get(SERVICE_PORT).asList()) {
ports.add(new ServicePort(node));
}
Expand Down Expand Up @@ -125,9 +125,9 @@ public void setTargetPort(int port) {
}

@Override
public int getTargetPort() {
public String getTargetPort() {
IServicePort port = getLowestPort();
return port != null ? port.getTargetPort() : 0;
return port != null ? port.getTargetPort() : "0";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jboss.dmr.ModelNode;

import com.openshift.restclient.model.IServicePort;
Expand Down Expand Up @@ -66,15 +67,23 @@ public void setName(String name) {
}

@Override
public int getTargetPort() {
return asInt(getNode(), KEY_MAP, PROPERTY_TARGET_PORT);
public String getTargetPort() {
return asString(getNode(), KEY_MAP, PROPERTY_TARGET_PORT);
}

@Override
public void setTargetPort(int port) {
set(getNode(), KEY_MAP, PROPERTY_TARGET_PORT, port);
}

@Override
public void setTargetPort(String name) {
if(StringUtils.isNumeric(name)) {
setTargetPort((Integer.parseInt(name)));
return;
}
set(getNode(), KEY_MAP, PROPERTY_TARGET_PORT, name);
}

@Override
public void setPort(int port) {
Expand All @@ -101,7 +110,7 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getPort();
result = prime * result + getTargetPort();
result = prime * result + getTargetPort().hashCode();
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getProtocol() == null) ? 0 : getProtocol().hashCode());
return result;
Expand All @@ -118,7 +127,10 @@ public boolean equals(Object obj) {
ServicePort other = (ServicePort) obj;
if (getPort() != other.getPort())
return false;
if (getTargetPort() != other.getTargetPort())
if (getTargetPort() == null) {
if (other.getTargetPort() != null)
return false;
} else if (!getTargetPort().equals(other.getTargetPort()))
return false;
if (getName() == null) {
if (other.getName() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public static final ResourcePropertiesRegistry getInstance(){
}

public KubernetesAPIVersion [] getSupportedKubernetesVersions(){
return KubernetesAPIVersion.values();
return new KubernetesAPIVersion[] {KubernetesAPIVersion.v1};
}

public OpenShiftAPIVersion[] getSupportedOpenShiftVersions(){
return OpenShiftAPIVersion.values();
return new OpenShiftAPIVersion[] {OpenShiftAPIVersion.v1};
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/openshift/restclient/ResourceKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public final class ResourceKind {
public static final String CONFIG = "Config";//not rest resource;
public static final String LIST = "List";
public static final String STATUS = "Status";//not rest resource
@Deprecated
public static final String TEMPLATE_CONFIG = "TemplateConfig";//mechanism for processing templates pre v1beta3
public static final String PROCESSED_TEMPLATES = "ProcessedTemplates";//mechanism for processing templates

/**
Expand Down Expand Up @@ -114,7 +112,6 @@ public static Collection<String> values() {
set.add(CONFIG);
set.add(LIST);
set.add(STATUS);
set.add(TEMPLATE_CONFIG );
set.add("ProcessedTemplates");
values = Collections.unmodifiableCollection(set);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ITemplateProcessing extends ICapability {
*
* @param template The template to process
* @param namespace The namespace to use when processing the template
* @return IConfig pre v1beta3; ITemplate otherwise
* @return ITemplate
*/
<T extends IResource> T process(ITemplate template, String namespace);
}
7 changes: 6 additions & 1 deletion src/main/java/com/openshift/restclient/model/IService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public interface IService extends IResource{
*/
Map<String, String> getSelector();

int getTargetPort();
/**
* The port this service targets on the
* pod
* @return
*/
String getTargetPort();

/**
* Returns the IP of the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ public interface IServicePort {
void setPort(int port);

/**
* The target port on the pod it services
* The target port on the pod it services. An integer
* or named port on the pod spec
* @return
*/
int getTargetPort();
String getTargetPort();
void setTargetPort(int port);
void setTargetPort(String name);

/**
* IP protocol (TCP, UDP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void testListTemplates(){
try {
project = factory.create(VERSION, ResourceKind.PROJECT);
project.setName(helper.generateNamespace());
template = factory.create(Samples.V1BETA3_TEMPLATE.getContentAsString());
template = factory.create(Samples.V1_TEMPLATE.getContentAsString());
template.setNamespace(project.getName());

project = client.create(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class ResourceFactoryTest {
public void testV1Beta3Implementations() {
List<String> v1beta3Exlusions = Arrays.asList(new String [] {
ResourceKind.CONFIG,
ResourceKind.PROCESSED_TEMPLATES,
ResourceKind.TEMPLATE_CONFIG
ResourceKind.PROCESSED_TEMPLATES
});
ResourceFactory factory = new ResourceFactory(mock(IClient.class));
final String version = OpenShiftAPIVersion.v1beta3.toString();
Expand Down
35 changes: 10 additions & 25 deletions src/test/java/com/openshift/internal/restclient/URLBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,68 +37,53 @@ public class URLBuilderTest {

@Before
public void setup() throws MalformedURLException {
mappings.put(ResourceKind.SERVICE, "api/v1beta3");
mappings.put(ResourceKind.PROJECT, "osapi/v1beta3");
mappings.put(ResourceKind.SERVICE, "api/v1");
mappings.put(ResourceKind.PROJECT, "oapi/v1");
builder = new URLBuilder(new URL(BASE_URL), mappings);

}

@Test
public void testBuildingURLForAWatchService() throws Exception {
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1beta3,"foo");
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1,"foo");

String url = builder.
resource(resource)
.watch()
.addParmeter("resourceVersion", "123")
.build().toString();
assertEquals(String.format("%s/api/v1beta3/namespaces/foo/services?watch=true&resourceVersion=123", BASE_URL),url.toString());
assertEquals(String.format("%s/api/v1/namespaces/foo/services?watch=true&resourceVersion=123", BASE_URL),url.toString());
}

@Test
public void testBuildingURLForAProjectUsingResource() throws Exception {
IResource resource = givenAResource(ResourceKind.PROJECT, KubernetesAPIVersion.v1beta3,"foo");
IResource resource = givenAResource(ResourceKind.PROJECT, KubernetesAPIVersion.v1,"foo");

String url = builder.
resource(resource)
.name("foo")
.build().toString();
assertEquals(String.format("%s/osapi/v1beta3/projects/foo", BASE_URL),url.toString());
assertEquals(String.format("%s/oapi/v1/projects/foo", BASE_URL),url.toString());
}

@Test
public void testBaseURLWithTrailingSlash() throws Exception {
builder = new URLBuilder(new URL(BASE_URL + "///"), mappings);
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1beta3,"foo");
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1,"foo");

String url = whenBuildingTheURLFor(resource, "foo");
assertEquals(String.format("%s/api/v1beta3/namespaces/foo/services/bar", BASE_URL),url.toString());
assertEquals(String.format("%s/api/v1/namespaces/foo/services/bar", BASE_URL),url.toString());
}

@Test
public void testV1Beta3() {
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1beta3,"foo");
String url = whenBuildingTheURLFor(resource, "foo");

assertEquals(String.format("%s/api/v1beta3/namespaces/foo/services/bar", BASE_URL),url.toString());
}

@Test
public void testV1Beta3WithoutANamespace() {
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1beta3,null);
String url = whenBuildingTheURLFor(resource, "");

assertEquals(String.format("%s/api/v1beta3/services/bar", BASE_URL),url.toString());
}
@Test
public void testAddingASubResource() {
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1beta3, "foo");
IResource resource = givenAResource(ResourceKind.SERVICE, KubernetesAPIVersion.v1, "foo");
String url = builder.
resource(resource)
.name("bar")
.subresource("aSubResource")
.build().toString();
assertEquals(String.format("%s/api/v1beta3/namespaces/foo/services/bar/aSubResource", BASE_URL),url.toString());
assertEquals(String.format("%s/api/v1/namespaces/foo/services/bar/aSubResource", BASE_URL),url.toString());
}

private String whenBuildingTheURLFor(IResource resource, String namespace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import org.slf4j.LoggerFactory;

import com.openshift.internal.restclient.IntegrationTestHelper;
import com.openshift.internal.restclient.model.properties.ResourcePropertiesRegistry;
import com.openshift.internal.restclient.model.template.Template;
import com.openshift.restclient.IClient;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.capability.CapabilityVisitor;
import com.openshift.restclient.capability.server.ITemplateProcessing;
import com.openshift.restclient.model.IResource;
Expand All @@ -33,7 +31,7 @@
* @author Jeff Cantrill
*/
public class ServerTemplateProcessingIntegrationTest {
private static final String VERSION = "v1beta3";
private static final String VERSION = "v1";

private static final String COMMON = "openshift";

Expand All @@ -50,7 +48,7 @@ public void setup () throws MalformedURLException{
@Test
public void testProcessAndApplyTemplate() throws Exception{
final Collection<IResource> results = new ArrayList<IResource>();
ModelNode node = ModelNode.fromJSONString(Samples.V1BETA3_TEMPLATE.getContentAsString());
ModelNode node = ModelNode.fromJSONString(Samples.V1_TEMPLATE.getContentAsString());
final Template template = new Template(node, client, null);
template.setNamespace(COMMON);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
public class PortFactory {

public static ServicePort createServicePort(String name, String proto, int port, int targetPort) {
return createServicePort(name, proto, port, String.valueOf(targetPort));
}
public static ServicePort createServicePort(String name, String proto, int port, String targetPort) {
ModelNode node = new ModelNode();
node.get("name").set(name);
node.get("protocol").set(proto);
Expand Down
Loading