├── .gitignore ├── .travis.yml ├── README.md ├── epl-v10.html ├── license ├── pom.xml └── src ├── main ├── java │ └── com │ │ ├── openshift │ │ ├── client │ │ │ ├── ApplicationBuilder.java │ │ │ ├── ApplicationScale.java │ │ │ ├── ConnectionBuilder.java │ │ │ ├── DeploymentTypes.java │ │ │ ├── GearState.java │ │ │ ├── HttpMethod.java │ │ │ ├── IApplication.java │ │ │ ├── IApplicationPortForwarding.java │ │ │ ├── IApplicationSSHSession.java │ │ │ ├── IAuthorization.java │ │ │ ├── IDomain.java │ │ │ ├── IEnvironmentVariable.java │ │ │ ├── IField.java │ │ │ ├── IGear.java │ │ │ ├── IGearGroup.java │ │ │ ├── IGearProfile.java │ │ │ ├── IGearState.java │ │ │ ├── IHttpClient.java │ │ │ ├── IOpenShiftConnection.java │ │ │ ├── IOpenShiftResource.java │ │ │ ├── IOpenShiftSSHKey.java │ │ │ ├── IQuickstart.java │ │ │ ├── ISSHPublicKey.java │ │ │ ├── ISeverity.java │ │ │ ├── IUser.java │ │ │ ├── InvalidCredentialsOpenShiftException.java │ │ │ ├── InvalidNameOpenShiftException.java │ │ │ ├── Message.java │ │ │ ├── Messages.java │ │ │ ├── NoopSSLCertificateCallback.java │ │ │ ├── NotFoundOpenShiftException.java │ │ │ ├── OpenShiftApplicationNotAvailableException.java │ │ │ ├── OpenShiftConnectionFactory.java │ │ │ ├── OpenShiftEndpointException.java │ │ │ ├── OpenShiftException.java │ │ │ ├── OpenShiftRequestException.java │ │ │ ├── OpenShiftSSHKeyException.java │ │ │ ├── OpenShiftSSHOperationException.java │ │ │ ├── OpenShiftTimeoutException.java │ │ │ ├── OpenShiftUnknownSSHKeyTypeException.java │ │ │ ├── SSHKeyPair.java │ │ │ ├── SSHKeyType.java │ │ │ ├── SSHPublicKey.java │ │ │ ├── cartridge │ │ │ │ ├── EmbeddableCartridge.java │ │ │ │ ├── ICartridge.java │ │ │ │ ├── IDeployedStandaloneCartridge.java │ │ │ │ ├── IEmbeddableCartridge.java │ │ │ │ ├── IEmbeddedCartridge.java │ │ │ │ ├── IStandaloneCartridge.java │ │ │ │ ├── StandaloneCartridge.java │ │ │ │ └── query │ │ │ │ │ ├── AbstractCartridgeQuery.java │ │ │ │ │ ├── CartridgeNameQuery.java │ │ │ │ │ ├── CartridgeNameRegexQuery.java │ │ │ │ │ ├── ICartridgeQuery.java │ │ │ │ │ ├── LatestEmbeddableCartridge.java │ │ │ │ │ ├── LatestStandaloneCartridge.java │ │ │ │ │ ├── LatestVersionOf.java │ │ │ │ │ ├── LatestVersionQuery.java │ │ │ │ │ ├── StringPropertyQuery.java │ │ │ │ │ └── UrlPropertyQuery.java │ │ │ ├── configuration │ │ │ │ ├── AbstractOpenshiftConfiguration.java │ │ │ │ ├── DefaultConfiguration.java │ │ │ │ ├── IOpenShiftConfiguration.java │ │ │ │ ├── OpenShiftConfiguration.java │ │ │ │ ├── SystemConfiguration.java │ │ │ │ ├── SystemProperties.java │ │ │ │ └── UserConfiguration.java │ │ │ └── utils │ │ │ │ ├── Base64Coder.java │ │ │ │ ├── HostUtils.java │ │ │ │ ├── OpenShiftResourceUtils.java │ │ │ │ ├── RFC822DateUtils.java │ │ │ │ ├── SSLUtils.java │ │ │ │ └── TarFileUtils.java │ │ └── internal │ │ │ └── client │ │ │ ├── APIResource.java │ │ │ ├── AbstractOpenShiftConnectionFactory.java │ │ │ ├── AbstractOpenShiftResource.java │ │ │ ├── AlternativeCartridges.java │ │ │ ├── ApplicationResource.java │ │ │ ├── ApplicationSSHSession.java │ │ │ ├── AuthorizationResource.java │ │ │ ├── CartridgeType.java │ │ │ ├── DomainResource.java │ │ │ ├── EmbeddedCartridgeResource.java │ │ │ ├── EnvironmentVariableResource.java │ │ │ ├── Field.java │ │ │ ├── Gear.java │ │ │ ├── GearGroupResource.java │ │ │ ├── GearProfile.java │ │ │ ├── IRestService.java │ │ │ ├── Quickstart.java │ │ │ ├── RestService.java │ │ │ ├── RestServiceProperties.java │ │ │ ├── SSHKeyResource.java │ │ │ ├── Severity.java │ │ │ ├── StandaloneCartridgeResource.java │ │ │ ├── UserResource.java │ │ │ ├── cartridge │ │ │ └── BaseCartridge.java │ │ │ ├── httpclient │ │ │ ├── BadRequestException.java │ │ │ ├── CallbackTrustManager.java │ │ │ ├── EncodingException.java │ │ │ ├── HttpClientException.java │ │ │ ├── InternalServerErrorException.java │ │ │ ├── NotFoundException.java │ │ │ ├── UnauthorizedException.java │ │ │ ├── UrlConnectionHttpClient.java │ │ │ ├── UrlConnectionHttpClientBuilder.java │ │ │ └── request │ │ │ │ ├── FormUrlEncodedMediaType.java │ │ │ │ ├── IMediaType.java │ │ │ │ ├── JsonMediaType.java │ │ │ │ ├── Parameter.java │ │ │ │ ├── ParameterValue.java │ │ │ │ ├── ParameterValueArray.java │ │ │ │ ├── ParameterValueMap.java │ │ │ │ ├── StringParameter.java │ │ │ │ └── StringValue.java │ │ │ ├── response │ │ │ ├── AbstractJsonDTOFactory.java │ │ │ ├── ApplicationResourceDTO.java │ │ │ ├── AuthorizationResourceDTO.java │ │ │ ├── BaseResourceDTO.java │ │ │ ├── CartridgeResourceDTO.java │ │ │ ├── CartridgeResourceProperties.java │ │ │ ├── CartridgeResourceProperty.java │ │ │ ├── DomainResourceDTO.java │ │ │ ├── DownloadableCartridgeSpec.java │ │ │ ├── EnumDataType.java │ │ │ ├── EnvironmentVariableResourceDTO.java │ │ │ ├── GearGroupResourceDTO.java │ │ │ ├── GearResourceDTO.java │ │ │ ├── IRestResponseFactory.java │ │ │ ├── KeyResourceDTO.java │ │ │ ├── Link.java │ │ │ ├── LinkParameter.java │ │ │ ├── LinkParameterType.java │ │ │ ├── NamedCartridgeSpec.java │ │ │ ├── OpenShiftJsonDTOFactory.java │ │ │ ├── QuickstartDTO.java │ │ │ ├── QuickstartJsonDTOFactory.java │ │ │ ├── RestResponse.java │ │ │ └── UserResourceDTO.java │ │ │ ├── ssh │ │ │ ├── AbstractSSHKey.java │ │ │ └── ApplicationPortForwarding.java │ │ │ └── utils │ │ │ ├── Assert.java │ │ │ ├── CollectionUtils.java │ │ │ ├── IOpenShiftJsonConstants.java │ │ │ ├── IOpenShiftParameterConstants.java │ │ │ ├── StreamUtils.java │ │ │ ├── StringUtils.java │ │ │ └── UrlUtils.java │ │ └── redhat │ │ └── openshift │ │ └── examples │ │ └── .gitignore └── resources │ └── restservice.properties └── test ├── java └── com │ └── openshift │ ├── client │ ├── HttpMethodTest.java │ ├── fakes │ │ ├── DefaultConfigurationFake.java │ │ ├── EmptySystemPropertiesFake.java │ │ ├── HttpServerFake.java │ │ ├── HttpsServerFake.java │ │ ├── OpenShiftConfigurationFake.java │ │ ├── PayLoadReturningHttpClientFake.java │ │ ├── SSLCiphersConnectionBuilderFake.java │ │ ├── SystemConfigurationFake.java │ │ ├── SystemPropertiesFake.java │ │ ├── TestSSHKey.java │ │ ├── UserConfigurationFake.java │ │ └── WaitingHttpServerFake.java │ ├── portforwarding │ │ └── PortForwardingL.java │ └── utils │ │ ├── ApplicationAssert.java │ │ ├── ApplicationTestUtils.java │ │ ├── CartridgeAssert.java │ │ ├── CartridgeAsserts.java │ │ ├── CartridgeTestUtils.java │ │ ├── DeployedStandaloneCartridgeAssert.java │ │ ├── DomainAssert.java │ │ ├── DomainTestUtils.java │ │ ├── EmbeddedCartridgeAssert.java │ │ ├── EmbeddedCartridgeTestUtils.java │ │ ├── ExceptionCauseMatcher.java │ │ ├── FileUtils.java │ │ ├── GearGroupAssert.java │ │ ├── GearGroupsAssert.java │ │ ├── GearProfileTestUtils.java │ │ ├── MessageAssert.java │ │ ├── OpenShiftTestConfiguration.java │ │ ├── ParametersMatcher.java │ │ ├── QuickstartAssert.java │ │ ├── QuickstartTestUtils.java │ │ ├── ResourcePropertyAssert.java │ │ ├── SSHKeyTestUtils.java │ │ ├── SSHPublicKeyAssertion.java │ │ ├── Samples.java │ │ ├── StandaloneCartridgeAssert.java │ │ ├── StateVerifier.java │ │ ├── StringUtils.java │ │ ├── TarFileTestUtils.java │ │ ├── TestConnectionBuilder.java │ │ ├── TestConnectionFactory.java │ │ └── UrlEndsWithMatcher.java │ └── internal │ └── client │ ├── APIResourceIntegrationTest.java │ ├── APIResourceTest.java │ ├── ApplicationBuilderTest.java │ ├── ApplicationResourceIntegrationTest.java │ ├── ApplicationResourceTest.java │ ├── ApplicationSSHSessionIntegrationTest.java │ ├── ApplicationSSHSessionMockDirector.java │ ├── ApplicationSSHSessionTest.java │ ├── AuthorizationIntegrationTest.java │ ├── AuthorizationTest.java │ ├── BaseCartridgeTest.java │ ├── CartridgeQueryTest.java │ ├── CertTrustIntegrationTest.java │ ├── ConfigurationTest.java │ ├── DomainResourceIntegrationTest.java │ ├── DomainResourceTest.java │ ├── EmbeddableCartridgeTest.java │ ├── EmbeddedCartridgeResourceIntegrationTest.java │ ├── EmbeddedCartridgeResourceTest.java │ ├── EnvironmentVariableResourceIntegrationTest.java │ ├── EnvironmentVariableResourceTest.java │ ├── GearGroupsResourceTest.java │ ├── GearTest.java │ ├── HttpClientMockDirector.java │ ├── LatestVersionQueryIntegrationTest.java │ ├── LinkRetriever.java │ ├── OpenShiftExceptionTest.java │ ├── OpenShiftIntegrationTestSuite.java │ ├── OpenShiftTestSuite.java │ ├── QuickstartTest.java │ ├── RestServicePropertiesTest.java │ ├── RestServiceTest.java │ ├── SSHKeyIntegrationTest.java │ ├── SSHKeyTest.java │ ├── StandaloneCartridgeResourceIntegrationTest.java │ ├── StandaloneCartridgeResourceTest.java │ ├── StandaloneCartridgeTest.java │ ├── TestTimer.java │ ├── UserResourceIntegrationTest.java │ ├── UserTest.java │ ├── httpclient │ ├── HttpClientTest.java │ └── request │ │ ├── FormUrlEncodedMediaTypeTest.java │ │ └── JsonMediaTypeTest.java │ └── response │ ├── OpenShiftJsonDTOFactoryTest.java │ └── QuickstartDTOCartridgeQueryTest.java └── resources ├── integrationTest.properties ├── log4j.xml ├── samples ├── delete-domains-foobar_ko.json ├── delete-domains-foobarz.json ├── delete-domains-foobarz_ko-existingapps.json ├── delete-user-key-ko.json ├── get-api-quickstarts.json ├── get-api.json ├── get-cartridges.json ├── get-domains-foobar_ko-notfound.json ├── get-domains-foobars.json ├── get-domains-foobarz-applications-downloadablecart.json ├── get-domains-foobarz-applications-springeap6-cartidges-mysql.json ├── get-domains-foobarz-applications-springeap6-cartridges_1embedded.json ├── get-domains-foobarz-applications-springeap6-cartridges_2embedded.json ├── get-domains-foobarz-applications-springeap6-cartridges_3embedded.json ├── get-domains-foobarz-applications-springeap6-geargroups-12additionalgearstorage.json ├── get-domains-foobarz-applications-springeap6-geargroups.json ├── get-domains-foobarz-applications-springeap6_0alias.json ├── get-domains-foobarz-applications-springeap6_1embedded.json ├── get-domains-foobarz-applications-springeap6_2alias.json ├── get-domains-foobarz-applications-springeap6_2embedded.json ├── get-domains-foobarz-applications_1embedded.json ├── get-domains-foobarz-applications_2embedded.json ├── get-domains-foobarz-applications_3embedded.json ├── get-domains-foobarz-applications_noapps.json ├── get-domains-foobarz-applications_noenvvars.json ├── get-domains-foobarz-applications_springeap_scalable_downloadablecart.json ├── get-domains-foobarz.json ├── get-domains.json ├── get-domains_empty.json ├── get-user-keys_1key.json ├── get-user-keys_2keys.json ├── get-user-keys_none.json ├── get-user.json ├── get_0_environment_variables_foobarz_springeap6.json ├── get_1_environment_variables_foobarz_springeap6.json ├── get_four_environment_variables_foobarz_springeap6.json ├── get_two_environment_variabls_foobarz_springeap6.json ├── links-unknown-linkparametertype.json ├── links-unknown-verb.json ├── post-foobar-domains_ko-inuse.json ├── post-jekyll-domains-foobarz-applications.json ├── post-mysql-domains-foobarz-applications-springeap6-cartridges.json ├── post-scalable-domains-foobarz-applications.json ├── post-stop-domains-foobarz-applications-springeap6-events.json ├── post_add_2_environment_variables_to_foobarz_springeap6.json ├── post_add_environment_variable_foo_to_foobarz_springeap6.json ├── put-bbcc-dsa-user-keys-somekey.json └── put_foo_environment_variable_foobarz_springeap6.json └── server-keystore.jks /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | .settings 4 | target 5 | bin 6 | .metadata 7 | .idea 8 | *.iml 9 | **/integrationTest.properties 10 | /target/ 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - openjdk7 5 | 6 | script: mvn package 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenShift Java Client [![Build Status](https://travis-ci.org/openshift/openshift-java-client.svg)](https://travis-ci.org/openshift/openshift-java-client) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.openshift/openshift-java-client/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.openshift/openshift-java-client) 2 | =========================== 3 | 4 | Java client for the OpenShift REST API. It pretty much offers all features that are currently available in the rhc-* command line tools 5 | (create/rename a domain, create/destroy applications, list applications, list available cartridges, add cartridges, etc.). 6 | 7 | Only for Version 2 8 | ---------------- 9 | 10 | This client is used by JBoss Tools for OpenShift 2.x. 11 | 12 | For later OpenShift versions see https://github.com/openshift/openshift-restclient-java/. 13 | 14 | Usage 15 | ----- 16 | An exemplary usage of the client may look like the following: 17 | 18 | IOpenShiftConnection connection = 19 | new OpenShiftConnectionFactory().getConnection("myApplicationId", "user", "password"); 20 | IUser user = connection.getUser(); 21 | IDomain domain = user.createDomain("myDomain"); 22 | IApplication as7Application = domain.createApplication("myApplication", LatestVersionOf.jbossAs().get(user)); 23 | IEmbeddedCartridge mySqlCartridge = as7Application.addEmbeddableCartridge(LatestVersionOf.mySQL().get(user)); 24 | String unstructuredCredentials = mySqlCartridge.getCreationLog(); 25 | String mySqlConnectionUrl = mySqlCartridge.getUrl(); 26 | 27 | There are also 2 blog posts on jboss.org which discuss the API in more details: 28 | 29 | * [show-domain-info: openshift-java-client in a nutshell](http://planet.jboss.org/post/show_domain_info_openshift_java_client_in_a_nutshell) 30 | * [enable-openshift-ci: full example using openshift-java-client](https://community.jboss.org/wiki/Enable-openshift-ciFullExampleUsingOpenshift-java-client) 31 | 32 | Most insightful are the integration tests within the library which pretty much use the API in all details: 33 | 34 | * ApplicationResourceIntegrationTest 35 | * DomainResourceIntegrationTest 36 | * EmbeddedCartridgeResourceIntegrationTest 37 | * etc. 38 | 39 | Download 40 | -------- 41 | You may either build from source using maven (mvn clean package) or get the prebuilt artifact from the maven central. 42 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/ApplicationScale.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | 14 | /** 15 | * Enum to indicate the support for scalability when creating a new application 16 | * @author Xavier Coulon 17 | * 18 | */ 19 | public enum ApplicationScale { 20 | 21 | SCALE("true"), NO_SCALE("false"); 22 | 23 | private static final String SCALING_TRUE = "TRUE"; 24 | 25 | private final String value; 26 | 27 | public static ApplicationScale safeValueOf(final String value) { 28 | if(value == null 29 | || !SCALING_TRUE.equals(value.toUpperCase())) { 30 | return NO_SCALE; 31 | } 32 | return SCALE; 33 | } 34 | 35 | private ApplicationScale(final String value) { 36 | this.value = value; 37 | } 38 | 39 | public String getValue() { 40 | return this.value; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/DeploymentTypes.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | /** 17 | * @author Andre Dietisheim 18 | */ 19 | public class DeploymentTypes { 20 | 21 | private static final String GIT = "git"; 22 | private static final String BINARY = "binary"; 23 | 24 | private DeploymentTypes() { 25 | } 26 | 27 | public static String git() { 28 | return GIT; 29 | } 30 | 31 | public static String binary() { 32 | return BINARY; 33 | } 34 | 35 | public static boolean isBinary(String deploymentType) { 36 | return BINARY.equals(deploymentType); 37 | } 38 | 39 | public static boolean isGit(String deploymentType) { 40 | return GIT.equals(deploymentType); 41 | } 42 | 43 | public static List getAll() { 44 | return Arrays.asList(GIT, BINARY); 45 | } 46 | 47 | public static String switchType(String deploymentType) { 48 | if (isBinary(deploymentType)) { 49 | return GIT; 50 | } else if (isGit(deploymentType)) { 51 | return BINARY; 52 | } else { 53 | throw new OpenShiftException("Unknown deployment type {0}", deploymentType); 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/GearState.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import com.openshift.internal.client.utils.StringUtils; 14 | 15 | public class GearState implements IGearState { 16 | /** 17 | * @see OpenShift 19 | * Origin Cartridge Developer’s Guide, 7.10.2. The status Action 20 | */ 21 | private String state; 22 | 23 | public GearState(String state) { 24 | this.state = getState(state); 25 | } 26 | 27 | public String getState() { 28 | return this.state; 29 | } 30 | 31 | public void setState(String state) { 32 | this.state = getState(state); 33 | } 34 | 35 | protected String getState(String state) { 36 | if (StringUtils.isEmpty(state)) { 37 | return UNKNOWN; 38 | } else { 39 | return state.toUpperCase(); 40 | } 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | final int prime = 31; 46 | int result = 1; 47 | result = prime * result + ((state == null) ? 0 : state.hashCode()); 48 | return result; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object obj) { 53 | if (this == obj) 54 | return true; 55 | if (obj == null) 56 | return false; 57 | if (getClass() != obj.getClass()) 58 | return false; 59 | GearState other = (GearState) obj; 60 | if (state == null) { 61 | if (other.state != null) 62 | return false; 63 | } else if (!state.equals(other.state)) 64 | return false; 65 | return true; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "GearState [state=" + state + "]"; 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public enum HttpMethod { 17 | GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS; 18 | 19 | /** 20 | * hasValue determines if enum can safely convert string to enum value 21 | * 22 | * @param value the value to inspect 23 | * @return true if the value can be safely converted to the enum; false otherwise 24 | */ 25 | public static boolean hasValue(String value) { 26 | for (HttpMethod m : HttpMethod.values()) { 27 | if(m.name().equalsIgnoreCase(value)){ 28 | return true; 29 | } 30 | } 31 | return false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IApplicationPortForwarding.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client; 2 | 3 | import com.jcraft.jsch.Session; 4 | 5 | public interface IApplicationPortForwarding { 6 | 7 | /** 8 | * Start the binding, ie, open a SSH tunnel between local address:port and remote address:port. 9 | * 10 | * @throws OpenShiftSSHOperationException 11 | */ 12 | public abstract void start(final Session session) throws OpenShiftSSHOperationException; 13 | 14 | /** 15 | * Stop the SSH tunnel. 16 | * 17 | * @throws OpenShiftSSHOperationException 18 | */ 19 | public abstract void stop(final Session session) throws OpenShiftSSHOperationException; 20 | 21 | /** 22 | * @return true if the SSH tunnel is open, false otherwise. 23 | * @throws OpenShiftSSHOperationException 24 | */ 25 | public abstract boolean isStarted(final Session session) throws OpenShiftSSHOperationException; 26 | 27 | /** 28 | * @return the name 29 | */ 30 | public abstract String getName(); 31 | 32 | /** 33 | * @return the localAddress 34 | */ 35 | public abstract String getLocalAddress(); 36 | 37 | /** 38 | * @param localAddress 39 | * the localAddress to set 40 | */ 41 | public abstract void setLocalAddress(final String localAddress); 42 | 43 | /** 44 | * @return the localPort 45 | */ 46 | public abstract int getLocalPort(); 47 | 48 | /** 49 | * @param localPort 50 | * the localPort to set 51 | */ 52 | public abstract void setLocalPort(final int localPort); 53 | 54 | /** 55 | * @return the remoteIp 56 | */ 57 | public abstract String getRemoteAddress(); 58 | 59 | /** 60 | * @return the remotePort 61 | */ 62 | public abstract int getRemotePort(); 63 | 64 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IAuthorization.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Sean Kavanagh - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * Operations to manage and view authorization resources 15 | * 16 | * @link http://openshift.github.io/documentation/rest_api/rest-api-1-6.html# 17 | * authorization 18 | * 19 | * @author Sean Kavanagh 20 | */ 21 | public interface IAuthorization extends IOpenShiftResource { 22 | 23 | public static String SCOPE_SESSION = "session"; 24 | public static String SCOPE_READ = "read"; 25 | public static String SCOPE_USERINFO = "userinfo"; 26 | public static int NO_EXPIRES_IN = -1; 27 | 28 | /** 29 | * Returns the unique id for this authorization. 30 | * 31 | * @return 32 | */ 33 | public String getId(); 34 | 35 | /** 36 | * authorization note 37 | * 38 | * @return 39 | */ 40 | public String getNote(); 41 | 42 | /** 43 | * returns the scope of the authorization token to determine type of access. 44 | * 45 | * @return 46 | */ 47 | public String getScopes(); 48 | 49 | /** 50 | * Returns authorization string that contains user credentials. 51 | * 52 | * @return 53 | */ 54 | public String getToken(); 55 | 56 | /** 57 | * Returns the total time in seconds before this authorization expires. 58 | * 59 | * @return 60 | */ 61 | public int getExpiresIn(); 62 | 63 | /** 64 | * Destroys this authorization 65 | * 66 | * @throws OpenShiftException 67 | */ 68 | public void destroy() throws OpenShiftException; 69 | 70 | /** 71 | * Refreshes the authorization by reloading its content from OpenShift. 72 | * 73 | * @throws OpenShiftException 74 | */ 75 | public void refresh() throws OpenShiftException; 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IEnvironmentVariable.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Syed Iqbal 15 | * @deprecated use {@link IApplication} instead 16 | */ 17 | public interface IEnvironmentVariable extends IOpenShiftResource { 18 | 19 | /** 20 | * @return Name of the environment variable 21 | */ 22 | public String getName(); 23 | 24 | /** 25 | * @return Value of the environment variable 26 | */ 27 | @Deprecated 28 | public String getValue(); 29 | 30 | /** 31 | * Updates this environment variable to the given value. 32 | * 33 | * @param value 34 | * new value for this environment variable 35 | * @throws OpenShiftException 36 | * @deprecated use {@link IApplication#updateEnvironmentVariable} instead 37 | */ 38 | @Deprecated 39 | public void update(String value) throws OpenShiftException; 40 | 41 | /** 42 | * Destroys this environment variable 43 | * 44 | * @throws OpenShiftException 45 | * @deprecated use {@link IApplication#removeEnvironmentVariable} instead 46 | */ 47 | @Deprecated 48 | public void destroy() throws OpenShiftException; 49 | 50 | 51 | /** 52 | * Returns the application for this environment variable 53 | * 54 | * @return 55 | */ 56 | public IApplication getApplication(); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IField.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import com.openshift.internal.client.Field; 14 | 15 | /** 16 | * @author Andre Dietisheim 17 | */ 18 | public interface IField { 19 | 20 | public static final IField DEFAULT = new Field(null); 21 | public static final IField RESULT = new Field("result"); 22 | public static final IField APPINFO = new Field("appinfo"); 23 | 24 | public String getValue(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IGear.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | public interface IGear { 14 | 15 | 16 | /** 17 | * Returns the id of this gear. 18 | * 19 | * @return the id 20 | */ 21 | public String getId(); 22 | 23 | /** 24 | * Returns the state of this gear 25 | * 26 | * @return the state 27 | */ 28 | public GearState getState(); 29 | 30 | /** 31 | * The URL to use when connecting with SSH in the following form: 32 | * {@code ssh://@} 33 | * @return the SSH URL 34 | */ 35 | public String getSshUrl(); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IGearGroup.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import java.util.Collection; 14 | 15 | import com.openshift.client.cartridge.ICartridge; 16 | 17 | public interface IGearGroup { 18 | 19 | public static final int NO_ADDITIONAL_GEAR_STORAGE = -1; 20 | 21 | /** 22 | * Returns the uuid of this gear groups. 23 | * 24 | * @return the uuid 25 | */ 26 | public String getUUID(); 27 | 28 | /** 29 | * Returns the name of this gear groups 30 | * 31 | * @return the name 32 | */ 33 | public String getName(); 34 | 35 | /** 36 | * Returns the gears in this gear group resource 37 | * 38 | * @return the gears 39 | */ 40 | public Collection getGears(); 41 | 42 | /** 43 | * Returns the cartridges in this gear group resource 44 | * 45 | * @return the gears 46 | */ 47 | public Collection getCartridges(); 48 | 49 | /** 50 | * Returns the additional storage configured for this gear group in gigabytes 51 | * 52 | * @return the additional storage value 53 | */ 54 | public int getAdditionalStorage(); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IGearProfile.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public interface IGearProfile { 17 | 18 | public String getName(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IGearState.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Corey Daley 15 | */ 16 | public interface IGearState { 17 | 18 | public static final String UNKNOWN = "UNKNOWN"; 19 | 20 | /** 21 | * Get the gears state 22 | * @return String the gears state 23 | */ 24 | public String getState(); 25 | 26 | /** 27 | * Set the gears state 28 | * @param state 29 | */ 30 | public void setState(String state); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IOpenShiftResource.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client; 2 | 3 | 4 | public interface IOpenShiftResource { 5 | 6 | /** 7 | * Returns 8 | * true if there is log about the creation of this resource. 9 | * Creation logs are only available at creation time. So resources that were retrieved 10 | * while they already existed wont have a creation log. 11 | * 12 | * @return true if there's creation log for this resource 13 | */ 14 | public boolean hasCreationLog(); 15 | 16 | /** 17 | * Returns the log that was created when the resource was created. 18 | * 19 | * @return the log which reported the creation of this resource 20 | */ 21 | public String getCreationLog(); 22 | 23 | /** 24 | * Returns all the (creation log) messages. These messages only exist at 25 | * creation time. Existing cartridges, that were added in a prior session 26 | * don't have any messages any more. 27 | * 28 | * @return all messages by field 29 | * 30 | * @see #getCreationLog() 31 | */ 32 | public Messages getMessages(); 33 | 34 | /** 35 | * Refresh the resource and its list of children resources that were 36 | * previously loaded 37 | * 38 | * @throws OpenShiftException 39 | */ 40 | public void refresh() throws OpenShiftException; 41 | 42 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/IOpenShiftSSHKey.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | 14 | /** 15 | * @author Andre Dietisheim 16 | */ 17 | public interface IOpenShiftSSHKey extends ISSHPublicKey { 18 | 19 | /** 20 | * Returns the name that is used to store this key on OpenShift. 21 | * 22 | * @return 23 | */ 24 | public String getName(); 25 | 26 | /** 27 | * Sets the public key portion of this ssh key to the OpenShift PaaS. 28 | * 29 | * @param publicKey the new public key porition of this key 30 | * @throws OpenShiftException 31 | */ 32 | public void setPublicKey(String publicKey) throws OpenShiftException; 33 | 34 | /** 35 | * Sets the new type and public key of this ssh key to the OpenShift PaaS 36 | * @param type 37 | * @throws OpenShiftException 38 | */ 39 | public void setKeyType(SSHKeyType type, String publicKey) throws OpenShiftException; 40 | 41 | public void destroy() throws OpenShiftException; 42 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/ISSHPublicKey.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public interface ISSHPublicKey { 17 | 18 | /** 19 | * Returns the content of the public key (key content without ssh-rsa 20 | * identifier nor comment) of the ssh key 21 | * 22 | * @return the content of the public key (without signature, without 23 | * comment) 24 | * @throws OpenShiftException 25 | */ 26 | public String getPublicKey(); 27 | 28 | /** 29 | * Returns the type of the key (ssh-rsa or ssh-dss) 30 | * 31 | * @return the type of key, either ssh-rsa or ssh-dss 32 | * @throws OpenShiftException 33 | */ 34 | public SSHKeyType getKeyType(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/ISeverity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import com.openshift.internal.client.Severity; 14 | 15 | /** 16 | * @author Andre Dietisheim 17 | */ 18 | public interface ISeverity { 19 | 20 | public static final ISeverity INFO = new Severity("info"); 21 | public static final ISeverity DEBUG = new Severity("debug"); 22 | public static final ISeverity ERROR = new Severity("error"); 23 | public static final ISeverity RESULT = new Severity("result"); 24 | 25 | public String getValue(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/InvalidCredentialsOpenShiftException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import com.openshift.internal.client.httpclient.HttpClientException; 14 | import com.openshift.internal.client.response.RestResponse; 15 | 16 | 17 | /** 18 | * @author André Dietisheim 19 | */ 20 | public class InvalidCredentialsOpenShiftException extends OpenShiftEndpointException { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public InvalidCredentialsOpenShiftException(String url, HttpClientException cause, RestResponse restResponse) throws OpenShiftException { 25 | super(url, cause, restResponse, "Your credentials are not authorized to access \"{0}\"", (Object) url); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/InvalidNameOpenShiftException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class InvalidNameOpenShiftException extends OpenShiftException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public InvalidNameOpenShiftException(String message, Object... arguments) { 21 | super(message, arguments); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/NoopSSLCertificateCallback.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import java.security.cert.X509Certificate; 14 | 15 | import javax.net.ssl.SSLSession; 16 | 17 | import com.openshift.client.IHttpClient.ISSLCertificateCallback; 18 | 19 | /** 20 | * @author Andre Dietisheim 21 | */ 22 | public class NoopSSLCertificateCallback implements ISSLCertificateCallback { 23 | 24 | @Override 25 | public boolean allowCertificate(X509Certificate[] chain) { 26 | return true; 27 | } 28 | 29 | @Override 30 | public boolean allowHostname(String hostname, SSLSession session) { 31 | return true; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/NotFoundOpenShiftException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import com.openshift.internal.client.httpclient.HttpClientException; 14 | import com.openshift.internal.client.response.RestResponse; 15 | 16 | /** 17 | * @author André Dietisheim 18 | */ 19 | public class NotFoundOpenShiftException extends OpenShiftEndpointException { 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | public NotFoundOpenShiftException(String url, HttpClientException e, RestResponse restResponse) throws OpenShiftException { 24 | super(url, e, restResponse, "Could not find any OpenShift resource at \"{0}\"", url); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftApplicationNotAvailableException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Xavier Coulon 15 | */ 16 | public class OpenShiftApplicationNotAvailableException extends OpenShiftException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | 21 | public OpenShiftApplicationNotAvailableException(final String message) { 22 | super(message); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftEndpointException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import java.util.List; 14 | 15 | import com.openshift.internal.client.response.RestResponse; 16 | 17 | /** 18 | * @author André Dietisheim 19 | */ 20 | public class OpenShiftEndpointException extends OpenShiftException { 21 | 22 | private static final long serialVersionUID = 8251533839480636815L; 23 | 24 | private final String url; 25 | private final RestResponse response; 26 | 27 | public OpenShiftEndpointException(final String url, final Throwable cause, RestResponse response, final String message, final Object... arguments) { 28 | super(cause, message, arguments); 29 | this.url = url; 30 | this.response = response; 31 | } 32 | 33 | /** 34 | * @return the server response after converting it into a {@link RestResponse}. 35 | * @throws OpenShiftException if the unmarshalling fails 36 | */ 37 | public RestResponse getRestResponse() throws OpenShiftException { 38 | return response; 39 | } 40 | 41 | /** 42 | * @return the server response messages after converting the response into a {@link RestResponse}. If the unmarshalling fails, the returned list is null. 43 | */ 44 | public Messages getRestResponseMessages() { 45 | if (response == null) { 46 | return null; 47 | } 48 | return response.getMessages(); 49 | } 50 | 51 | /** 52 | * Returns the message for the given field. Returns null otherwise. 53 | * 54 | * @param field 55 | * @return the message for the given field 56 | * 57 | * @see Message#FIELD_DEFAULT 58 | * @see Message#FIELD_APPINFO 59 | * @see Message#FIELD_RESULT 60 | */ 61 | public List getRestResponseMessage(IField field) { 62 | Messages messages = getRestResponseMessages(); 63 | if (messages == null) { 64 | return null; 65 | } 66 | return messages.getBy(field); 67 | } 68 | 69 | protected String getUrl() { 70 | return url; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import java.text.MessageFormat; 14 | 15 | /** 16 | * @author André Dietisheim 17 | */ 18 | public class OpenShiftException extends RuntimeException { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | public OpenShiftException(Throwable cause, String message, Object... arguments) { 23 | super(MessageFormat.format(message, arguments), cause); 24 | } 25 | 26 | public OpenShiftException(String message, Object... arguments) { 27 | super(MessageFormat.format(message, arguments)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftRequestException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | 14 | /** 15 | * @author Andre Dietisheim 16 | */ 17 | public class OpenShiftRequestException extends OpenShiftException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | public OpenShiftRequestException(String message, Object... arguments) { 22 | super(message, arguments); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftSSHKeyException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class OpenShiftSSHKeyException extends OpenShiftException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public OpenShiftSSHKeyException(String message, Object... arguments) { 21 | super(message, arguments); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftSSHOperationException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * OpenShift Exception that encapsulates an underlying exception that occurred during an SSH operation. 15 | * @author Xavier Coulon 16 | * 17 | */ 18 | public class OpenShiftSSHOperationException extends OpenShiftException { 19 | 20 | private static final long serialVersionUID = -1058021959768485317L; 21 | 22 | public OpenShiftSSHOperationException(Throwable cause, String message, Object... arguments) { 23 | super(cause, message, arguments); 24 | } 25 | 26 | public OpenShiftSSHOperationException(String message, Object... arguments) { 27 | super(message, arguments); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftTimeoutException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class OpenShiftTimeoutException extends OpenShiftEndpointException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public OpenShiftTimeoutException(String url, Throwable e, String message, Object... arguments) { 21 | super(url, e, null, message, arguments); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/OpenShiftUnknownSSHKeyTypeException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class OpenShiftUnknownSSHKeyTypeException extends OpenShiftException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public OpenShiftUnknownSSHKeyTypeException(String message, Object... arguments) { 21 | super(message, arguments); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/SSHKeyType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import com.jcraft.jsch.KeyPair; 14 | import com.openshift.internal.client.utils.Assert; 15 | 16 | /** 17 | * @author Andre Dietisheim 18 | */ 19 | public enum SSHKeyType { 20 | 21 | SSH_RSA("ssh-rsa"), SSH_DSA("ssh-dss"); 22 | 23 | private final String typeId; 24 | 25 | SSHKeyType(String typeId) { 26 | this.typeId = typeId; 27 | } 28 | 29 | public String getTypeId() { 30 | return typeId; 31 | } 32 | 33 | /** 34 | * Returns the JSch key pair constant for a given SSHKeyType. 35 | * 36 | * @param type 37 | * the SSHKeyType that the JSch KeyPair constant will get 38 | * returned for 39 | * @return 40 | */ 41 | public int toJSchKeyType() { 42 | switch (this) { 43 | case SSH_RSA: 44 | return KeyPair.RSA; 45 | case SSH_DSA: 46 | return KeyPair.DSA; 47 | default: 48 | return KeyPair.UNKNOWN; 49 | } 50 | } 51 | 52 | public static SSHKeyType getByTypeId(String keyTypeId) throws OpenShiftUnknownSSHKeyTypeException { 53 | Assert.notNull(keyTypeId); 54 | 55 | for (SSHKeyType sSHKeyType : values()) { 56 | if (keyTypeId.equals(sSHKeyType.getTypeId())) { 57 | return sSHKeyType; 58 | } 59 | } 60 | throw new OpenShiftUnknownSSHKeyTypeException("OpenShift does not support keys of type \"{0}\"", keyTypeId); 61 | } 62 | 63 | public static SSHKeyType getByJSchKeyType(KeyPair keyPair) throws OpenShiftUnknownSSHKeyTypeException { 64 | Assert.notNull(keyPair); 65 | 66 | return getByJSchKeyType(keyPair.getKeyType()); 67 | } 68 | 69 | public static SSHKeyType getByJSchKeyType(int jschKeyType) throws OpenShiftUnknownSSHKeyTypeException { 70 | if (jschKeyType == KeyPair.RSA) { 71 | return SSH_RSA; 72 | } else if (jschKeyType == KeyPair.DSA) { 73 | return SSH_DSA; 74 | } else { 75 | throw new OpenShiftUnknownSSHKeyTypeException("Unknown jsch key type \"{0}\"", jschKeyType); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/SSHPublicKey.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client; 12 | 13 | import java.io.File; 14 | import java.io.FileNotFoundException; 15 | import java.io.FileReader; 16 | import java.io.IOException; 17 | import java.util.regex.Matcher; 18 | import java.util.regex.Pattern; 19 | 20 | import com.openshift.internal.client.ssh.AbstractSSHKey; 21 | import com.openshift.internal.client.utils.StreamUtils; 22 | 23 | /** 24 | * @author André Dietisheim 25 | */ 26 | public class SSHPublicKey extends AbstractSSHKey { 27 | 28 | private static final Pattern PUBLICKEY_PATTERN = Pattern.compile("([^ ]+) ([^ ]+)( .+)*"); 29 | 30 | private String publicKey; 31 | 32 | public SSHPublicKey(String publicKeyFilePath) throws FileNotFoundException, OpenShiftException, IOException { 33 | this(new File(publicKeyFilePath)); 34 | } 35 | 36 | public SSHPublicKey(File publicKeyFile) throws FileNotFoundException, OpenShiftException, IOException { 37 | super(null); 38 | init(publicKeyFile); 39 | } 40 | 41 | public String getPublicKey() { 42 | return publicKey; 43 | } 44 | 45 | private void init(File publicKeyFile) throws OpenShiftException, FileNotFoundException, IOException { 46 | String keyWithIdAndComment = StreamUtils.readToString(new FileReader(publicKeyFile)); 47 | Matcher matcher = PUBLICKEY_PATTERN.matcher(keyWithIdAndComment); 48 | if (!matcher.find() 49 | || matcher.groupCount() < 1) { 50 | throw new OpenShiftException("Could not load public key from file \"{0}\": unknown key format.", publicKeyFile.getAbsolutePath()); 51 | } 52 | 53 | setKeyType(matcher.group(1)); 54 | this.publicKey = matcher.group(2); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/IDeployedStandaloneCartridge.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge; 12 | 13 | import com.openshift.client.IGearGroup; 14 | 15 | /** 16 | * Represents a standalone cartridge that has been deployed as opposed to IStandaloneCartridge 17 | * which really represents the metadata about a standalone cartridge 18 | * 19 | * @author Jeff Cantrill 20 | * @author Andre Dietisheim 21 | */ 22 | public interface IDeployedStandaloneCartridge extends IStandaloneCartridge{ 23 | 24 | /** 25 | * set the additional gear storage for the cartridge to the given 26 | * size. 27 | * 28 | * @param size The total additional gear storage for the cartridge 29 | * in gigabytes 30 | */ 31 | public void setAdditionalGearStorage(int size); 32 | 33 | /** 34 | * Returns the additional gear storage for this cartridge 35 | * @return 36 | */ 37 | public int getAdditionalGearStorage(); 38 | 39 | /** 40 | * Returns the gear group that this cartridge is deployed on 41 | * @return 42 | */ 43 | public IGearGroup getGearGroup(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/IEmbeddableCartridge.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge; 12 | 13 | 14 | 15 | /** 16 | * @author Xavier Coulon 17 | * @author Andre Dietisheim 18 | */ 19 | public interface IEmbeddableCartridge extends ICartridge { 20 | 21 | public static final String NAME_10GEN_MMS_AGENT = "10gen-mms-agent"; 22 | public static final String NAME_CRON = "cron"; 23 | public static final String NAME_HAPROXY = "haproxy"; 24 | public static final String NAME_JENKINS_CLIENT = "jenkins-client"; 25 | public static final String NAME_METRICS = "metrics"; 26 | public static final String NAME_MONGODB = "mongodb"; 27 | public static final String NAME_PHPMYADMIN = "phpmyadmin"; 28 | public static final String NAME_POSTGRESQL = "postgresql"; 29 | public static final String NAME_MYSQL = "mysql"; 30 | public static final String NAME_ROCKMONGO = "rockmongo"; 31 | public static final String NAME_SWITCHYARD = "switchyard"; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/IEmbeddedCartridge.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge; 12 | 13 | import com.openshift.client.IApplication; 14 | import com.openshift.client.IOpenShiftResource; 15 | import com.openshift.client.OpenShiftException; 16 | import com.openshift.internal.client.response.CartridgeResourceProperties; 17 | 18 | /** 19 | * Interface to designate a cartridge that has been added and configured 20 | * 21 | * @author André Dietisheim 22 | * @author Jeff Cantrill 23 | */ 24 | public interface IEmbeddedCartridge extends IOpenShiftResource, IEmbeddableCartridge { 25 | 26 | /** 27 | * Destroys this cartridge (and removes it from the list of existing cartridges) 28 | * 29 | * @throws OpenShiftException 30 | */ 31 | public void destroy() throws OpenShiftException; 32 | 33 | 34 | /** 35 | * Returns the application this cartridge is embedded into. 36 | * 37 | * @return application this is embedded into 38 | */ 39 | public IApplication getApplication(); 40 | 41 | /** 42 | * Returns the properties for this embedded cartridge 43 | * 44 | * @return the resource properties 45 | */ 46 | public CartridgeResourceProperties getProperties(); 47 | 48 | /** 49 | * set the additional gear storage for the cartridge to the given 50 | * size. 51 | * 52 | * @param size The total additional gear storage for the cartridge 53 | * in gigabytes 54 | */ 55 | public void setAdditionalGearStorage(int size); 56 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/IStandaloneCartridge.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public interface IStandaloneCartridge extends ICartridge { 17 | 18 | public static final String NAME_JBOSSEWS = "jbossews"; 19 | public static final String NAME_JBOSSAS = "jbossas"; 20 | public static final String NAME_JBOSSEAP = "jbosseap"; 21 | public static final String NAME_JENKINS = "jenkins"; 22 | public static final String NAME_PERL = "perl"; 23 | public static final String NAME_PHP = "php"; 24 | public static final String NAME_PYTHON = "python"; 25 | public static final String NAME_RUBY = "ruby"; 26 | public static final String NAME_ZEND = "zend"; 27 | 28 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/AbstractCartridgeQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import com.openshift.client.IApplication; 17 | import com.openshift.client.IDomain; 18 | import com.openshift.client.IOpenShiftConnection; 19 | import com.openshift.client.cartridge.ICartridge; 20 | import com.openshift.internal.client.utils.Assert; 21 | 22 | /** 23 | * A base query class for query that shall match cartridges. 24 | * 25 | * @author Andre Dietisheim 26 | */ 27 | public abstract class AbstractCartridgeQuery implements ICartridgeQuery { 28 | 29 | @Override 30 | public List getAll(List cartridges) { 31 | List matchingCartridges = new ArrayList(); 32 | 33 | if (cartridges == null) { 34 | return matchingCartridges; 35 | } 36 | 37 | for (C cartridge : cartridges) { 38 | if (matches(cartridge)) { 39 | matchingCartridges.add(cartridge); 40 | } 41 | } 42 | 43 | return matchingCartridges; 44 | } 45 | 46 | @Override 47 | public C get(List cartridges) { 48 | List matchingCartridges = getAll(cartridges); 49 | if (matchingCartridges == null 50 | || matchingCartridges.size() == 0) { 51 | return null; 52 | } 53 | return matchingCartridges.iterator().next(); 54 | } 55 | 56 | @Override 57 | public abstract boolean matches(C cartridge); 58 | 59 | protected IOpenShiftConnection getConnection(IApplication application) { 60 | Assert.notNull(application); 61 | return application.getDomain().getUser().getConnection(); 62 | } 63 | 64 | protected IOpenShiftConnection getConnection(IDomain domain) { 65 | Assert.notNull(domain); 66 | return domain.getUser().getConnection(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/CartridgeNameQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import com.openshift.client.cartridge.ICartridge; 14 | import com.openshift.internal.client.utils.Assert; 15 | 16 | /** 17 | * A query that returns the cartridges whose name match the given pattern. 18 | * 19 | * @author André Dietisheim 20 | */ 21 | public class CartridgeNameQuery extends AbstractCartridgeQuery { 22 | 23 | private String nameSubstring; 24 | 25 | public CartridgeNameQuery(String nameSubstring) { 26 | Assert.notEmpty(nameSubstring); 27 | this.nameSubstring = nameSubstring; 28 | } 29 | 30 | @Override 31 | public boolean matches(C cartridge) { 32 | if (cartridge == null 33 | || cartridge.getName() == null) { 34 | return false; 35 | } 36 | return cartridge.getName().contains(nameSubstring); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "CartridgeNameQuery [" 42 | + "nameSubstring=" + nameSubstring 43 | + "]"; 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/CartridgeNameRegexQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import java.util.regex.Pattern; 14 | 15 | import com.openshift.client.cartridge.ICartridge; 16 | 17 | /** 18 | * A query that returns the cartridges whose name match the given pattern. 19 | * 20 | * @author André Dietisheim 21 | */ 22 | public class CartridgeNameRegexQuery extends AbstractCartridgeQuery { 23 | 24 | private Pattern namePattern; 25 | 26 | public CartridgeNameRegexQuery(String namePattern) { 27 | this(Pattern.compile(namePattern)); 28 | } 29 | 30 | public CartridgeNameRegexQuery(Pattern namePattern) { 31 | this.namePattern = namePattern; 32 | } 33 | 34 | @Override 35 | public boolean matches(C cartridge) { 36 | if (cartridge == null) { 37 | return false; 38 | } 39 | return namePattern.matcher(cartridge.getName()).find(); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "CartridgeNameRegexQuery [" 45 | + "namePattern=" + namePattern 46 | + "]"; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/ICartridgeQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import java.util.List; 14 | 15 | import com.openshift.client.cartridge.ICartridge; 16 | 17 | /** 18 | * A query that shall selected cartridges among the given collection of cartridges. 19 | * 20 | * @author Andre Dietisheim 21 | * 22 | */ 23 | public interface ICartridgeQuery { 24 | 25 | public List getAll(List cartridges); 26 | 27 | public C get(List cartridges); 28 | 29 | public boolean matches(C cartridge); 30 | 31 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/LatestEmbeddableCartridge.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import java.util.List; 14 | 15 | import com.openshift.client.IApplication; 16 | import com.openshift.client.IOpenShiftConnection; 17 | import com.openshift.client.IUser; 18 | import com.openshift.client.cartridge.ICartridge; 19 | import com.openshift.client.cartridge.IEmbeddableCartridge; 20 | import com.openshift.internal.client.utils.Assert; 21 | 22 | /** 23 | * A query that shall select the latest version of an embedded cartridge that's given by name. 24 | * 25 | * @author Andre Dietisheim 26 | * 27 | * @see IEmbeddableCartridge 28 | */ 29 | public class LatestEmbeddableCartridge { 30 | 31 | private LatestVersionQuery query; 32 | 33 | public LatestEmbeddableCartridge(final String name) { 34 | this.query = new LatestVersionQuery(name); 35 | } 36 | 37 | public boolean matches(ICartridge cartridge) { 38 | return query.matches(cartridge); 39 | } 40 | 41 | public C get(List cartridges) { 42 | Assert.notNull(cartridges); 43 | return query.get(cartridges); 44 | } 45 | 46 | public IEmbeddableCartridge get(IOpenShiftConnection connection) { 47 | Assert.notNull(connection); 48 | return get(connection.getEmbeddableCartridges()); 49 | } 50 | 51 | public IEmbeddableCartridge get(IApplication application) { 52 | Assert.notNull(application); 53 | return get(application.getDomain().getUser().getConnection()); 54 | } 55 | 56 | public IEmbeddableCartridge get(IUser user) { 57 | Assert.notNull(user); 58 | return get(user.getConnection()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/LatestStandaloneCartridge.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import com.openshift.client.IApplication; 14 | import com.openshift.client.IOpenShiftConnection; 15 | import com.openshift.client.IUser; 16 | import com.openshift.client.cartridge.ICartridge; 17 | import com.openshift.client.cartridge.IStandaloneCartridge; 18 | import com.openshift.internal.client.utils.Assert; 19 | 20 | /** 21 | * A query that shall select the latest version of a standalone cartridge that's given by name. 22 | * 23 | * @author Andre Dietisheim 24 | * 25 | * @see IStandaloneCartridge 26 | */ 27 | public class LatestStandaloneCartridge { 28 | 29 | private LatestVersionQuery query; 30 | 31 | public LatestStandaloneCartridge(final String name) { 32 | this.query = new LatestVersionQuery(name); 33 | } 34 | 35 | public boolean matches(ICartridge cartridge) { 36 | return query.matches(cartridge); 37 | } 38 | 39 | public IStandaloneCartridge get(IOpenShiftConnection connection) { 40 | Assert.isTrue(connection != null); 41 | return query.get(connection.getStandaloneCartridges()); 42 | } 43 | 44 | public IStandaloneCartridge get(IApplication application) { 45 | return get(application.getDomain().getUser().getConnection()); 46 | } 47 | 48 | public IStandaloneCartridge get(IUser user) { 49 | Assert.notNull(user); 50 | return get(user.getConnection()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/StringPropertyQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import java.util.regex.Pattern; 14 | 15 | import com.openshift.client.cartridge.ICartridge; 16 | import com.openshift.client.cartridge.IEmbeddableCartridge; 17 | import com.openshift.client.cartridge.IStandaloneCartridge; 18 | import com.openshift.internal.client.utils.Assert; 19 | 20 | /** 21 | * A constraint that shall match available cartridges by url. 22 | * 23 | * @author Andre Dietisheim 24 | * 25 | * @see IEmbeddableCartridge 26 | * @see IStandaloneCartridge 27 | */ 28 | public abstract class StringPropertyQuery extends AbstractCartridgeQuery { 29 | 30 | private final Pattern namePattern; 31 | 32 | public StringPropertyQuery(final String propertyPattern) { 33 | Assert.isTrue(propertyPattern != null); 34 | this.namePattern = Pattern.compile(propertyPattern); 35 | } 36 | 37 | 38 | 39 | public StringPropertyQuery(Pattern pattern) { 40 | Assert.isTrue(pattern != null); 41 | this.namePattern = pattern; 42 | } 43 | 44 | @Override 45 | public boolean matches(C cartridge) { 46 | if (cartridge == null) { 47 | return false; 48 | } 49 | String propertyValue = getProperty(cartridge); 50 | if (propertyValue == null) { 51 | return namePattern == null; 52 | } 53 | return namePattern.matcher(propertyValue).matches(); 54 | } 55 | 56 | protected abstract String getProperty(C cartridge); 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/cartridge/query/UrlPropertyQuery.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.cartridge.query; 12 | 13 | import java.util.regex.Pattern; 14 | 15 | import com.openshift.client.cartridge.IEmbeddedCartridge; 16 | import com.openshift.internal.client.response.CartridgeResourceProperty; 17 | 18 | /** 19 | * @author André Dietisheim 20 | */ 21 | public class UrlPropertyQuery { 22 | 23 | private static final Pattern NAME_URL_PATTERN = Pattern.compile("url", Pattern.CASE_INSENSITIVE); 24 | 25 | public CartridgeResourceProperty getMatchingProperty(IEmbeddedCartridge embeddedCartridge) { 26 | for (CartridgeResourceProperty property : embeddedCartridge.getProperties().getAll()) { 27 | if (NAME_URL_PATTERN.matcher(property.getName()).find()) { 28 | return property; 29 | } 30 | } 31 | return null; 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/configuration/DefaultConfiguration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011-2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.configuration; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.util.Properties; 16 | 17 | import com.openshift.client.OpenShiftException; 18 | 19 | /** 20 | * @author André Dietisheim 21 | * @author Corey Daley 22 | */ 23 | public class DefaultConfiguration extends AbstractOpenshiftConfiguration { 24 | 25 | public static final String LIBRA_SERVER = System.getenv(KEY_OPENSHIFT_BROKER_HOST) != null ? System.getenv(KEY_OPENSHIFT_BROKER_HOST) : "openshift.redhat.com"; 26 | public static final String LIBRA_DOMAIN = System.getenv(KEY_OPENSHIFT_CLOUD_DOMAIN) != null ? System.getenv(KEY_OPENSHIFT_CLOUD_DOMAIN) : "rhcloud.com"; 27 | 28 | public DefaultConfiguration() throws OpenShiftException, IOException { 29 | super(); 30 | } 31 | 32 | @Override 33 | protected Properties getProperties(File file, Properties defaultProperties) { 34 | Properties properties = new Properties(); 35 | properties.put(KEY_LIBRA_SERVER, LIBRA_SERVER); 36 | properties.put(KEY_LIBRA_DOMAIN, LIBRA_DOMAIN); 37 | properties.put(KEY_TIMEOUT, DEFAULT_OPENSHIFT_TIMEOUT); 38 | properties.put(KEY_DISABLE_BAD_SSL_CIPHERS, ConfigurationOptions.NO.toString()); 39 | return properties; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/configuration/IOpenShiftConfiguration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011-2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.configuration; 12 | 13 | import java.util.Properties; 14 | 15 | import com.openshift.client.configuration.AbstractOpenshiftConfiguration.ConfigurationOptions; 16 | 17 | /** 18 | * @author André Dietisheim 19 | * @author Corey Daley 20 | */ 21 | public interface IOpenShiftConfiguration { 22 | 23 | public String getRhlogin(); 24 | 25 | public void setRhlogin(String rhlogin); 26 | 27 | public String getLibraServer(); 28 | 29 | public void setLibraServer(String libraServer); 30 | 31 | public String getLibraDomain(); 32 | 33 | public Integer getTimeout(); 34 | 35 | public void setLibraDomain(String libraDomain); 36 | 37 | public ConfigurationOptions getDisableBadSSLCiphers(); 38 | 39 | public void setDisableBadSSLCiphers(ConfigurationOptions option); 40 | 41 | public Properties getProperties(); 42 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/configuration/OpenShiftConfiguration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011-2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.configuration; 12 | 13 | import java.io.IOException; 14 | 15 | import com.openshift.client.OpenShiftException; 16 | 17 | /** 18 | * @author André Dietisheim 19 | */ 20 | public class OpenShiftConfiguration extends AbstractOpenshiftConfiguration { 21 | 22 | public OpenShiftConfiguration() throws IOException, OpenShiftException { 23 | super(new SystemProperties( 24 | new UserConfiguration( 25 | new SystemConfiguration( 26 | new DefaultConfiguration())))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/configuration/SystemConfiguration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.configuration; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | 16 | import com.openshift.client.OpenShiftException; 17 | 18 | /** 19 | * The system wide OpenShift configuration that is at /etc/express.conf 20 | * 21 | * @author André Dietisheim 22 | */ 23 | public class SystemConfiguration extends AbstractOpenshiftConfiguration { 24 | 25 | private static final String CONFIGURATION_FOLDER = File.separatorChar + "etc" + File.separatorChar + "openshift"; 26 | private static final String CONFIGURATION_FILE = "express.conf"; 27 | 28 | public SystemConfiguration(IOpenShiftConfiguration parentConfiguration) throws OpenShiftException, IOException { 29 | super(new File(CONFIGURATION_FOLDER, CONFIGURATION_FILE), parentConfiguration); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/configuration/SystemProperties.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.configuration; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.util.Properties; 16 | 17 | import com.openshift.client.OpenShiftException; 18 | 19 | /** 20 | * @author André Dietisheim 21 | * @author Corey Daley 22 | */ 23 | public class SystemProperties extends AbstractOpenshiftConfiguration { 24 | 25 | protected static final String KEY_OPENSHIFT_TIMEOUT = "express.timeout"; 26 | 27 | public SystemProperties(IOpenShiftConfiguration parentConfiguration) throws OpenShiftException, IOException { 28 | super(parentConfiguration); 29 | } 30 | 31 | @Override 32 | protected Properties getProperties(File file, Properties defaultProperties) { 33 | Properties properties = new Properties(defaultProperties); 34 | copySystemProperty(KEY_LIBRA_DOMAIN, properties); 35 | copySystemProperty(KEY_LIBRA_SERVER, properties); 36 | copySystemProperty(KEY_RHLOGIN, properties); 37 | copySystemProperty(KEY_PASSWORD, properties); 38 | copySystemProperty(KEY_CLIENT_ID, properties); 39 | copySystemProperty(KEY_OPENSHIFT_TIMEOUT, properties); 40 | copySystemProperty(KEY_DISABLE_BAD_SSL_CIPHERS, properties); 41 | return properties; 42 | } 43 | 44 | private void copySystemProperty(String key, Properties properties) { 45 | Object value = System.getProperties().get(key); 46 | if (key.equals(KEY_OPENSHIFT_TIMEOUT) && value != null) { 47 | properties.put(KEY_TIMEOUT, value); 48 | } else if (value != null) { 49 | properties.put(key, value); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/configuration/UserConfiguration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.configuration; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | 16 | import com.openshift.client.OpenShiftException; 17 | 18 | /** 19 | * @author André Dietisheim 20 | */ 21 | public class UserConfiguration extends AbstractOpenshiftConfiguration { 22 | 23 | private static final String CONFIGURATION_FOLDER = ".openshift"; 24 | private static final String CONFIGURATION_FILE = "express.conf"; 25 | private static final String PROPERTY_USERHOME = "user.home"; 26 | 27 | public UserConfiguration(SystemConfiguration systemConfiguration) throws OpenShiftException, IOException { 28 | super(new File(System.getProperty(PROPERTY_USERHOME) + File.separatorChar + CONFIGURATION_FOLDER, CONFIGURATION_FILE), systemConfiguration); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/utils/HostUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import java.net.InetAddress; 14 | import java.net.MalformedURLException; 15 | import java.net.URL; 16 | import java.net.UnknownHostException; 17 | 18 | /** 19 | * @author Andre Dietisheim 20 | */ 21 | public class HostUtils { 22 | 23 | public static boolean canResolv(String urlString) throws MalformedURLException { 24 | try { 25 | URL url = new URL(urlString); 26 | String host = url.getHost(); 27 | return InetAddress.getByName(host) != null; 28 | } catch (UnknownHostException e) { 29 | return false; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/utils/OpenShiftResourceUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import com.openshift.client.cartridge.ICartridge; 17 | 18 | /** 19 | * @author Andre Dietisheim 20 | */ 21 | public class OpenShiftResourceUtils { 22 | 23 | public static List toNames(ICartridge... cartridges) { 24 | List cartridgeNames = new ArrayList(); 25 | if (cartridges == null) { 26 | return cartridgeNames; 27 | } 28 | for (ICartridge cartridge : cartridges) { 29 | if (cartridge == null) { 30 | continue; 31 | } 32 | cartridgeNames.add(cartridge.getName()); 33 | } 34 | return cartridgeNames; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/utils/RFC822DateUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import java.util.Date; 14 | import java.util.GregorianCalendar; 15 | 16 | import javax.xml.datatype.DatatypeConfigurationException; 17 | import javax.xml.datatype.DatatypeFactory; 18 | 19 | /** 20 | * @author André Dietisheim 21 | */ 22 | public class RFC822DateUtils { 23 | 24 | /** 25 | * Returns a date instance for a given timestamp string that complies to the 26 | * RFC 822 standard 27 | * 28 | * @param rfc822DateString 29 | * @return 30 | * @throws DatatypeConfigurationException 31 | */ 32 | public static Date getDate(String rfc822DateString) throws DatatypeConfigurationException { 33 | // SimpleDateFormat can't handle RFC822 (-04:00 instead of GMT-04:00) 34 | // date formats 35 | // 36 | // SimpleDateFormat dateFormat = new 37 | // SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 38 | // return dateFormat.parse(propertyNode.asString()); 39 | GregorianCalendar calendar = 40 | DatatypeFactory.newInstance() 41 | .newXMLGregorianCalendar(rfc822DateString) 42 | .toGregorianCalendar(); 43 | return calendar.getTime(); 44 | } 45 | 46 | /** 47 | * Returns a date instance for a given timestamp string that complies to the 48 | * RFC 822 standard. If an error occurs, null is returned an 49 | * no exception is thrown. 50 | * 51 | * @param rfc822DateString 52 | * @return 53 | */ 54 | public static Date safeGetDate(String rfc822DateString) { 55 | try { 56 | return getDate(rfc822DateString); 57 | } catch (DatatypeConfigurationException e) { 58 | return null; 59 | } 60 | } 61 | 62 | public static String getString(Date date) throws DatatypeConfigurationException { 63 | GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance(); 64 | return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toXMLFormat(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/client/utils/TarFileUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | 16 | import org.apache.commons.compress.archivers.tar.TarArchiveEntry; 17 | import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; 18 | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; 19 | 20 | import com.openshift.internal.client.utils.StreamUtils; 21 | 22 | /** 23 | * @author Andre Dietisheim 24 | */ 25 | public class TarFileUtils { 26 | 27 | private static final String GIT_FOLDER_NAME = "git"; 28 | 29 | private TarFileUtils() { 30 | // inhibit instantiation 31 | } 32 | 33 | public static boolean hasGitFolder(InputStream inputStream) throws IOException { 34 | TarArchiveInputStream tarInputStream = null; 35 | try { 36 | boolean gitFolderPresent = false; 37 | tarInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(inputStream)); 38 | for (TarArchiveEntry entry = null; (entry = tarInputStream.getNextTarEntry()) != null;) { 39 | if (GIT_FOLDER_NAME.equals(entry.getName()) 40 | && entry.isDirectory()) { 41 | gitFolderPresent = true; 42 | break; 43 | } 44 | } 45 | return gitFolderPresent; 46 | } finally { 47 | StreamUtils.close(tarInputStream); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/AbstractOpenShiftConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012-2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import java.io.IOException; 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | import com.openshift.client.HttpMethod; 18 | import com.openshift.client.IHttpClient; 19 | import com.openshift.client.IOpenShiftConnection; 20 | import com.openshift.client.OpenShiftException; 21 | import com.openshift.internal.client.httpclient.request.Parameter; 22 | import com.openshift.internal.client.response.Link; 23 | import com.openshift.internal.client.response.RestResponse; 24 | 25 | /** 26 | * Connection Factory, used to establish a connection and retrieve a user. 27 | * 28 | * @author Xavier Coulon 29 | * @author Andre Dietisheim 30 | * @author Sean Kavanagh 31 | * 32 | */ 33 | public abstract class AbstractOpenShiftConnectionFactory { 34 | 35 | @SuppressWarnings("unchecked") 36 | protected IOpenShiftConnection getConnection(IRestService service, final String login, final String password, final String token) throws IOException, OpenShiftException { 37 | RestResponse response = 38 | (RestResponse) service.request( 39 | new Link("Get API", "/api", HttpMethod.GET), 40 | IHttpClient.NO_TIMEOUT, 41 | Collections. emptyList(), 42 | Collections. emptyList()); 43 | return new APIResource(login, password, token, service, (Map) response.getData()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/AlternativeCartridges.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import java.util.List; 14 | 15 | import com.openshift.client.cartridge.ICartridge; 16 | import com.openshift.client.cartridge.query.ICartridgeQuery; 17 | 18 | /** 19 | * A list of alternative cartridges that one can choose from. The user 20 | * may only pick 1 cartridge among the alternatives. 21 | * 22 | * @author Andre Dietisheim 23 | * 24 | */ 25 | public class AlternativeCartridges { 26 | 27 | private ICartridgeQuery query; 28 | private APIResource api; 29 | 30 | AlternativeCartridges(ICartridgeQuery query, APIResource api) { 31 | this.query = query; 32 | this.api = api; 33 | } 34 | 35 | /** 36 | * Returns all alternative cartridges that a user may choose its cartridge 37 | * from. 38 | * 39 | * @return the alternative cartridges 40 | */ 41 | public List get() { 42 | return query.getAll(api.getCartridges(true)); // include obsolete cartridges 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "AlternativeCartridges [query=" + query + "]"; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/CartridgeType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | 14 | public enum CartridgeType { 15 | 16 | EMBEDDED, STANDALONE, UNDEFINED; 17 | 18 | public static CartridgeType safeValueOf(String type) { 19 | try { 20 | if (type == null) { 21 | return null; 22 | } 23 | return valueOf(type.toUpperCase()); 24 | } catch(IllegalArgumentException e) { 25 | return null; 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/Field.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import com.openshift.client.IField; 14 | 15 | /** 16 | * @author Andre Dietisheim 17 | */ 18 | public class Field implements IField { 19 | 20 | private final String field; 21 | 22 | public Field(String field) { 23 | this.field = field; 24 | } 25 | 26 | public String getValue() { 27 | return field; 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | final int prime = 31; 33 | int result = 1; 34 | result = prime * result + ((field == null) ? 0 : field.hashCode()); 35 | return result; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (this == obj) 41 | return true; 42 | if (obj == null) 43 | return false; 44 | if (getClass() != obj.getClass()) 45 | return false; 46 | Field other = (Field) obj; 47 | if (field == null) { 48 | if (other.field != null) 49 | return false; 50 | } else if (!field.equals(other.field)) 51 | return false; 52 | return true; 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/Gear.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import com.openshift.client.GearState; 14 | import com.openshift.client.IGear; 15 | 16 | 17 | /** 18 | * A gear that a cartridge is running on. 19 | * 20 | * @author Andre Dietisheim 21 | */ 22 | public class Gear implements IGear { 23 | 24 | private final String id; 25 | private GearState state; 26 | private final String sshUrl; 27 | 28 | public Gear(String id, GearState state, String sshUrl) { 29 | this.id = id; 30 | this.state = state; 31 | this.sshUrl = sshUrl; 32 | } 33 | 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | public GearState getState() { 39 | return state; 40 | } 41 | 42 | /** 43 | * @return the sshUrl 44 | */ 45 | public String getSshUrl() { 46 | return sshUrl; 47 | } 48 | 49 | public String toString() { 50 | return "Gear [id=" + id + ", state=" + state + "]"; 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/GearProfile.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import com.openshift.client.IGearProfile; 14 | import com.openshift.internal.client.utils.Assert; 15 | 16 | /** 17 | * @author Andre Dietisheim 18 | */ 19 | public class GearProfile implements IGearProfile { 20 | 21 | private String name; 22 | 23 | public GearProfile(String name) { 24 | Assert.notNull(name); 25 | 26 | this.name = name; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | final int prime = 31; 36 | int result = 1; 37 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 38 | return result; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object obj) { 43 | if (this == obj) 44 | return true; 45 | if (obj == null) 46 | return false; 47 | if (getClass() != obj.getClass()) 48 | return false; 49 | GearProfile other = (GearProfile) obj; 50 | if (name == null) { 51 | if (other.name != null) 52 | return false; 53 | } else if (!name.equals(other.name)) 54 | return false; 55 | return true; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "GearProfile [name=" + name + "]"; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/Severity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import com.openshift.client.ISeverity; 14 | 15 | /** 16 | * @author Andre Dietisheim 17 | */ 18 | public class Severity implements ISeverity { 19 | 20 | private final String severity; 21 | 22 | public Severity(String severity) { 23 | this.severity = severity; 24 | } 25 | 26 | public String getValue() { 27 | return severity; 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | final int prime = 31; 33 | int result = 1; 34 | result = prime * result + ((severity == null) ? 0 : severity.hashCode()); 35 | return result; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) { 40 | if (this == obj) 41 | return true; 42 | if (obj == null) 43 | return false; 44 | if (getClass() != obj.getClass()) 45 | return false; 46 | Severity other = (Severity) obj; 47 | if (severity == null) { 48 | if (other.severity != null) 49 | return false; 50 | } else if (!severity.equals(other.severity)) 51 | return false; 52 | return true; 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/BadRequestException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public class BadRequestException extends HttpClientException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public BadRequestException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public BadRequestException(Throwable cause) { 25 | super(cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/CallbackTrustManager.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | import java.security.cert.CertificateException; 14 | import java.security.cert.X509Certificate; 15 | 16 | import javax.net.ssl.X509TrustManager; 17 | 18 | import com.openshift.internal.client.utils.Assert; 19 | 20 | /** 21 | * A trust manager that calls a callback if the wrapped trustmanager fails to 22 | * validate a given certificate. 23 | * 24 | * @author Andre Dietisheim 25 | * 26 | * @see TrustManagerCallback 27 | */ 28 | public class CallbackTrustManager implements X509TrustManager { 29 | 30 | private X509TrustManager trustManager; 31 | private TrustManagerCallback callback; 32 | 33 | private CallbackTrustManager(X509TrustManager trustManager, TrustManagerCallback callback) { 34 | Assert.isTrue(trustManager != null); 35 | this.trustManager = trustManager; 36 | this.callback = callback; 37 | } 38 | 39 | public X509Certificate[] getAcceptedIssuers() { 40 | return trustManager.getAcceptedIssuers(); 41 | } 42 | 43 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 44 | try { 45 | trustManager.checkServerTrusted(chain, authType); 46 | } catch (CertificateException e) { 47 | if (callback.allow(chain)) { 48 | throw e; 49 | } 50 | } 51 | } 52 | 53 | public void checkClientTrusted(X509Certificate[] chain, 54 | String authType) throws CertificateException { 55 | trustManager.checkServerTrusted(chain, authType); 56 | } 57 | 58 | public interface TrustManagerCallback { 59 | 60 | public boolean allow(X509Certificate[] chain); 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/EncodingException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | 14 | /** 15 | * @author Ioannis Canellos 16 | */ 17 | public class EncodingException extends HttpClientException { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | public EncodingException(String message, Throwable t) { 22 | super(message, t); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/HttpClientException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public class HttpClientException extends RuntimeException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public HttpClientException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public HttpClientException(String message) { 25 | super(message); 26 | } 27 | 28 | public HttpClientException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/InternalServerErrorException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public class InternalServerErrorException extends HttpClientException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public InternalServerErrorException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public InternalServerErrorException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/NotFoundException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public class NotFoundException extends HttpClientException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public NotFoundException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public NotFoundException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/UnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public class UnauthorizedException extends HttpClientException { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | public UnauthorizedException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public UnauthorizedException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/request/IMediaType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient.request; 12 | 13 | import java.io.OutputStream; 14 | 15 | import com.openshift.client.IHttpClient; 16 | import com.openshift.internal.client.httpclient.EncodingException; 17 | 18 | /** 19 | * 20 | * A media type that encodes and writes request parameters before they get sent by the client. 21 | * 22 | * @author Andre Dietisheim 23 | * 24 | * @see IHttpClient#post(java.net.URL, IMediaType, int, com.openshift.internal.client.httpclient.request.Parameter...) 25 | * @see IHttpClient#put(java.net.URL, IMediaType, int, com.openshift.internal.client.httpclient.request.Parameter...) 26 | * @see IHttpClient#delete(java.net.URL, IMediaType, int, com.openshift.internal.client.httpclient.request.Parameter...) 27 | */ 28 | public interface IMediaType { 29 | 30 | public String getType(); 31 | 32 | public void writeTo(ParameterValueMap parameterMap, OutputStream out) throws EncodingException; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/request/Parameter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient.request; 12 | 13 | /** 14 | * A parameter wrapper to pass param key/values to the service when executing a 15 | * remote operation from a link. 16 | * 17 | * @author Andre Dietisheim 18 | * 19 | */ 20 | public class Parameter extends ParameterValue> { 21 | 22 | private final String name; 23 | 24 | public Parameter(final String name, final String value) { 25 | this(name, new StringValue(value)); 26 | } 27 | 28 | public Parameter(final String name, final ParameterValue value) { 29 | super(value); 30 | this.name = name; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | final int prime = 31; 40 | int result = 1; 41 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 42 | result = prime * result + ((getValue() == null) ? 0 : getValue().hashCode()); 43 | return result; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) 49 | return true; 50 | if (obj == null) 51 | return false; 52 | if (getClass() != obj.getClass()) 53 | return false; 54 | Parameter other = (Parameter) obj; 55 | if (name == null) { 56 | if (other.name != null) 57 | return false; 58 | } else if (!name.equals(other.name)) 59 | return false; 60 | if (getValue() == null) { 61 | if (other.getValue() != null) 62 | return false; 63 | } else if (!getValue().equals(other.getValue())) 64 | return false; 65 | return true; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "Parameter [" 71 | + "name=" + name 72 | + ", value=" + getValue() 73 | + "]"; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/request/ParameterValue.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | 12 | package com.openshift.internal.client.httpclient.request; 13 | 14 | /** 15 | * @author Andre Dietisheim 16 | */ 17 | public abstract class ParameterValue { 18 | 19 | private V value; 20 | 21 | public ParameterValue(V value) { 22 | this.value = value; 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | final int prime = 31; 28 | int result = 1; 29 | result = prime * result + ((value == null) ? 0 : value.hashCode()); 30 | return result; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object obj) { 35 | if (this == obj) 36 | return true; 37 | if (obj == null) 38 | return false; 39 | if (getClass() != obj.getClass()) 40 | return false; 41 | @SuppressWarnings("rawtypes") 42 | ParameterValue other = (ParameterValue) obj; 43 | if (value == null) { 44 | if (other.value != null) 45 | return false; 46 | } else if (!value.equals(other.value)) 47 | return false; 48 | return true; 49 | } 50 | 51 | public V getValue() { 52 | return value; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "ParameterValue [value=" + value + "]"; 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/request/ParameterValueArray.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient.request; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | import java.util.List; 16 | 17 | /** 18 | * @author Andre Dietisheim 19 | */ 20 | public class ParameterValueArray extends ParameterValue>> { 21 | 22 | public ParameterValueArray() { 23 | this(new ArrayList>()); 24 | } 25 | 26 | public ParameterValueArray(List> values) { 27 | super(values); 28 | } 29 | 30 | public ParameterValueArray add(String name, String value) { 31 | return add(new StringParameter(name, value)); 32 | } 33 | 34 | public ParameterValueArray add(ParameterValue value) { 35 | getValue().add(value); 36 | return this; 37 | } 38 | 39 | public ParameterValueArray addAll(List> values) { 40 | getValue().addAll(values); 41 | return this; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "ParameterValueArray [" 47 | + "values=" + Arrays.toString(getValue().toArray()) + "]"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/request/StringParameter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient.request; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class StringParameter extends Parameter { 17 | 18 | public StringParameter(final String name, final String value) { 19 | super(name, new StringValue(value)); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "StringParameter [" 25 | + "name=" + getName() 26 | + ", value=" + getValue() 27 | + "]"; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/httpclient/request/StringValue.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.httpclient.request; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class StringValue extends ParameterValue { 17 | 18 | public StringValue(String value) { 19 | super(value); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "StringValue [" 25 | + "value=" + getValue() 26 | + "]"; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/AuthorizationResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Sean Kavanagh - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import com.openshift.client.Messages; 14 | 15 | import java.util.Map; 16 | 17 | /** 18 | * @author Sean Kavanagh 19 | * @author Andre Dietisheim 20 | */ 21 | public class AuthorizationResourceDTO extends BaseResourceDTO { 22 | 23 | /* authorization id */ 24 | private final String id; 25 | /* authorization note */ 26 | private final String note; 27 | /* authorization scopes */ 28 | private final String scopes; 29 | /* authorization token */ 30 | private final String token; 31 | private int expiresIn; 32 | 33 | AuthorizationResourceDTO(final String id, String note, String scopes, String token, int expiresIn, 34 | final Map links, 35 | final Messages messages) { 36 | super(links, messages); 37 | this.id = id; 38 | this.note = note; 39 | this.scopes = scopes; 40 | this.token = token; 41 | this.expiresIn = expiresIn; 42 | } 43 | 44 | public String getId() { 45 | return id; 46 | } 47 | 48 | public String getNote() { 49 | return note; 50 | } 51 | 52 | public String getScopes() { 53 | return scopes; 54 | } 55 | 56 | public String getToken() { 57 | return token; 58 | } 59 | 60 | public int getExpiresIn() { 61 | return expiresIn; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/BaseResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | import com.openshift.client.Messages; 17 | 18 | /** 19 | * The Class BaseResourceDTO. 20 | * 21 | * @param 22 | * the generic type 23 | */ 24 | public abstract class BaseResourceDTO { 25 | 26 | /** the indexed map of links to perform operations from this resource. */ 27 | private final Map links; 28 | private final Messages messages; 29 | 30 | protected BaseResourceDTO() { 31 | this(new HashMap(), null); 32 | } 33 | 34 | /** 35 | * Instantiates a new base resource dto. 36 | * 37 | * @param links 38 | * the links 39 | */ 40 | protected BaseResourceDTO(final Map links, Messages messages) { 41 | this.links = links; 42 | this.messages = messages; 43 | } 44 | 45 | /** 46 | * Gets the links. 47 | * 48 | * @return all the links 49 | */ 50 | public final Map getLinks() { 51 | return links; 52 | } 53 | 54 | /** 55 | * Gets the link. 56 | * 57 | * @param name 58 | * the name of the link to look for. 59 | * @return the named link 60 | */ 61 | public final Link getLink(String name) { 62 | return links.get(name); 63 | } 64 | 65 | /** 66 | * Returns the messages that were reported when this resource was created. 67 | * May be null if retrieved in a session in which we did not 68 | * create this resource. 69 | * 70 | * @return the messages that were reported when this resource was created 71 | */ 72 | public Messages getMessages() { 73 | return messages; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/CartridgeResourceProperties.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.LinkedHashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | import com.openshift.internal.client.utils.CollectionUtils; 18 | 19 | /** 20 | * Properties that hold informations available in cartridges 21 | * 22 | * @author Andre Dietisheim 23 | */ 24 | public class CartridgeResourceProperties { 25 | 26 | public static final String CONNECTION_URL = "connection_url"; 27 | public static final String JOB_URL = "job_url"; 28 | public static final String USERNAME = "username"; 29 | public static final String PASSWORD = "password"; 30 | public static final String DATABASE_NAME = "database_name"; 31 | 32 | private Map properties = new LinkedHashMap(); 33 | 34 | public String getPropertyValue(String name) { 35 | CartridgeResourceProperty property = properties.get(name); 36 | if (property == null) { 37 | return null; 38 | } 39 | return property.getValue(); 40 | } 41 | 42 | public void add(String name, CartridgeResourceProperty property) { 43 | properties.put(name, property); 44 | } 45 | 46 | public CartridgeResourceProperty getProperty(String name) { 47 | return properties.get(name); 48 | } 49 | 50 | public List getAll() { 51 | return CollectionUtils.toUnmodifiableCopy(properties.values()); 52 | } 53 | 54 | public int size() { 55 | return properties.size(); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "ResourceProperties [ " 61 | + "properties=" + properties + 62 | " ]"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/DomainResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.Map; 14 | 15 | import com.openshift.client.Messages; 16 | 17 | /** 18 | * @author Xavier Coulon 19 | */ 20 | public class DomainResourceDTO extends BaseResourceDTO { 21 | 22 | /** the domain's configured id. */ 23 | private final String id; 24 | /** the domain's configured suffix (cannot be configured by user, returned by platform). */ 25 | private String suffix; 26 | 27 | DomainResourceDTO(final String id, final String suffix, final Map links, final Messages messages) { 28 | super(links, messages); 29 | this.id = id; 30 | this.suffix = suffix; 31 | } 32 | 33 | /** 34 | * @return the id 35 | */ 36 | public final String getId() { 37 | return id; 38 | } 39 | 40 | public String getSuffix() { 41 | return suffix; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/DownloadableCartridgeSpec.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.net.MalformedURLException; 14 | import java.net.URL; 15 | import java.util.Collections; 16 | import java.util.List; 17 | 18 | import com.openshift.client.cartridge.ICartridge; 19 | import com.openshift.client.cartridge.query.ICartridgeQuery; 20 | import com.openshift.internal.client.cartridge.BaseCartridge; 21 | 22 | /** 23 | * @author Andre Dietisheim 24 | */ 25 | public class DownloadableCartridgeSpec implements ICartridgeQuery { 26 | 27 | private final ICartridge cartridge; 28 | 29 | protected DownloadableCartridgeSpec(String url) throws MalformedURLException { 30 | this(new URL(url)); 31 | } 32 | 33 | protected DownloadableCartridgeSpec(URL url) { 34 | this.cartridge = new BaseCartridge(url); 35 | } 36 | 37 | @SuppressWarnings("unchecked") 38 | @Override 39 | public List getAll(List cartridges) { 40 | return (List) Collections.singletonList(cartridge); 41 | } 42 | 43 | @SuppressWarnings("unchecked") 44 | @Override 45 | public C get(List cartridges) { 46 | return (C) cartridge; 47 | } 48 | 49 | @Override 50 | public boolean matches(C cartridge) { 51 | return this.cartridge.equals(cartridge); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "DownloadableCartridgeSpec [cartridge=" + cartridge + "]"; 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/EnumDataType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012-2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.regex.Pattern; 14 | 15 | /** 16 | * The Enum EnumDataType. 17 | * 18 | * @author Xavier Coulon 19 | * @author Andre Dieitsheim 20 | * @author Sean Kavanagh 21 | */ 22 | public enum EnumDataType { 23 | 24 | /** Links / the root node that allows for navigation amongst resources.*/ 25 | links, 26 | user, 27 | /** the user's keys. */ 28 | keys, 29 | /** one user's key.*/ 30 | key, 31 | domains, 32 | domain, 33 | applications, 34 | application, 35 | authorization, 36 | authorizations, 37 | /** The embedded cartridge type. */ 38 | embedded, 39 | gear_groups, 40 | /** The standalone cartridges type. */ 41 | cartridges, 42 | /** The standalone cartridge type. */ 43 | cartridge, 44 | /** The environment-variables type*/ 45 | environment_variables, 46 | /** The environment-variable type*/ 47 | environment_variable 48 | ; 49 | 50 | private static final Pattern pattern = Pattern.compile("-"); 51 | 52 | /** 53 | * Returns the enum value matching the given value (as string), or 'undefined' if null/unknown value. 54 | * 55 | * @param value 56 | * as String 57 | * @return value as enum 58 | */ 59 | static EnumDataType safeValueOf(String value) { 60 | if (value != null) { 61 | try { 62 | return valueOf(pattern.matcher(value).replaceAll("_")); 63 | } catch (IllegalArgumentException e) { 64 | // do nothing, will just return 'undefined' 65 | } 66 | } 67 | return null; 68 | } 69 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/EnvironmentVariableResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.Map; 14 | 15 | import com.openshift.client.Messages; 16 | 17 | /** 18 | * The DTO for an environment variable 19 | * 20 | * @author Syed Iqbal 21 | * 22 | */ 23 | public class EnvironmentVariableResourceDTO extends BaseResourceDTO{ 24 | /** The environment variable's name. */ 25 | private final String name; 26 | 27 | /** the environment variable's value */ 28 | private final String value; 29 | 30 | /** 31 | * Instantiates a new environment variable resource dto. 32 | * 33 | * @param name 34 | * the name 35 | * @param value 36 | * the value 37 | */ 38 | public EnvironmentVariableResourceDTO(final String name, final String value, final Map links,final Messages messages) { 39 | super(links, messages); 40 | this.name = name; 41 | this.value = value; 42 | } 43 | 44 | /** 45 | * Returns the name of this environment variable 46 | * 47 | * @return the name 48 | */ 49 | public final String getName() { 50 | return name; 51 | } 52 | 53 | /** 54 | * Returns the value of this gear group. 55 | * 56 | * @return the value 57 | */ 58 | public final String getValue() { 59 | return value; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/GearResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.HashMap; 14 | 15 | /** 16 | * The Class ApplicationDTO. 17 | * 18 | * @author Xavier Coulon 19 | */ 20 | public class GearResourceDTO extends BaseResourceDTO { 21 | 22 | /** uuid the Gear UUID. */ 23 | private final String uuid; 24 | 25 | /** state the Gear state. */ 26 | private final String state; 27 | 28 | /** the URL to connect with SSH. */ 29 | private final String sshUrl; 30 | 31 | /** 32 | * Constructor 33 | * @param uuid the Gear UUID 34 | * @param state the Gear state 35 | * @param sshUrl the URL to connect with SSH 36 | */ 37 | GearResourceDTO(String uuid, String state, String sshUrl) { 38 | super(new HashMap(), null); 39 | this.uuid = uuid; 40 | this.sshUrl = sshUrl; 41 | this.state = state; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "GearResourceDTO"; 47 | } 48 | 49 | public String getUuid() { 50 | return uuid; 51 | } 52 | 53 | public String getState() { 54 | return state; 55 | } 56 | 57 | /** 58 | * @return the sshUrl 59 | */ 60 | public String getSshUrl() { 61 | return sshUrl; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/IRestResponseFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import com.openshift.client.OpenShiftException; 14 | 15 | public interface IRestResponseFactory { 16 | 17 | /** 18 | * Returns a {@link RestResponse} instance for a given rest response string. 19 | * @param rest response string 20 | * @return RestResponse instance 21 | * @throws OpenShiftException 22 | * 23 | * @see RestResponse 24 | */ 25 | public RestResponse get(final String restResponse) throws OpenShiftException; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/KeyResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.Map; 14 | 15 | import com.openshift.client.Messages; 16 | 17 | /** 18 | * The Class KeyResourceDTO. 19 | */ 20 | public class KeyResourceDTO extends BaseResourceDTO { 21 | 22 | /** The name. */ 23 | private final String name; 24 | 25 | /** The type. */ 26 | private final String type; 27 | 28 | /** The public key content. */ 29 | private final String content; 30 | 31 | /** 32 | * Instantiates a new key resource dto. 33 | * 34 | * @param name 35 | * the name 36 | * @param type 37 | * the type 38 | * @param content 39 | * the content 40 | * @param links 41 | * the links 42 | */ 43 | KeyResourceDTO(final String name, final String type, final String content, final Map links, final Messages messages) { 44 | super(links, messages); 45 | this.name = name; 46 | this.type = type; 47 | this.content = content; 48 | } 49 | 50 | /** 51 | * Returns the name. 52 | * 53 | * @return the name 54 | */ 55 | public final String getName() { 56 | return name; 57 | } 58 | 59 | /** 60 | * Returns the type. 61 | * 62 | * @return the type 63 | */ 64 | public final String getType() { 65 | return type; 66 | } 67 | 68 | /** 69 | * Returns the public key content. 70 | * 71 | * @return the public key content 72 | */ 73 | public final String getContent() { 74 | return content; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "KeyResourceDTO [" 80 | + "name=" + name 81 | + ", type=" + type 82 | + ", content=" + content 83 | + "]"; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/LinkParameter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.List; 14 | 15 | import com.openshift.client.OpenShiftRequestException; 16 | 17 | 18 | /** 19 | * @author Xavier Coulon 20 | * @author Andre Dietisheim 21 | */ 22 | public class LinkParameter { 23 | 24 | protected final String name; 25 | protected final LinkParameterType type; 26 | protected final String description; 27 | protected final String defaultValue; 28 | protected final List validOptions; 29 | 30 | protected LinkParameter(final String name, final String type, final String defaultValue, final String description, 31 | final List validOptions) throws OpenShiftRequestException { 32 | this(name, new LinkParameterType(type), defaultValue, description, validOptions); 33 | } 34 | 35 | protected LinkParameter(final String name, final LinkParameterType type, final String defaultValue, final String description, 36 | final List validOptions) throws OpenShiftRequestException { 37 | this.name = name; 38 | this.type = type; 39 | this.description = description; 40 | this.defaultValue = defaultValue; 41 | this.validOptions = validOptions; 42 | } 43 | 44 | /** 45 | * @return the name 46 | */ 47 | public final String getName() { 48 | return name; 49 | } 50 | 51 | /** 52 | * @return the type 53 | */ 54 | public final LinkParameterType getType() { 55 | return type; 56 | } 57 | 58 | /** 59 | * @return the description 60 | */ 61 | public final String getDescription() { 62 | return description; 63 | } 64 | 65 | /** 66 | * @return the defaultValue, or null. Only applicable to optional parameters. 67 | */ 68 | public String getDefaultValue() { 69 | return defaultValue; 70 | } 71 | 72 | public List getValidOptions() { 73 | return validOptions; 74 | } 75 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/LinkParameterType.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | 14 | 15 | /** 16 | * @author Andre Dietisheim 17 | */ 18 | public class LinkParameterType { 19 | 20 | 21 | public static final LinkParameterType STRING = new LinkParameterType("string"); 22 | public static final LinkParameterType BOOLEAN = new LinkParameterType("boolean"); 23 | public static final LinkParameterType INTEGER = new LinkParameterType("integer"); 24 | public static final LinkParameterType ARRAY = new LinkParameterType("array"); 25 | 26 | private String type; 27 | 28 | public LinkParameterType(String type) { 29 | this.type = type; 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | final int prime = 31; 35 | int result = 1; 36 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 37 | return result; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object obj) { 42 | if (this == obj) 43 | return true; 44 | if (obj == null) 45 | return false; 46 | if (getClass() != obj.getClass()) 47 | return false; 48 | LinkParameterType other = (LinkParameterType) obj; 49 | if (type == null) { 50 | if (other.type != null) 51 | return false; 52 | } else if (!type.equals(other.type)) 53 | return false; 54 | return true; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/NamedCartridgeSpec.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | import com.openshift.client.cartridge.ICartridge; 17 | import com.openshift.client.cartridge.query.ICartridgeQuery; 18 | import com.openshift.internal.client.cartridge.BaseCartridge; 19 | 20 | /** 21 | * @author Andre Dietisheim 22 | */ 23 | public class NamedCartridgeSpec implements ICartridgeQuery { 24 | 25 | private final ICartridge cartridge; 26 | 27 | protected NamedCartridgeSpec(String name) { 28 | this.cartridge = new BaseCartridge(name); 29 | } 30 | 31 | @SuppressWarnings("unchecked") 32 | @Override 33 | public List getAll(List cartridges) { 34 | return (List) Collections.singletonList(cartridge); 35 | } 36 | 37 | @SuppressWarnings("unchecked") 38 | @Override 39 | public C get(List cartridges) { 40 | return (C) cartridge; 41 | } 42 | 43 | @Override 44 | public boolean matches(C cartridge) { 45 | return this.cartridge.equals(cartridge); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "NamedCartridgeSpec [cartridge=" + cartridge + "]"; 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/RestResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import com.openshift.client.Messages; 14 | 15 | /** 16 | * The Class Response. 17 | */ 18 | public class RestResponse { 19 | 20 | /** The status. */ 21 | final String status; 22 | 23 | /** The messages in which the service reports errors. */ 24 | final Messages messages; 25 | 26 | /** The type of the payload (data) in this response. */ 27 | final EnumDataType dataType; 28 | 29 | /** The payload (data). */ 30 | final Object data; 31 | 32 | /** 33 | * Instantiates a new response. 34 | * 35 | * @param status the status 36 | * @param messages the messages 37 | * @param data the data 38 | * @param dataType the data type 39 | */ 40 | protected RestResponse(final String status, final Messages messages, final Object data, final EnumDataType dataType) { 41 | this.status = status; 42 | this.messages = messages; 43 | this.data = data; 44 | this.dataType = dataType; 45 | } 46 | 47 | /** 48 | * Gets the status. 49 | * 50 | * @return the status 51 | */ 52 | public final String getStatus() { 53 | return status; 54 | } 55 | 56 | 57 | /** 58 | * Gets the messages. 59 | * 60 | * @return the messages 61 | */ 62 | public final Messages getMessages() { 63 | return messages; 64 | } 65 | 66 | /** 67 | * Gets the data type. 68 | * 69 | * @return the dataType 70 | */ 71 | public final EnumDataType getDataType() { 72 | return dataType; 73 | } 74 | 75 | /** 76 | * Gets the data. 77 | * 78 | * @param the generic type 79 | * @return the data, casted as the caller requires. To avoid ClassCastExceptions, caller may refer to the 80 | * {@link RestResponse#getDataType()} method to discover the actual type of the data. 81 | */ 82 | @SuppressWarnings("unchecked") 83 | public final T getData() { 84 | return (T) data; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/response/UserResourceDTO.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.response; 12 | 13 | import java.util.Map; 14 | 15 | public class UserResourceDTO extends BaseResourceDTO { 16 | 17 | private final String id; 18 | /** the user's login on rhcloud. */ 19 | private final String rhLogin; 20 | 21 | private final int maxGears; 22 | private final int consumedGears; 23 | 24 | UserResourceDTO(final String id, final String rhLogin, final int maxGears, final int consumedGears, final Map links) { 25 | super(links, null); 26 | this.id = id; 27 | this.rhLogin = rhLogin; 28 | this.maxGears = maxGears; 29 | this.consumedGears = consumedGears; 30 | } 31 | 32 | /** 33 | * @return the id 34 | */ 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | /** 40 | * @return the rhLogin 41 | */ 42 | public String getRhLogin() { 43 | return rhLogin; 44 | } 45 | 46 | /** 47 | * @return the maxGears 48 | */ 49 | public int getMaxGears() { 50 | return maxGears; 51 | } 52 | 53 | /** 54 | * @return the consumedGears 55 | */ 56 | public int getConsumedGears() { 57 | return consumedGears; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/ssh/AbstractSSHKey.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.ssh; 12 | 13 | import com.openshift.client.ISSHPublicKey; 14 | import com.openshift.client.OpenShiftUnknownSSHKeyTypeException; 15 | import com.openshift.client.SSHKeyType; 16 | 17 | /** 18 | * @author Andre Dietisheim 19 | */ 20 | public abstract class AbstractSSHKey implements ISSHPublicKey { 21 | 22 | private SSHKeyType keyType; 23 | 24 | protected AbstractSSHKey(SSHKeyType sshKeyType) { 25 | this.keyType = sshKeyType; 26 | } 27 | 28 | public SSHKeyType getKeyType() { 29 | return keyType; 30 | } 31 | 32 | protected void setKeyType(String keyTypeId) throws OpenShiftUnknownSSHKeyTypeException { 33 | setKeyType(SSHKeyType.getByTypeId(keyTypeId)); 34 | } 35 | 36 | protected void setKeyType(SSHKeyType keyType) { 37 | this.keyType = keyType; 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | final int prime = 31; 43 | int result = 1; 44 | result = prime * result + ((keyType == null) ? 0 : keyType.hashCode()); 45 | return result; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object obj) { 50 | if (this == obj) 51 | return true; 52 | if (obj == null) 53 | return false; 54 | if (getClass() != obj.getClass()) 55 | return false; 56 | AbstractSSHKey other = (AbstractSSHKey) obj; 57 | return keyType == other.keyType; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "AbstractSSHKey [keyType=" + keyType + "]"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/utils/Assert.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.utils; 12 | 13 | 14 | 15 | /** 16 | * @author André Dietisheim 17 | */ 18 | public class Assert { 19 | 20 | public static final class AssertionFailedException extends RuntimeException { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public AssertionFailedException() { 25 | super(); 26 | } 27 | 28 | } 29 | 30 | public static V notNull(V value) { 31 | if (value == null) { 32 | throw new AssertionFailedException(); 33 | } 34 | return value; 35 | } 36 | 37 | public static void notEmpty(String value) { 38 | notNull(value); 39 | isTrue(!value.isEmpty()); 40 | } 41 | 42 | public static void isTrue(boolean assertion) { 43 | if (!assertion) { 44 | throw new AssertionFailedException(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/utils/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.utils; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.Collections; 16 | import java.util.List; 17 | 18 | /** 19 | * @author Andre Dietisheim 20 | */ 21 | public class CollectionUtils { 22 | 23 | private CollectionUtils() { 24 | } 25 | 26 | public static List toUnmodifiableCopy(Collection collection) { 27 | return Collections.unmodifiableList(new ArrayList(collection)); 28 | } 29 | 30 | public static List toList(T element, T... elements) { 31 | List allElements = new ArrayList(); 32 | if (element != null) { 33 | allElements.add(element); 34 | } 35 | if (elements != null) { 36 | Collections.addAll(allElements, elements); 37 | } 38 | return allElements; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/utils/IOpenShiftParameterConstants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.utils; 12 | 13 | /** 14 | * @author André Dietisheim 15 | */ 16 | public class IOpenShiftParameterConstants { 17 | 18 | public static final String PARAMETER_ID = "id"; 19 | public static final String PARAMETER_INCLUDE = "include"; 20 | public static final String PARAMETER_CARTRIDGES = "cartridges"; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.utils; 12 | 13 | 14 | /** 15 | * @author André Dietisheim 16 | */ 17 | public class StringUtils { 18 | 19 | public static String toLowerCase(String message) { 20 | if (message == null) { 21 | return null; 22 | } 23 | return message.toLowerCase(); 24 | } 25 | 26 | public static String toLowerCase(Enum aEnum) { 27 | if (aEnum == null) { 28 | return null; 29 | } 30 | return toLowerCase(aEnum.name()); 31 | } 32 | 33 | public static boolean isEmpty(String string) { 34 | return string == null 35 | || string.trim().isEmpty(); 36 | } 37 | 38 | public static String prependIfNonEmpty(String prefix, String string) { 39 | if (isEmpty(prefix)) { 40 | return string; 41 | } 42 | 43 | return prefix + string; 44 | } 45 | 46 | public static String nullToEmptyString(String string) { 47 | if (string == null) { 48 | return ""; 49 | } 50 | return string; 51 | } 52 | 53 | public static String encodeQuotationMarks(String string) { 54 | return string.replaceAll("\"", """); 55 | } 56 | 57 | public static String decodeQuotationMarks(String string) { 58 | return string.replaceAll(""", "\""); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/openshift/internal/client/utils/UrlUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client.utils; 12 | 13 | import java.net.URL; 14 | import java.util.regex.Pattern; 15 | 16 | /** 17 | * @author Andre Dietisheim 18 | */ 19 | public class UrlUtils { 20 | 21 | private static final Pattern URL_PATTERN = Pattern 22 | .compile("(https?|ftp)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"); 23 | 24 | private static final String HTTPS = "https"; 25 | private static final String SCHEMA_SEPARATOR = "://"; 26 | 27 | public static final String SCHEME_HTTPS = HTTPS + SCHEMA_SEPARATOR; 28 | public static final char USERNAME_SEPARATOR = '@'; 29 | 30 | private UrlUtils() { 31 | // inhibit instantiation 32 | } 33 | 34 | public static String ensureStartsWithHttps(String url) { 35 | if (url == null 36 | || url.isEmpty()) { 37 | return url; 38 | } 39 | 40 | if (url.indexOf(SCHEMA_SEPARATOR) > 0) { 41 | return url; 42 | } 43 | 44 | return HTTPS + SCHEMA_SEPARATOR + url; 45 | } 46 | 47 | public static boolean isUrl(String string) { 48 | return URL_PATTERN.matcher(string).matches(); 49 | } 50 | 51 | public static String appendPath(String parent, String child) { 52 | if (parent.charAt(parent.length() - 1) == '/') { 53 | if (child.charAt(0) == '/') { 54 | return parent + child.substring(1); 55 | } else { 56 | return parent + child; 57 | } 58 | } else { 59 | if (child.charAt(0) == '/') { 60 | return parent + child; 61 | } else { 62 | return parent + '/' + child; 63 | } 64 | } 65 | } 66 | 67 | public static String toString(URL url) { 68 | if (url == null) { 69 | return null; 70 | } 71 | return url.toString(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/redhat/openshift/examples/.gitignore: -------------------------------------------------------------------------------- 1 | /domaininfo 2 | -------------------------------------------------------------------------------- /src/main/resources/restservice.properties: -------------------------------------------------------------------------------- 1 | version=${pom.version} 2 | useragent=Java OpenShift REST/{0} ({1}) 3 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/HttpMethodTest.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class HttpMethodTest { 8 | 9 | @Test 10 | public void hasValueForKnownValueShouldReturnTrue() { 11 | assertTrue(HttpMethod.hasValue("POST")); 12 | assertTrue(HttpMethod.hasValue("pOst")); 13 | } 14 | @Test 15 | public void hasValueForUnKnownValueShouldReturnFalse() { 16 | assertFalse(HttpMethod.hasValue("afdadsfads")); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/DefaultConfigurationFake.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client.fakes; 2 | 3 | import com.openshift.client.OpenShiftException; 4 | import com.openshift.client.configuration.DefaultConfiguration; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.util.Properties; 9 | 10 | /** 11 | * Created by cdaley on 3/13/14. 12 | */ 13 | public class DefaultConfigurationFake extends DefaultConfiguration { 14 | public static final String LIBRA_SERVER = "openshift.redhat.com"; 15 | public static final String LIBRA_DOMAIN = "rhcloud.com"; 16 | 17 | public DefaultConfigurationFake() throws OpenShiftException, IOException { 18 | super(); 19 | } 20 | 21 | @Override 22 | protected Properties getProperties(File file, Properties defaultProperties) { 23 | Properties properties = new Properties(); 24 | properties.put(KEY_LIBRA_SERVER, LIBRA_SERVER); 25 | properties.put(KEY_LIBRA_DOMAIN, LIBRA_DOMAIN); 26 | properties.put(KEY_TIMEOUT, DEFAULT_OPENSHIFT_TIMEOUT); 27 | return properties; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/EmptySystemPropertiesFake.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.fakes; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.util.Properties; 16 | 17 | import com.openshift.client.OpenShiftException; 18 | import com.openshift.client.configuration.IOpenShiftConfiguration; 19 | import com.openshift.client.configuration.SystemProperties; 20 | 21 | /** 22 | * @author Andre Dietisheim 23 | */ 24 | public class EmptySystemPropertiesFake extends SystemProperties { 25 | 26 | public EmptySystemPropertiesFake(IOpenShiftConfiguration parentConfiguration) 27 | throws OpenShiftException,IOException { 28 | super(parentConfiguration); 29 | } 30 | 31 | @Override 32 | protected Properties getProperties(File file, Properties defaultProperties) { 33 | return new Properties(defaultProperties); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/OpenShiftConfigurationFake.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client.fakes; 2 | 3 | import com.openshift.client.OpenShiftException; 4 | import com.openshift.client.configuration.*; 5 | 6 | import java.io.File; 7 | import java.io.FileNotFoundException; 8 | import java.io.IOException; 9 | import java.io.Writer; 10 | import java.util.Properties; 11 | 12 | /** 13 | * @author Corey Daley 14 | */ 15 | public class OpenShiftConfigurationFake extends AbstractOpenshiftConfiguration { 16 | public OpenShiftConfigurationFake(final String systemConfigurationTimeout, final String userConfigurationTimeout, final String systemPropertiesTimeout, final String defaultConfigurationTimeout) throws FileNotFoundException, IOException, OpenShiftException { 17 | super(new SystemPropertiesFake( 18 | new UserConfigurationFake( 19 | new SystemConfigurationFake( 20 | new DefaultConfigurationFake(){ 21 | @Override 22 | protected Properties getProperties(File file, Properties defaultProperties) { 23 | Properties properties = new Properties(); 24 | properties.put(KEY_LIBRA_SERVER, LIBRA_SERVER); 25 | properties.put(KEY_LIBRA_DOMAIN, LIBRA_DOMAIN); 26 | if (defaultConfigurationTimeout != null) { 27 | properties.put(KEY_TIMEOUT, defaultConfigurationTimeout); 28 | } else { 29 | properties.put(KEY_TIMEOUT, DEFAULT_OPENSHIFT_TIMEOUT); 30 | } 31 | 32 | return properties; 33 | } 34 | }){ 35 | //SystemConfigurationFake 36 | protected void init(Properties properties) { 37 | if (systemConfigurationTimeout != null) { 38 | properties.put(KEY_TIMEOUT, systemConfigurationTimeout); 39 | } 40 | } 41 | }){ 42 | //UserConfigurationFake 43 | protected void initFile(Writer writer) throws IOException { 44 | if (userConfigurationTimeout != null) { 45 | writer.append(KEY_TIMEOUT).append('=').append(userConfigurationTimeout).append('\n'); 46 | } 47 | } 48 | }){ 49 | //SystemPropertiesFake 50 | @Override 51 | protected Properties getProperties(File file, Properties defaultProperties) { 52 | Properties properties = new Properties(defaultProperties); 53 | if (systemPropertiesTimeout != null) { 54 | properties.setProperty(KEY_TIMEOUT,systemPropertiesTimeout); 55 | } 56 | return properties; 57 | } 58 | }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/SystemConfigurationFake.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.fakes; 12 | 13 | import java.io.File; 14 | import java.io.FileNotFoundException; 15 | import java.io.IOException; 16 | import java.util.Properties; 17 | 18 | import com.openshift.client.OpenShiftException; 19 | import com.openshift.client.configuration.DefaultConfiguration; 20 | import com.openshift.client.configuration.SystemConfiguration; 21 | 22 | /** 23 | * @author André Dietisheim 24 | */ 25 | public class SystemConfigurationFake extends SystemConfiguration { 26 | 27 | public SystemConfigurationFake() throws OpenShiftException, IOException { 28 | this(null); 29 | } 30 | 31 | public SystemConfigurationFake(DefaultConfiguration defaultConfiguration) throws OpenShiftException, IOException { 32 | super(defaultConfiguration); 33 | } 34 | 35 | protected Properties getProperties(File file, Properties defaultProperties) throws FileNotFoundException, IOException { 36 | Properties properties = new Properties(defaultProperties); 37 | init(properties); 38 | return properties; 39 | } 40 | 41 | protected void init(Properties properties) { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/SystemPropertiesFake.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client.fakes; 2 | 3 | import com.openshift.client.OpenShiftException; 4 | import com.openshift.client.configuration.IOpenShiftConfiguration; 5 | import com.openshift.client.configuration.SystemProperties; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * @author Corey Daley 11 | */ 12 | public class SystemPropertiesFake extends SystemProperties { 13 | public SystemPropertiesFake(IOpenShiftConfiguration parentConfiguration) throws OpenShiftException, IOException { 14 | super(parentConfiguration); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/UserConfigurationFake.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.fakes; 12 | 13 | import java.io.File; 14 | import java.io.FileNotFoundException; 15 | import java.io.FileWriter; 16 | import java.io.IOException; 17 | import java.io.Writer; 18 | import java.util.Properties; 19 | 20 | import com.openshift.client.OpenShiftException; 21 | import com.openshift.client.configuration.SystemConfiguration; 22 | import com.openshift.client.configuration.UserConfiguration; 23 | import com.openshift.internal.client.utils.StreamUtils; 24 | 25 | /** 26 | * @author André Dietisheim 27 | */ 28 | public class UserConfigurationFake extends UserConfiguration { 29 | 30 | public UserConfigurationFake() throws OpenShiftException, IOException { 31 | this(null); 32 | } 33 | 34 | public UserConfigurationFake(SystemConfiguration systemConfiguration) throws OpenShiftException, IOException { 35 | super(systemConfiguration); 36 | } 37 | 38 | protected void initProperties(File file, Properties defaultProperties) throws FileNotFoundException, IOException { 39 | file = createFile(); 40 | initFile(file); 41 | super.initProperties(file,defaultProperties); 42 | } 43 | 44 | protected void initFile(File file) { 45 | Writer writer = null; 46 | try { 47 | writer = new FileWriter(file); 48 | initFile(writer); 49 | writer.flush(); 50 | } catch (Exception e) { 51 | throw new RuntimeException(e); 52 | } finally { 53 | try { 54 | StreamUtils.close(writer); 55 | } catch (Exception e) { 56 | throw new RuntimeException(e); 57 | } 58 | } 59 | } 60 | 61 | protected File createFile() { 62 | try { 63 | return File.createTempFile(createRandomString(), null); 64 | } catch (Exception e) { 65 | throw new RuntimeException(e); 66 | } 67 | } 68 | 69 | protected void initFile(Writer writer) throws IOException { 70 | } 71 | 72 | private String createRandomString() { 73 | return String.valueOf(System.currentTimeMillis()); 74 | } 75 | 76 | public File getFile() { 77 | return super.getFile(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/fakes/WaitingHttpServerFake.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.fakes; 12 | 13 | import java.io.IOException; 14 | import java.io.OutputStream; 15 | 16 | /** 17 | * @author Nicolas Spano 18 | * @author Andre Dietisheim 19 | */ 20 | public class WaitingHttpServerFake extends HttpServerFake { 21 | 22 | private long delay; 23 | 24 | @Override 25 | protected void write(byte[] text, OutputStream outputStream) throws IOException { 26 | 27 | try { 28 | Thread.sleep(delay); 29 | } catch (InterruptedException e) { 30 | //Intentional ignored 31 | } 32 | } 33 | 34 | public WaitingHttpServerFake(long delay){ 35 | this.delay = delay; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/CartridgeAsserts.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import java.text.MessageFormat; 16 | import java.util.Collection; 17 | 18 | import com.openshift.client.cartridge.ICartridge; 19 | 20 | /** 21 | * @author André Dietisheim 22 | */ 23 | public class CartridgeAsserts { 24 | 25 | public static void assertThatContainsCartridge(String cartridgeName, Collection cartridges) { 26 | boolean found = false; 27 | for (ICartridge cartridge : cartridges) { 28 | if (cartridgeName.equals(cartridge.getName())) { 29 | found = true; 30 | break; 31 | } 32 | } 33 | if (!found) { 34 | fail(MessageFormat.format("Could not find cartridge with name \"{0}\"", cartridgeName)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/DeployedStandaloneCartridgeAssert.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | 15 | import com.openshift.client.OpenShiftException; 16 | import com.openshift.client.cartridge.IDeployedStandaloneCartridge; 17 | 18 | /** 19 | * @author André Dietisheim 20 | */ 21 | public class DeployedStandaloneCartridgeAssert extends CartridgeAssert { 22 | 23 | public DeployedStandaloneCartridgeAssert(IDeployedStandaloneCartridge cartridge) { 24 | super(cartridge); 25 | } 26 | 27 | public CartridgeAssert isEqualTo(IDeployedStandaloneCartridge otherCartridge) 28 | throws OpenShiftException { 29 | super.isEqualTo(otherCartridge); 30 | 31 | assertThat(getCartridge().getAdditionalGearStorage()).isEqualTo(otherCartridge.getAdditionalGearStorage()); 32 | return this; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/DomainAssert.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | import static org.junit.Assert.assertEquals; 15 | 16 | import org.fest.assertions.AssertExtension; 17 | 18 | import com.openshift.client.IApplication; 19 | import com.openshift.client.IDomain; 20 | import com.openshift.client.OpenShiftException; 21 | 22 | /** 23 | * @author Andre Dietisheim 24 | */ 25 | public class DomainAssert implements AssertExtension { 26 | 27 | private IDomain domain; 28 | 29 | public DomainAssert(IDomain domain) { 30 | this.domain = domain; 31 | } 32 | 33 | public DomainAssert hasId(String id) { 34 | assertEquals(domain.getId(), id); 35 | return this; 36 | } 37 | 38 | public DomainAssert hasSuffix(String suffix) throws OpenShiftException { 39 | assertEquals(domain.getSuffix(), suffix); 40 | return this; 41 | } 42 | 43 | public DomainAssert hasApplications(int size) { 44 | assertThat(domain.getApplications()).hasSize(size); 45 | return this; 46 | } 47 | 48 | public DomainAssert hasApplications(IApplication... applications) { 49 | assertThat(domain.getApplications()).contains(applications); 50 | return this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/DomainTestUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import java.util.Iterator; 14 | 15 | import com.openshift.client.IDomain; 16 | import com.openshift.client.IUser; 17 | import com.openshift.client.OpenShiftException; 18 | 19 | /** 20 | * @author Andre Dietisheim 21 | */ 22 | public class DomainTestUtils { 23 | 24 | public static void destroyAllDomains(IUser user) { 25 | if (user == null) { 26 | return; 27 | } 28 | for (IDomain domain : user.getDomains()) { 29 | domain.destroy(true); 30 | } 31 | } 32 | 33 | public static void silentlyDestroy(IDomain domain) { 34 | if (domain == null) { 35 | return; 36 | } 37 | try { 38 | domain.destroy(true); 39 | } catch (Exception e) { 40 | // e.printStackTrace(); 41 | } 42 | } 43 | 44 | public static IDomain ensureHasDomain(IUser user) throws OpenShiftException { 45 | return getFirstDomainOrCreate(user); 46 | } 47 | 48 | public static IDomain getFirstDomainOrCreate(IUser user) throws OpenShiftException { 49 | IDomain domain = null; 50 | domain = getFirstDomain(user); 51 | 52 | if (domain == null) { 53 | domain = user.createDomain(createRandomName()); 54 | } 55 | 56 | return domain; 57 | } 58 | 59 | public static IDomain getFirstDomain(IUser user) throws OpenShiftException { 60 | IDomain domain = null; 61 | Iterator domainIterator = user.getDomains().iterator(); 62 | if (domainIterator.hasNext()) { 63 | domain = domainIterator.next(); 64 | } 65 | return domain; 66 | } 67 | 68 | public static String createRandomName() { 69 | return String.valueOf(System.currentTimeMillis()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/ExceptionCauseMatcher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import org.hamcrest.Description; 14 | import org.hamcrest.Matcher; 15 | import org.junit.internal.matchers.TypeSafeMatcher; 16 | 17 | /** 18 | * @author Andre Dietisheim 19 | */ 20 | public class ExceptionCauseMatcher extends TypeSafeMatcher { 21 | 22 | private Matcher causeMatcher; 23 | 24 | public ExceptionCauseMatcher(Matcher matcher) { 25 | this.causeMatcher = matcher; 26 | } 27 | 28 | public void describeTo(Description description) { 29 | description.appendText("exception with cause "); 30 | } 31 | 32 | @Override 33 | public boolean matchesSafely(Throwable throwable) { 34 | return causeMatcher.matches(throwable.getCause()); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/GearProfileTestUtils.java: -------------------------------------------------------------------------------- 1 | package com.openshift.client.utils; 2 | 3 | import com.openshift.client.IDomain; 4 | import com.openshift.client.IGearProfile; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by corey on 2/17/14. 10 | */ 11 | public class GearProfileTestUtils { 12 | public static IGearProfile getFirstAvailableGearProfile(IDomain domain) { 13 | IGearProfile gear = null; 14 | List gears = domain.getAvailableGearProfiles(); 15 | if (gears != null 16 | && !gears.isEmpty()) { 17 | gear = gears.get(0); 18 | } 19 | return gear; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/MessageAssert.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | import static org.junit.Assert.assertEquals; 15 | 16 | import org.fest.assertions.AssertExtension; 17 | 18 | import com.openshift.client.IField; 19 | import com.openshift.client.ISeverity; 20 | import com.openshift.client.Message; 21 | 22 | /** 23 | * @author Andre Dietisheim 24 | */ 25 | public class MessageAssert implements AssertExtension { 26 | 27 | private Message message; 28 | 29 | public MessageAssert(Message message) { 30 | assertThat(message).isNotNull(); 31 | this.message = message; 32 | } 33 | 34 | public MessageAssert hasText() { 35 | assertThat(message.getText()).isNotEmpty(); 36 | return this; 37 | } 38 | 39 | public MessageAssert hasText(String text) { 40 | assertEquals(text, message.getText()); 41 | return this; 42 | } 43 | 44 | public MessageAssert hasSeverity(ISeverity severity) { 45 | assertEquals(severity, message.getSeverity()); 46 | return this; 47 | } 48 | 49 | public MessageAssert hasExitCode(int exitCode) { 50 | assertEquals(exitCode, message.getExitCode()); 51 | return this; 52 | } 53 | 54 | public MessageAssert hasField(IField field) { 55 | assertThat(field).isEqualTo(message.getField()); 56 | return this; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/ParametersMatcher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.mockito.Matchers.argThat; 14 | 15 | import java.util.Arrays; 16 | 17 | import org.mockito.ArgumentMatcher; 18 | import org.mockito.internal.matchers.VarargMatcher; 19 | 20 | import com.openshift.internal.client.httpclient.request.Parameter; 21 | 22 | /** 23 | * Custom Mockito Matcher that verifies that the given RequestParameters matches 24 | * the expected ones. 25 | * 26 | * @author Andre Dietisheim 27 | * 28 | */ 29 | public class ParametersMatcher extends ArgumentMatcher implements VarargMatcher { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | private final Parameter[] expected; 34 | 35 | private ParametersMatcher(final Parameter... expected) { 36 | this.expected = expected; 37 | } 38 | 39 | @Override 40 | public boolean matches(Object argument) { 41 | if (!(argument instanceof Parameter[])) { 42 | return false; 43 | } 44 | Parameter[] parameters = (Parameter[]) argument; 45 | if (expected.length != parameters.length) { 46 | return false; 47 | } 48 | 49 | for (Parameter parameter : parameters) { 50 | if (!isExpected(parameter)) { 51 | return false; 52 | } 53 | } 54 | return true; 55 | } 56 | 57 | private boolean isExpected(Parameter parameter) { 58 | for (Parameter expectedParameter : expected) { 59 | if (expectedParameter.equals(parameter)) { 60 | return true; 61 | } 62 | } 63 | return false; 64 | } 65 | 66 | public static Parameter[] eq(Parameter[] expected) { 67 | return argThat(new ParametersMatcher(expected)); 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "RequestParametersMatcher [" 73 | + "expected=" + Arrays.toString(expected) 74 | + "]"; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/ResourcePropertyAssert.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | 15 | import org.fest.assertions.AssertExtension; 16 | 17 | import com.openshift.internal.client.response.CartridgeResourceProperty; 18 | 19 | /** 20 | * @author Andre Dietisheim 21 | */ 22 | public class ResourcePropertyAssert implements AssertExtension { 23 | 24 | private CartridgeResourceProperty property; 25 | 26 | public ResourcePropertyAssert(CartridgeResourceProperty property) { 27 | assertThat(property).isNotNull(); 28 | this.property = property; 29 | } 30 | 31 | public ResourcePropertyAssert hasName(String name) { 32 | assertThat(property.getName()).isEqualTo(name); 33 | return this; 34 | } 35 | 36 | public ResourcePropertyAssert hasDescription(String description) { 37 | assertThat(property.getDescription()).isEqualTo(description); 38 | return this; 39 | } 40 | 41 | public ResourcePropertyAssert hasType(String type) { 42 | assertThat(property.getType()).isEqualTo(type); 43 | return this; 44 | } 45 | 46 | public ResourcePropertyAssert hasValue(String value) { 47 | assertThat(property.getValue()).isEqualTo(value); 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/SSHPublicKeyAssertion.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | 15 | import org.fest.assertions.AssertExtension; 16 | 17 | import com.openshift.client.IOpenShiftSSHKey; 18 | import com.openshift.client.SSHKeyType; 19 | 20 | /** 21 | * @author Andre Dietisheim 22 | */ 23 | public class SSHPublicKeyAssertion implements AssertExtension { 24 | 25 | private IOpenShiftSSHKey sshKey; 26 | 27 | public SSHPublicKeyAssertion(IOpenShiftSSHKey key) { 28 | this.sshKey = key; 29 | } 30 | 31 | public SSHPublicKeyAssertion hasName(String name) { 32 | assertThat(name).isEqualTo(sshKey.getName()); 33 | return this; 34 | } 35 | 36 | public SSHPublicKeyAssertion hasPublicKey(String publicKey) { 37 | assertThat(publicKey).isEqualTo(sshKey.getPublicKey()); 38 | return this; 39 | } 40 | 41 | public SSHPublicKeyAssertion isType(String type) { 42 | assertThat(type).isEqualTo(sshKey.getKeyType().getTypeId()); 43 | return this; 44 | } 45 | 46 | public SSHPublicKeyAssertion isType(SSHKeyType type) { 47 | assertThat(type).isEqualTo(sshKey.getKeyType()); 48 | return this; 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/StandaloneCartridgeAssert.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import com.openshift.client.cartridge.IStandaloneCartridge; 14 | 15 | /** 16 | * @author André Dietisheim 17 | */ 18 | public class StandaloneCartridgeAssert extends CartridgeAssert { 19 | 20 | public StandaloneCartridgeAssert(IStandaloneCartridge cartridge) { 21 | super(cartridge); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/StateVerifier.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import org.junit.rules.Verifier; 14 | import org.junit.runners.model.FrameworkMethod; 15 | import org.junit.runners.model.Statement; 16 | 17 | /** 18 | * @author Xavier Coulon 19 | * 20 | */ 21 | public class StateVerifier extends Verifier { 22 | 23 | @Override 24 | public Statement apply(Statement base, FrameworkMethod method, Object target) { 25 | return super.apply(base, method, target); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | /** 14 | * @author Andre Dietisheim 15 | */ 16 | public class StringUtils { 17 | 18 | public static String createRandomString() { 19 | return String.valueOf(System.currentTimeMillis()); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/TestConnectionBuilder.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import java.io.IOException; 14 | 15 | import com.openshift.client.ConnectionBuilder; 16 | import com.openshift.client.OpenShiftException; 17 | import com.openshift.client.configuration.IOpenShiftConfiguration; 18 | 19 | /** 20 | * @author Andre Dietisheim 21 | */ 22 | public class TestConnectionBuilder extends ConnectionBuilder { 23 | 24 | public TestConnectionBuilder(String serverUrl) throws OpenShiftException, IOException { 25 | super(serverUrl); 26 | } 27 | 28 | public TestConnectionBuilder() throws OpenShiftException, IOException { 29 | super(null); 30 | } 31 | 32 | public CredentialsConnectionBuilder defaultCredentials() throws IOException { 33 | return credentials(getTestConfiguration().getRhlogin(), getTestConfiguration().getPassword()); 34 | } 35 | 36 | @Override 37 | protected IOpenShiftConfiguration createConfiguration() throws IOException { 38 | return new OpenShiftTestConfiguration(); 39 | } 40 | 41 | protected OpenShiftTestConfiguration getTestConfiguration() throws IOException { 42 | return (OpenShiftTestConfiguration) getConfiguration(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/client/utils/UrlEndsWithMatcher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.client.utils; 12 | 13 | import static org.mockito.Matchers.argThat; 14 | 15 | import java.net.URL; 16 | 17 | import org.mockito.ArgumentMatcher; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | /** 22 | * Custom Mockito Matcher that verifies that the given URL ends with a given 23 | * suffix. 24 | * 25 | * @author Xavier Coulon 26 | * 27 | */ 28 | public class UrlEndsWithMatcher extends ArgumentMatcher { 29 | 30 | private static final Logger LOGGER = LoggerFactory.getLogger(UrlEndsWithMatcher.class); 31 | 32 | private final String urlSuffix; 33 | 34 | private UrlEndsWithMatcher(final String urlSuffix) { 35 | this.urlSuffix = urlSuffix; 36 | } 37 | 38 | @Override 39 | public boolean matches(Object argument) { 40 | if (argument == null) { 41 | return false; 42 | } 43 | URL url = (URL) argument; 44 | final boolean match = url.toExternalForm().endsWith(urlSuffix); 45 | if (match) { 46 | LOGGER.trace("Matching {}", urlSuffix); 47 | } 48 | return match; 49 | } 50 | 51 | /** More friendly way to call the {@link UrlEndsWithMatcher}. */ 52 | public static URL urlEndsWith(String suffix) { 53 | return argThat(new UrlEndsWithMatcher(suffix)); 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/CertTrustIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | 14 | import java.io.IOException; 15 | 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | 19 | import com.openshift.client.IUser; 20 | import com.openshift.client.OpenShiftException; 21 | 22 | /** 23 | * @author William DeCoste 24 | */ 25 | public class CertTrustIntegrationTest extends TestTimer { 26 | 27 | private IUser user; 28 | 29 | @Before 30 | public void setUp() throws OpenShiftException, IOException { 31 | // service = new OpenShiftService(TestUser.ID, new OpenShiftConfiguration().getLibraServer()); 32 | // service.setEnableSSLCertChecks(Boolean.parseBoolean(System.getProperty("enableSSLCertChecks"))); 33 | // 34 | // user = new TestUser(service); 35 | } 36 | 37 | @Test 38 | public void testValidationSwitch() throws Exception { 39 | // 40 | // try { 41 | // service.setEnableSSLCertChecks(true); 42 | // service.getUserInfo(user); 43 | // fail("Expected cert validation exception"); 44 | // } catch (Exception e) { 45 | // } 46 | // 47 | // service.setEnableSSLCertChecks(false); 48 | // service.getUserInfo(user); 49 | // 50 | // try { 51 | // service.setEnableSSLCertChecks(true); 52 | // service.getUserInfo(user); 53 | // fail("Expected cert validation exception"); 54 | // } catch (Exception e) { 55 | // } 56 | // 57 | // service.setEnableSSLCertChecks(false); 58 | // service.getUserInfo(user); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/GearTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | 15 | import org.junit.Test; 16 | 17 | import com.openshift.client.GearState; 18 | 19 | /** 20 | * @author Xavier Coulon 21 | * @author Andre Dietisheim 22 | */ 23 | public class GearTest extends TestTimer { 24 | 25 | @Test 26 | public void nullShouldCreateUnknownGearState() { 27 | // operation 28 | GearState state = new GearState(null); 29 | // verification 30 | assertThat(state).isEqualTo(new GearState("UNKNOWN")); 31 | } 32 | 33 | @Test 34 | public void emptyShouldCreateUnknownGearState() { 35 | // operation 36 | GearState state = new GearState(""); 37 | // verification 38 | assertThat(state).isEqualTo(new GearState("UNKNOWN")); 39 | } 40 | 41 | @Test 42 | public void stateCaseShouldNotMatter() { 43 | // operation 44 | GearState state = new GearState("sTaRtEd"); 45 | // verification 46 | assertThat(state).isEqualTo(new GearState("STARTED")); 47 | } 48 | 49 | @Test 50 | public void bogusStateShouldBeUnknown() { 51 | // operation 52 | GearState state = new GearState("BOGUS!"); 53 | // verification 54 | assertThat(state).isEqualTo(new GearState("BOGUS!")); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/LinkRetriever.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import static org.junit.Assert.fail; 14 | 15 | import java.net.SocketTimeoutException; 16 | import java.util.Map; 17 | 18 | import com.openshift.client.OpenShiftException; 19 | import com.openshift.internal.client.response.Link; 20 | 21 | /** 22 | * Utility class to validate that a link in a resources contains a given fragment. 23 | * 24 | * @author Xavier Coulon 25 | * 26 | */ 27 | 28 | public class LinkRetriever { 29 | 30 | /** 31 | * Retrieves the link identified by the given name from the given resource. 32 | * @throws OpenShiftException 33 | * @throws SocketTimeoutException 34 | * 35 | */ 36 | public static Link retrieveLink(final Object resource, final String linkName) { 37 | try { 38 | return ((AbstractOpenShiftResource)resource).getLink(linkName); 39 | } catch (Exception e) { 40 | fail("Failed to retrieve link for given resource: " + resource); 41 | } 42 | return null; 43 | } 44 | 45 | /** 46 | * Retrieves the links from the given resource. 47 | * @throws OpenShiftException 48 | * @throws SocketTimeoutException 49 | * 50 | */ 51 | public static Map retrieveLinks(final Object resource) { 52 | try { 53 | return ((AbstractOpenShiftResource)resource).getLinks(); 54 | } catch (Exception e) { 55 | fail("Failed to retrieve links for given resource: " + resource); 56 | } 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/OpenShiftIntegrationTestSuite.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2013 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | 16 | @RunWith(Suite.class) 17 | @Suite.SuiteClasses({ 18 | APIResourceIntegrationTest.class, 19 | LatestVersionQueryIntegrationTest.class, 20 | SSHKeyIntegrationTest.class, 21 | ApplicationSSHSessionIntegrationTest.class, 22 | UserResourceIntegrationTest.class, 23 | DomainResourceIntegrationTest.class, 24 | ApplicationResourceIntegrationTest.class, 25 | StandaloneCartridgeResourceIntegrationTest.class, 26 | EmbeddedCartridgeResourceIntegrationTest.class, 27 | EnvironmentVariableResourceIntegrationTest.class, 28 | AuthorizationIntegrationTest.class 29 | }) 30 | /** 31 | * @author André Dietisheim 32 | */ 33 | public class OpenShiftIntegrationTestSuite { 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/OpenShiftTestSuite.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2007 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import org.junit.runner.RunWith; 14 | import org.junit.runners.Suite; 15 | 16 | import com.openshift.client.HttpMethodTest; 17 | import com.openshift.internal.client.httpclient.HttpClientTest; 18 | import com.openshift.internal.client.httpclient.request.FormUrlEncodedMediaTypeTest; 19 | import com.openshift.internal.client.httpclient.request.JsonMediaTypeTest; 20 | import com.openshift.internal.client.response.OpenShiftJsonDTOFactoryTest; 21 | import com.openshift.internal.client.response.QuickstartDTOCartridgeQueryTest; 22 | 23 | @RunWith(Suite.class) 24 | @Suite.SuiteClasses({ 25 | ConfigurationTest.class, 26 | HttpClientTest.class, 27 | HttpMethodTest.class, 28 | RestServicePropertiesTest.class, 29 | RestServiceTest.class, 30 | OpenShiftJsonDTOFactoryTest.class, 31 | DomainResourceTest.class, 32 | ApplicationBuilderTest.class, 33 | ApplicationResourceTest.class, 34 | APIResourceTest.class, 35 | QuickstartTest.class, 36 | BaseCartridgeTest.class, 37 | StandaloneCartridgeTest.class, 38 | StandaloneCartridgeResourceTest.class, 39 | EmbeddableCartridgeTest.class, 40 | EmbeddedCartridgeResourceTest.class, 41 | CartridgeQueryTest.class, 42 | UserTest.class, 43 | SSHKeyTest.class, 44 | GearGroupsResourceTest.class, 45 | GearTest.class, 46 | GearTest.class, 47 | OpenShiftExceptionTest.class, 48 | FormUrlEncodedMediaTypeTest.class, 49 | JsonMediaTypeTest.class, 50 | EnvironmentVariableResourceTest.class, 51 | ApplicationSSHSessionTest.class, 52 | QuickstartDTOCartridgeQueryTest.class, 53 | AuthorizationTest.class 54 | }) 55 | 56 | /** 57 | * @author André Dietisheim 58 | */ 59 | public class OpenShiftTestSuite { 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/RestServicePropertiesTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2012 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package com.openshift.internal.client; 12 | 13 | import static org.fest.assertions.Assertions.assertThat; 14 | 15 | import java.io.FileNotFoundException; 16 | import java.io.IOException; 17 | import java.util.Properties; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import com.openshift.client.OpenShiftException; 23 | import com.openshift.internal.client.httpclient.HttpClientException; 24 | 25 | /** 26 | * @author Andre Dietisheim 27 | */ 28 | public class RestServicePropertiesTest extends TestTimer { 29 | 30 | private static final String VERSION = "0.0.1"; 31 | private RestServiceProperties serviceProperties; 32 | 33 | @Before 34 | public void setUp() throws FileNotFoundException, IOException, OpenShiftException, HttpClientException { 35 | this.serviceProperties = new RestServiceProperties() { 36 | protected Properties getProperties() throws IOException { 37 | Properties properties = new Properties(); 38 | properties.put(KEY_VERSION, VERSION); 39 | properties.put(KEY_USERAGENTPATTERN, "{0} {1}"); 40 | return properties; 41 | } 42 | }; 43 | } 44 | 45 | @Test 46 | public void shouldReturnClientIdAndVersion() { 47 | // pre-conditions 48 | String clientId = "properties-test"; 49 | 50 | // operation 51 | String userAgent = serviceProperties.getUseragent(clientId); 52 | 53 | // verification 54 | assertThat(userAgent).isNotEmpty(); 55 | String[] clientIdAndVersion = userAgent.split(" "); 56 | assertThat(clientIdAndVersion).isNotNull().hasSize(2).containsOnly(clientId, VERSION); 57 | } 58 | 59 | @Test 60 | public void shouldReturnUserAgentEvenIfClientIdIsNull() { 61 | // pre-conditions 62 | 63 | // operation 64 | String userAgent = serviceProperties.getUseragent(null); 65 | 66 | // verification 67 | assertThat(userAgent).isNotEmpty(); 68 | // length of version + space, no client-id 69 | assertThat(userAgent).hasSize(VERSION.length() + 1); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/com/openshift/internal/client/TestTimer.java: -------------------------------------------------------------------------------- 1 | package com.openshift.internal.client; 2 | 3 | import com.openshift.client.OpenShiftException; 4 | 5 | import org.junit.After; 6 | import org.junit.Before; 7 | import org.junit.Rule; 8 | import org.junit.rules.TestName; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by cdaley on 3/13/14. 14 | */ 15 | public class TestTimer { 16 | protected long startTime; 17 | protected long endTime; 18 | 19 | @Rule 20 | public TestName name = new TestName(); 21 | 22 | @Before 23 | public void startTimer() throws OpenShiftException, IOException { 24 | this.startTime = 0; 25 | this.startTime = System.currentTimeMillis(); 26 | } 27 | 28 | @After 29 | public void endTimer() { 30 | this.endTime = 0; 31 | this.endTime = System.currentTimeMillis(); 32 | calcExecTime(); 33 | 34 | 35 | } 36 | 37 | public void calcExecTime() { 38 | if (System.getProperty("showTestTimes") != null) { 39 | System.out.println(this.getClass() +"#"+name.getMethodName() + " : " + (this.endTime - this.startTime)); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/resources/integrationTest.properties: -------------------------------------------------------------------------------- 1 | client_id=openshift-java-client-rest-test 2 | 3 | #libra_server=int.openshift.redhat.com 4 | libra_server=openshift.redhat.com 5 | 6 | default_rhlogin=toolsjboss@gmail.com 7 | 8 | rhpassword=1q2w3e 9 | 10 | proxySet=true 11 | proxyHost=file.rdu.redhat.com 12 | proxyPort=3128 13 | 14 | enableSSLCertChecks=false 15 | 16 | KNOWN_HOSTS=/home/bdecoste/.ssh/known_hosts 17 | IDENTITY=/home/bdecoste/.ssh/libra.pem 18 | -------------------------------------------------------------------------------- /src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/test/resources/samples/delete-domains-foobar_ko.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":null, 3 | "errors":{ 4 | 5 | }, 6 | "messages":[ 7 | { 8 | "exit_code":127, 9 | "field":null, 10 | "severity":"error", 11 | "text":"Domain foobar not found" 12 | } 13 | ], 14 | "status":"not_found", 15 | "supported_api_versions":[ 16 | 1.0, 17 | 1.1, 18 | 1.2, 19 | 1.3, 20 | 1.4 21 | ], 22 | "type":null, 23 | "version":"1.2" 24 | } -------------------------------------------------------------------------------- /src/test/resources/samples/delete-domains-foobarz.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openshift/openshift-java-client/eed6e201024f2f9f8a2b839f6dbfc62dfbf4cb14/src/test/resources/samples/delete-domains-foobarz.json -------------------------------------------------------------------------------- /src/test/resources/samples/delete-domains-foobarz_ko-existingapps.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":null, 3 | "errors":{ 4 | 5 | }, 6 | "messages":[ 7 | { 8 | "exit_code":128, 9 | "field":null, 10 | "severity":"error", 11 | "text":"Domain contains applications. Delete applications first or set force to true." 12 | } 13 | ], 14 | "status":"bad_request", 15 | "supported_api_versions":[ 16 | 1.0, 17 | 1.1, 18 | 1.2, 19 | 1.3, 20 | 1.4 21 | ], 22 | "type":null, 23 | "version":"1.2" 24 | } -------------------------------------------------------------------------------- /src/test/resources/samples/delete-user-key-ko.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":null, 3 | "type":null, 4 | "messages":[ 5 | { 6 | "severity":"error", 7 | "exit_code":124, 8 | "field":null, 9 | "text":"Failed to delete SSH key default for user foobar+test@redhat.com due to:ERROR: Can't remove 'default' ssh key for user foobar+test@redhat.com" 10 | } 11 | ], 12 | "version":"1.0", 13 | "status":"internal_server_error" 14 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get-domains-foobar_ko-notfound.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":null, 3 | "messages":[ 4 | { 5 | "exit_code":127, 6 | "field":null, 7 | "severity":"error", 8 | "text":"Domain foobar not found." 9 | } 10 | ], 11 | "status":"not_found", 12 | "supported_api_versions":[ 13 | 1.0, 14 | 1.1, 15 | 1.2, 16 | 1.3, 17 | 1.4 18 | ], 19 | "type":null, 20 | "version":"1.2" 21 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get-domains-foobarz-applications_noapps.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":[ 3 | 4 | ], 5 | "messages":[ 6 | 7 | ], 8 | "status":"ok", 9 | "supported_api_versions":[ 10 | 1.0, 11 | 1.1, 12 | 1.2, 13 | 1.3, 14 | 1.4 15 | ], 16 | "type":"applications", 17 | "version":"1.2" 18 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get-domains_empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":[ 3 | 4 | ], 5 | "messages":[ 6 | 7 | ], 8 | "status":"ok", 9 | "supported_api_versions":[ 10 | 1.0, 11 | 1.1, 12 | 1.2, 13 | 1.3, 14 | 1.4 15 | ], 16 | "type":"domains", 17 | "version":"1.2" 18 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get-user-keys_none.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":[ 3 | 4 | ], 5 | "messages":[ 6 | 7 | ], 8 | "status":"ok", 9 | "supported_api_versions":[ 10 | 1.0, 11 | 1.1, 12 | 1.2, 13 | 1.3, 14 | 1.4 15 | ], 16 | "type":"keys", 17 | "version":"1.2" 18 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get_0_environment_variables_foobarz_springeap6.json: -------------------------------------------------------------------------------- 1 | { 2 | "api_version":1.2, 3 | "data":[ 4 | 5 | ], 6 | "messages":[ 7 | { 8 | "exit_code":0, 9 | "field":null, 10 | "severity":"info", 11 | "text":"Listing environment variables for application springeap6" 12 | } 13 | ], 14 | "status":"ok", 15 | "supported_api_versions":[ 16 | 1.0, 17 | 1.1, 18 | 1.2, 19 | 1.3, 20 | 1.4, 21 | 1.5, 22 | 1.6 23 | ], 24 | "type":"environment-variables", 25 | "version":"1.2" 26 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get_1_environment_variables_foobarz_springeap6.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":[ 3 | { 4 | "links":{ 5 | "GET":{ 6 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 7 | "method":"GET", 8 | "optional_params":[ 9 | 10 | ], 11 | "rel":"Get environment variable", 12 | "required_params":[ 13 | 14 | ] 15 | }, 16 | "UPDATE":{ 17 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 18 | "method":"PUT", 19 | "optional_params":[ 20 | 21 | ], 22 | "rel":"Update environment variable", 23 | "required_params":[ 24 | { 25 | "description":"Value of the environment variable", 26 | "invalid_options":[ 27 | 28 | ], 29 | "name":"value", 30 | "type":"string", 31 | "valid_options":[ 32 | 33 | ] 34 | } 35 | ] 36 | }, 37 | "DELETE":{ 38 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 39 | "method":"DELETE", 40 | "optional_params":[ 41 | 42 | ], 43 | "rel":"Delete environment variable", 44 | "required_params":[ 45 | 46 | ] 47 | } 48 | }, 49 | "name":"FOO", 50 | "value":"123" 51 | } 52 | ], 53 | "messages":[ 54 | { 55 | "exit_code":0, 56 | "field":null, 57 | "severity":"info", 58 | "text":"Listing environment variables for application springeap6" 59 | } 60 | ], 61 | "status":"ok", 62 | "supported_api_versions":[ 63 | 1.0, 64 | 1.1, 65 | 1.2, 66 | 1.3, 67 | 1.4, 68 | 1.5, 69 | 1.6 70 | ], 71 | "type":"environment-variables", 72 | "version":"1.2" 73 | } -------------------------------------------------------------------------------- /src/test/resources/samples/get_two_environment_variabls_foobarz_springeap6.json: -------------------------------------------------------------------------------- 1 | {"api_version":1.2,"data":[{"links":{"GET":{"href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/Y_NAME","method":"GET","optional_params":[],"rel":"Get environment variable","required_params":[]},"UPDATE":{"href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/Y_NAME","method":"PUT","optional_params":[],"rel":"Update environment variable","required_params":[{"description":"Value of the environment variable","invalid_options":[],"name":"value","type":"string","valid_options":[]}]},"DELETE":{"href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/Y_NAME","method":"DELETE","optional_params":[],"rel":"Delete environment variable","required_params":[]}},"name":"Y_NAME","value":"Y_VALUE"},{"links":{"GET":{"href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/X_NAME","method":"GET","optional_params":[],"rel":"Get environment variable","required_params":[]},"UPDATE":{"href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/X_NAME","method":"PUT","optional_params":[],"rel":"Update environment variable","required_params":[{"description":"Value of the environment variable","invalid_options":[],"name":"value","type":"string","valid_options":[]}]},"DELETE":{"href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/X_NAME","method":"DELETE","optional_params":[],"rel":"Delete environment variable","required_params":[]}},"name":"X_NAME","value":"X_VALUE"}],"messages":[{"exit_code":0,"field":null,"severity":"info","text":"Listing environment variables for application springeap6"}],"status":"ok","supported_api_versions":[1.0,1.1,1.2,1.3,1.4,1.5,1.6],"type":"environment-variables","version":"1.2"} -------------------------------------------------------------------------------- /src/test/resources/samples/links-unknown-linkparametertype.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":{ 3 | "POST1":{ 4 | "href":"https://openshift.redhat.com/broker/rest/post1", 5 | "method":"POST", 6 | "optional_params":[ 7 | 8 | ], 9 | "rel":"Post1", 10 | "required_params":[ 11 | { 12 | "description":"post1Required1Description", 13 | "invalid_options":[ 14 | 15 | ], 16 | "name":"post1Required1Name", 17 | "type":"unknown", 18 | "valid_options":[ 19 | ] 20 | } 21 | ] 22 | } 23 | }, 24 | "type":"links", 25 | "version":"1.2" 26 | } -------------------------------------------------------------------------------- /src/test/resources/samples/links-unknown-verb.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":{ 3 | "ALINK":{ 4 | "href":"https://openshift.redhat.com/broker/rest/post1", 5 | "method":"MadeUpMethodName", 6 | "optional_params":[ 7 | 8 | ], 9 | "rel":"Post1", 10 | "required_params":[ 11 | ] 12 | } 13 | }, 14 | "type":"links", 15 | "version":"1.2" 16 | } -------------------------------------------------------------------------------- /src/test/resources/samples/post-foobar-domains_ko-inuse.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":null, 3 | "errors":{ 4 | 5 | }, 6 | "messages":[ 7 | { 8 | "exit_code":103, 9 | "field":"id", 10 | "severity":"error", 11 | "text":"Namespace 'foobar' is already in use. Please choose another." 12 | } 13 | ], 14 | "status":"unprocessable_entity", 15 | "supported_api_versions":[ 16 | 1.0, 17 | 1.1, 18 | 1.2, 19 | 1.3, 20 | 1.4 21 | ], 22 | "type":null, 23 | "version":"1.2" 24 | } -------------------------------------------------------------------------------- /src/test/resources/samples/post_add_environment_variable_foo_to_foobarz_springeap6.json: -------------------------------------------------------------------------------- 1 | { 2 | "data":{ 3 | "links":{ 4 | "GET":{ 5 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 6 | "method":"GET", 7 | "optional_params":[ 8 | 9 | ], 10 | "rel":"Get environment variable", 11 | "required_params":[ 12 | 13 | ] 14 | }, 15 | "UPDATE":{ 16 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 17 | "method":"PUT", 18 | "optional_params":[ 19 | 20 | ], 21 | "rel":"Update environment variable", 22 | "required_params":[ 23 | { 24 | "description":"Value of the environment variable", 25 | "invalid_options":[ 26 | 27 | ], 28 | "name":"value", 29 | "type":"string", 30 | "valid_options":[ 31 | 32 | ] 33 | } 34 | ] 35 | }, 36 | "DELETE":{ 37 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 38 | "method":"DELETE", 39 | "optional_params":[ 40 | 41 | ], 42 | "rel":"Delete environment variable", 43 | "required_params":[ 44 | 45 | ] 46 | } 47 | }, 48 | "name":"FOO", 49 | "value":"123" 50 | }, 51 | "messages":[ 52 | { 53 | "exit_code":0, 54 | "field":null, 55 | "severity":"info", 56 | "text":"Added environment variable 'FOO' to application springeap6" 57 | } 58 | ], 59 | "status":"created", 60 | "supported_api_versions":[ 61 | 1.0, 62 | 1.1, 63 | 1.2, 64 | 1.3, 65 | 1.4, 66 | 1.5, 67 | 1.6 68 | ], 69 | "type":"environment-variable", 70 | "version":"1.2" 71 | } -------------------------------------------------------------------------------- /src/test/resources/samples/put_foo_environment_variable_foobarz_springeap6.json: -------------------------------------------------------------------------------- 1 | { 2 | "api_version":1.2, 3 | "data":{ 4 | "links":{ 5 | "GET":{ 6 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 7 | "method":"GET", 8 | "optional_params":[ 9 | 10 | ], 11 | "rel":"Get environment variable", 12 | "required_params":[ 13 | 14 | ] 15 | }, 16 | "UPDATE":{ 17 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 18 | "method":"PUT", 19 | "optional_params":[ 20 | 21 | ], 22 | "rel":"Update environment variable", 23 | "required_params":[ 24 | { 25 | "description":"Value of the environment variable", 26 | "invalid_options":[ 27 | 28 | ], 29 | "name":"value", 30 | "type":"string", 31 | "valid_options":[ 32 | 33 | ] 34 | } 35 | ] 36 | }, 37 | "DELETE":{ 38 | "href":"https://openshift.redhat.com/broker/rest/domains/foobarz/applications/springeap6/environment-variables/FOO", 39 | "method":"DELETE", 40 | "optional_params":[ 41 | 42 | ], 43 | "rel":"Delete environment variable", 44 | "required_params":[ 45 | 46 | ] 47 | } 48 | }, 49 | "name":"FOO", 50 | "value":"321" 51 | }, 52 | "messages":[ 53 | { 54 | "exit_code":0, 55 | "field":null, 56 | "severity":"info", 57 | "text":"Updated environment variable 'FOO' in application springeap6" 58 | } 59 | ], 60 | "status":"ok", 61 | "supported_api_versions":[ 62 | 1.0, 63 | 1.1, 64 | 1.2, 65 | 1.3, 66 | 1.4, 67 | 1.5, 68 | 1.6 69 | ], 70 | "type":"environment-variable", 71 | "version":"1.2" 72 | } -------------------------------------------------------------------------------- /src/test/resources/server-keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openshift/openshift-java-client/eed6e201024f2f9f8a2b839f6dbfc62dfbf4cb14/src/test/resources/server-keystore.jks --------------------------------------------------------------------------------