From 3d6feef167f8e8eb716312599132c41dd89457cb Mon Sep 17 00:00:00 2001 From: Piotr Jaszczyk Date: Mon, 3 Jun 2019 14:20:40 +0200 Subject: Monitoring API - write framework adapters Change-Id: Iaba9c4ef6022d01c1f572055316700a3a4dfa8f2 Issue-ID: DCAEGEN2-1589 Signed-off-by: Piotr Jaszczyk --- .../moher/health/api/AliveMessage.java | 29 ++++++++++++ .../standardization/moher/health/api/Health.java | 51 ++++++++++++++++++++++ .../moher/health/api/HealthProvider.java | 38 ++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/AliveMessage.java create mode 100644 standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/Health.java create mode 100644 standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/HealthProvider.java (limited to 'standardization/moher-api/healthstate/src/main/java') diff --git a/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/AliveMessage.java b/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/AliveMessage.java new file mode 100644 index 00000000..c9a8c226 --- /dev/null +++ b/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/AliveMessage.java @@ -0,0 +1,29 @@ +/* + * ============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.standardization.moher.health.api; + +public final class AliveMessage { + + public static final String ALIVE_MESSAGE_JSON = "{\"alive\":true}"; + + private AliveMessage() { + } +} diff --git a/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/Health.java b/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/Health.java new file mode 100644 index 00000000..65b11ad1 --- /dev/null +++ b/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/Health.java @@ -0,0 +1,51 @@ +/* + * ============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.standardization.moher.health.api; + +import org.immutables.gson.Gson; +import org.immutables.value.Value; + +@Value.Immutable +@Gson.TypeAdapters +public interface Health { + + @Value.Default + default boolean healthy() { + return true; + } + + @Value.Default + default String description() { + return "Service is working correctly"; + } + + static Health createHealthy() { + return ImmutableHealth.builder().build(); + } + + static Health createHealthy(String description) { + return ImmutableHealth.builder().description(description).build(); + } + + static Health createUnhealthy(String description) { + return ImmutableHealth.builder().healthy(false).description(description).build(); + } +} diff --git a/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/HealthProvider.java b/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/HealthProvider.java new file mode 100644 index 00000000..b6d770a4 --- /dev/null +++ b/standardization/moher-api/healthstate/src/main/java/org/onap/dcaegen2/services/sdk/standardization/moher/health/api/HealthProvider.java @@ -0,0 +1,38 @@ +/* + * ============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.standardization.moher.health.api; + +import io.vavr.Function0; +import java.util.function.Supplier; +import reactor.core.publisher.Mono; + +@FunctionalInterface +public interface HealthProvider { + Mono currentHealth(); + + static HealthProvider fromFunction(Function0 function) { + return () -> Mono.fromCallable(function::apply); + } + + static HealthProvider fromSupplier(Supplier function) { + return () -> Mono.fromCallable(function::get); + } +} -- cgit 1.2.3-korg