Skip to content

Commit

Permalink
Merge pull request #2552 from RolefH/develop
Browse files Browse the repository at this point in the history
correct BuildService.of_service
  • Loading branch information
markheger committed Aug 19, 2020
2 parents 1206f3e + d1eab69 commit 1a882bb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
27 changes: 16 additions & 11 deletions com.ibm.streamsx.topology/opt/python/packages/streamsx/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ def of_service(config):
# service_name is the instance name
service_name = service['service_name']
auth = streamsx.rest_primitives._ICPDAuthHandler(service_name, service['service_token'])
build_url = BuildService._root_from_endpoint(service['connection_info'].get('serviceBuildEndpoint'))
resource_url = BuildService._root_from_endpoint(service['connection_info'].get('serviceBuildEndpoint'))
print("## BuildService: resource_url = " + resource_url)
buildpools_url = service['connection_info'].get('serviceBuildPoolsEndpoint', None)
sc = BuildService(resource_url=build_url, buildpools_url=buildpools_url, auth=auth)
sc = BuildService(resource_url=resource_url, buildpools_url=buildpools_url, auth=auth)
if streamsx.topology.context.ConfigParams.SSL_VERIFY in config:
sc.rest_client.session.verify = config[streamsx.topology.context.ConfigParams.SSL_VERIFY]
return sc
Expand Down Expand Up @@ -450,21 +451,25 @@ def of_endpoint(endpoint=None, service_name=None, username=None, password=None,

@staticmethod
def _root_from_endpoint(endpoint):
"""
Returns the build resources URL from the build endpoint
"""
import urllib.parse as up
esu = up.urlsplit(endpoint)
if esu.path.startswith('/streams-build/instances/'):
# CPD 2.5 ... < 3.5
# external URL; CPD 2.5 ... < 3.5
return endpoint.replace('/streams-build/instances', '/streams-build-resource/instances', 1)
elif esu.path.startswith('/streams_build_service/v1/'):
# CPD >= 3.5
# external URL, CPD >= 3.5
return up.urlunsplit((esu.scheme, esu.netloc, esu.path.replace('/builds', '/roots'), None, None))
if not esu.path.startswith('/streams/rest/builds'):
return None

es = endpoint.split('/')
root_url = endpoint.split('/streams/rest/builds')[0]
resource_url = root_url + '/streams/rest/resources'
return resource_url
elif esu.path.startswith('/streams/rest/builds'):
# internal URL; CPD 2.5 ... < 3.5
return up.urlunsplit((esu.scheme, esu.netloc, esu.path.replace('/builds', '/resources'), None, None))
elif esu.path.startswith('/streams/v1/builds'):
# internal URL, CPD >= 3.5
return up.urlunsplit((esu.scheme, esu.netloc, esu.path.replace('/builds', '/roots'), None, None))

raise ValueError("Can't convert build endpoint " + endpoint + " into resource URL")

def __str__(self):
return pformat(self.__dict__)
Expand Down
12 changes: 5 additions & 7 deletions java/src/com/ibm/streamsx/rest/build/BuildService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.ibm.streamsx.rest.build;

import static com.ibm.streamsx.rest.build.StreamsBuildService.STREAMS_BUILD_PATH;
import static com.ibm.streamsx.rest.build.StreamsBuildService.STREAMS_REST_RESOURCES;
import static com.ibm.streamsx.topology.internal.gson.GsonUtilities.jstring;

import java.io.IOException;
Expand Down Expand Up @@ -73,12 +72,11 @@ public static BuildService ofEndpoint(String endpoint, String name, String userN
}
String basicAuth = RestUtils.createBasicAuth(userName, password);
String buildsEndpoint = endpoint;
// TODO: URL completion cannot be done as the build path depends on Streams version - commented out
// if (!buildsEndpoint.endsWith(STREAMS_BUILD_PATH)) {
// URL buildUrl = new URL(url.getProtocol(), url.getHost(),
// url.getPort(), STREAMS_BUILD_PATH);
// buildsEndpoint = buildUrl.toExternalForm();
// }
if (!buildsEndpoint.endsWith(STREAMS_BUILD_PATH)) {
URL buildUrl = new URL(url.getProtocol(), url.getHost(),
url.getPort(), STREAMS_BUILD_PATH);
buildsEndpoint = buildUrl.toExternalForm();
}
return StreamsBuildService.of(e -> basicAuth, buildsEndpoint, verify);
}
return StreamsBuildService.of(auth, serviceDefinition, verify);
Expand Down
30 changes: 14 additions & 16 deletions java/src/com/ibm/streamsx/rest/build/StreamsBuildService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

class StreamsBuildService extends AbstractConnection implements BuildService, BuildServiceSetters {

static final String STREAMS_REST_RESOURCES = "/streams/rest/resources";
static final String STREAMS_BUILD_PATH = "/streams/rest/builds";
// static final String STREAMS_REST_RESOURCES = "/streams/v1/roots";
static final String STREAMS_BUILD_PATH = "/streams/v1/builds"; // serviceBuildEndpoint

static BuildService of(Function<Executor,String> authenticator, JsonObject serviceDefinition,
boolean verify) throws IOException {
Expand All @@ -42,13 +42,12 @@ static BuildService of(Function<Executor,String> authenticator, JsonObject servi
if (buildServiceEndpoint == null) {
buildServiceEndpoint = Util.getenv(Util.STREAMS_BUILD_URL);
}
// TODO: URL completion cannot be done as the build path depends on Streams version - commented out
// if (!buildServiceEndpoint.endsWith(STREAMS_BUILD_PATH)) {
// // URL was user-provided root of service, add the path
// URL url = new URL(buildServiceEndpoint);
// URL buildsUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), STREAMS_BUILD_PATH);
// buildServiceEndpoint = buildsUrl.toExternalForm();
// }
if (!buildServiceEndpoint.endsWith(STREAMS_BUILD_PATH)) {
// URL was user-provided root of service, add the path
URL url = new URL(buildServiceEndpoint);
URL buildsUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), STREAMS_BUILD_PATH);
buildServiceEndpoint = buildsUrl.toExternalForm();
}
return StreamsBuildService.of(authenticator, buildServiceEndpoint, verify);
}
return new StreamsBuildService(buildServiceEndpoint, buildServicePoolsEndpoint, authenticator, verify);
Expand All @@ -59,13 +58,12 @@ static BuildService of(Function<Executor,String> authenticator, String buildServ

if (buildServiceEndpoint == null) {
buildServiceEndpoint = Util.getenv(Util.STREAMS_BUILD_URL);
// TODO: URL completion cannot be done as the build path depends on Streams version - commented out
// if (!buildServiceEndpoint.endsWith(STREAMS_BUILD_PATH)) {
// // URL was user-provided root of service, add the path
// URL url = new URL(buildServiceEndpoint);
// URL buildsUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), STREAMS_BUILD_PATH);
// buildServiceEndpoint = buildsUrl.toExternalForm();
// }
if (!buildServiceEndpoint.endsWith(STREAMS_BUILD_PATH)) {
// URL was user-provided root of service, add the path
URL url = new URL(buildServiceEndpoint);
URL buildsUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), STREAMS_BUILD_PATH);
buildServiceEndpoint = buildsUrl.toExternalForm();
}
}
return new StreamsBuildService(buildServiceEndpoint, null, authenticator, verify);
}
Expand Down

0 comments on commit 1a882bb

Please sign in to comment.