2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.plugins.grtoolkit.resolver;
24 import org.onap.ccsdk.sli.core.dblib.DbLibService;
25 import org.onap.ccsdk.sli.plugins.grtoolkit.data.AdminHealth;
26 import org.onap.ccsdk.sli.plugins.grtoolkit.data.ClusterActor;
27 import org.onap.ccsdk.sli.plugins.grtoolkit.data.ClusterHealth;
28 import org.onap.ccsdk.sli.plugins.grtoolkit.data.DatabaseHealth;
29 import org.onap.ccsdk.sli.plugins.grtoolkit.data.FailoverStatus;
30 import org.onap.ccsdk.sli.plugins.grtoolkit.data.Health;
31 import org.onap.ccsdk.sli.plugins.grtoolkit.data.SiteHealth;
33 import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.plugins.gr.toolkit.rev180926.FailoverInput;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 import java.util.Collections;
39 import java.util.List;
41 import java.util.Properties;
44 * Implementation of {@code HealthResolver} for a single node controller
47 * @author Anthony Haddox
50 public class SingleNodeHealthResolver extends HealthResolver {
51 private final Logger log = LoggerFactory.getLogger(SingleNodeHealthResolver.class);
54 * Constructs the health resolver used by the {@code GrToolkitProvider} to
55 * determine the health of the application components.
57 * @param map a HashMap containing all of the nodes in the akka cluster
58 * @param properties the properties passed ino the provider
59 * @param dbLib a reference to the {@code DbLibService} of the provider
61 * @see org.onap.ccsdk.sli.plugins.grtoolkit.GrToolkitProvider
63 public SingleNodeHealthResolver(Map<String, ClusterActor> map, Properties properties, DbLibService dbLib) {
64 super(map, properties, dbLib);
69 * Implementation of {@code getClusterHealth()}. Uses the
70 * {@code ShardResolver} to gather health information about the controller.
71 * This method assumes the cluster is always healthy since it is a single
74 * @return an {@code ClusterHealth} object with health of the akka cluster
75 * @see org.onap.ccsdk.sli.plugins.grtoolkit.GrToolkitProvider
81 public ClusterHealth getClusterHealth() {
82 log.info("getClusterHealth(): Getting cluster health...");
83 shardResolver.getControllerHealth(memberMap);
84 return new ClusterHealth().withHealth(Health.HEALTHY);
88 * Implementation of {@code getSiteHealth()}. Uses the results from
89 * {@code getAdminHealth}, {@code getDatabaseHealth}, and
90 * {@code getClusterHealth} to determine the health of the site. If all
91 * components are healthy, the site is healthy.
93 * @return a List of {@code SiteHealth} objects with health of the site
94 * @see org.onap.ccsdk.sli.plugins.grtoolkit.GrToolkitProvider
100 public List<SiteHealth> getSiteHealth() {
101 log.info("getSiteHealth(): Getting site health...");
102 AdminHealth adminHealth = getAdminHealth();
103 DatabaseHealth databaseHealth = getDatabaseHealth();
104 ClusterHealth clusterHealth = getClusterHealth();
105 SiteHealth siteHealth = new SiteHealth()
106 .withAdminHealth(adminHealth)
107 .withDatabaseHealth(databaseHealth)
108 .withClusterHealth(clusterHealth)
110 .withId(getSiteIdentifier());
111 log.info("getSiteHealth(): Admin Health: {}", adminHealth.getHealth().toString());
112 log.info("getSiteHealth(): Database Health: {}", databaseHealth.getHealth().toString());
113 log.info("getSiteHealth(): Cluster Health: {}", clusterHealth.getHealth().toString());
114 if(isHealthy(adminHealth.getHealth()) && isHealthy(databaseHealth.getHealth()) && isHealthy(clusterHealth.getHealth())) {
115 siteHealth.setHealth(Health.HEALTHY);
118 return Collections.singletonList(siteHealth);
122 * Implementation of {@code tryFailover()}. No controller-level failover
123 * options are available in a single node architecture, so 400 Bad Request
124 * is returned, and no action is taken.
126 * @return an {@code SiteHealth} object with health of the site
127 * @see org.onap.ccsdk.sli.plugins.grtoolkit.GrToolkitProvider
128 * @see HealthResolver
129 * @see FailoverStatus
133 public FailoverStatus tryFailover(FailoverInput input) {
134 log.info("tryFailover(): Failover not supported in the current configuration.");
135 return new FailoverStatus().withStatusCode(400).withMessage("Failover not supported in current configuration.");
139 * Implementation of {@code resolveSites()}. Calls
140 * {@code resolveSiteForMember()} to resolve which site a member belongs to.
142 * @see HealthResolver
145 public void resolveSites() {
146 log.info("Map contains {} entries", memberMap.size());
147 memberMap.forEach((key, value) -> resolveSiteForMember(value));
151 * Resolves which site a member belongs to. Since this is a Single node
152 * architecture, it is defaulted to <i>Site 1</i>.
154 * @see HealthResolver
156 private void resolveSiteForMember(ClusterActor actor) {
157 actor.setSite("Site 1");
158 log.info("resolveSiteForMember(): {} belongs to {}", actor.getNode(), actor.getSite());