* This method will do a lookup of Config Binding Service using Consul as service discovery mechanism and create
* client configured with found address. Created client will be published in returned Mono instance.
* </p>
+ * <p>
+ * In case of failure during CBS resolution, returned Mono will emit error signal with possible cause.
+ * User is expected to handle this signal and possibly retry subscription to returned Mono.
+ * </p>
*
* @param env required environment properties
* @return non-null {@link Mono} of {@link CbsClient} instance
--- /dev/null
+/*
+ * ============LICENSE_START====================================
+ * DCAEGEN2-SERVICES-SDK
+ * =========================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * =========================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================
+ */
+
+package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions;
+
+import org.jetbrains.annotations.NotNull;
+
+public class CbsClientException extends RuntimeException {
+ CbsClientException(final @NotNull String message) {
+ super(message);
+ }
+}
--- /dev/null
+/*
+ * ============LICENSE_START====================================
+ * DCAEGEN2-SERVICES-SDK
+ * =========================================================
+ * Copyright (C) 2019 Nokia. All rights reserved.
+ * =========================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=====================================
+ */
+
+package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions;
+
+public class ServiceLookupException extends CbsClientException {
+ public ServiceLookupException(String message) {
+ super(message);
+ }
+}
* ============LICENSE_END=====================================
*/
-package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams;
+package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions;
import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi;
* ============LICENSE_END=====================================
*/
-package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams;
+package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions;
import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi;
* @since 1.1.2
*/
@ExperimentalApi
-public class StreamParsingException extends RuntimeException {
+public class StreamParsingException extends CbsClientException {
private final StreamParserError cause;
import io.vavr.control.Either;
import org.onap.dcaegen2.services.sdk.rest.services.annotations.ExperimentalApi;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.StreamParserError;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.StreamParsingException;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.listener.MerkleTree;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.streams.DataStream;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+
import java.net.InetSocketAddress;
+
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.ServiceLookupException;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
import reactor.core.publisher.Mono;
private Mono<JsonObject> firstService(JsonArray services) {
return services.size() == 0
- ? Mono.empty()
+ ? Mono.error(new ServiceLookupException("Consul server did not return any service with given name"))
: Mono.just(services.get(0).getAsJsonObject());
}
}
}
-
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.ServiceLookupException;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.EnvProperties;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableEnvProperties;
}
@Test
- void lookupShouldReturnEmptyResultWhenServiceArrayIsEmpty() {
+ void lookupShouldEmitErrorWhenServiceArrayIsEmpty() {
// given
givenConsulResponse(new JsonArray());
final Mono<InetSocketAddress> result = cut.lookup(env);
// then
- StepVerifier.create(result).verifyComplete();
+ StepVerifier.create(result).verifyError(ServiceLookupException.class);
}
private JsonElement parseResource(String resource) {