Updated feature-healthcheck thru feature-pooling-dmaap.
Issue-ID: POLICY-3397
Change-Id: Ia7b00a521cdb82ed0eb22bdaed03d02665fbbff1
Signed-off-by: Jim Hahn <jrh3@att.com>
* ============LICENSE_START=======================================================
* feature-healthcheck
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. 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.
import java.util.ArrayList;
import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.onap.policy.common.capabilities.Startable;
/**
/**
* Healthcheck Report.
*/
+ @Getter
+ @Setter
+ @ToString
public static class Report {
/**
* Named Entity in the report.
* Message from remote entity.
*/
private String message;
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Report [name=");
- builder.append(getName());
- builder.append(", url=");
- builder.append(getUrl());
- builder.append(", healthy=");
- builder.append(isHealthy());
- builder.append(", code=");
- builder.append(getCode());
- builder.append(", message=");
- builder.append(getMessage());
- builder.append("]");
- return builder.toString();
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public boolean isHealthy() {
- return healthy;
- }
-
- public void setHealthy(boolean healthy) {
- this.healthy = healthy;
- }
-
- public int getCode() {
- return code;
- }
-
- public void setCode(int code) {
- this.code = code;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
}
/**
* Report aggregation.
*/
+ @Getter
+ @Setter
+ @ToString
public static class Reports {
private boolean healthy;
private List<Report> details = new ArrayList<>();
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Reports [healthy=");
- builder.append(isHealthy());
- builder.append(", details=");
- builder.append(getDetails());
- builder.append("]");
- return builder.toString();
- }
-
- public boolean isHealthy() {
- return healthy;
- }
-
- public void setHealthy(boolean healthy) {
- this.healthy = healthy;
- }
-
- public List<Report> getDetails() {
- return details;
- }
-
- public void setDetails(List<Report> details) {
- this.details = details;
- }
}
/**
* ============LICENSE_START=======================================================
* feature-healthcheck
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.healthcheck;
+import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
-public class HealthCheckConstants {
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class HealthCheckConstants {
/**
* Healthcheck Monitor.
*/
@Getter
private static final HealthCheck manager = new HealthCheckManager();
-
- private HealthCheckConstants() {
- // do nothing
- }
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. 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.
import java.util.List;
import java.util.Properties;
import javax.ws.rs.core.Response;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.ToString;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
/**
* Healthcheck Monitor.
*/
+@Getter
+@ToString
public class HealthCheckManager implements HealthCheck {
/**
/**
* Healthcheck configuration.
*/
+ @Getter(AccessLevel.NONE)
+ @ToString.Exclude
protected Properties healthCheckProperties = null;
/**
return this.healthCheckProperties != null;
}
- /**
- * Get servers.
- *
- * @return list of attached Http Servers
- */
- public List<HttpServletServer> getServers() {
- return this.servers;
- }
-
- /**
- * Get clients.
- *
- * @return list of attached Http Clients
- */
- public List<HttpClient> getClients() {
- return this.clients;
- }
-
/**
* Gets the body from the response.
*
}
}
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("HealthCheckMonitor [servers=");
- builder.append(servers);
- builder.append(", clients=");
- builder.append(clients);
- builder.append("]");
- return builder.toString();
- }
-
// the following methods may be overridden by junit tests
protected PolicyEngine getEngineManager() {
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
@Test
public void testHealthCheckMonitor_ToString() {
- assertTrue(monitor.toString().startsWith("HealthCheckMonitor ["));
+ assertTrue(monitor.toString().startsWith("HealthCheckManager("));
}
@Test
setPdpType(properties.getProperty(PDP_TYPE, DEFAULT_PDP_TYPE));
policyTypesMap.put(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER,
- new PolicyTypeNativeDroolsController(this, POLICY_TYPE_DROOLS_NATIVE_CONTROLLER));
+ new PolicyTypeNativeDroolsController(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER, this));
policyTypesMap.put(
POLICY_TYPE_DROOLS_NATIVE_RULES,
- new PolicyTypeNativeArtifactController(this, POLICY_TYPE_DROOLS_NATIVE_RULES));
+ new PolicyTypeNativeArtifactController(POLICY_TYPE_DROOLS_NATIVE_RULES, this));
String commaSeparatedPolicyTypes = properties.getProperty(MANDATORY_POLICY_TYPES);
if (!StringUtils.isBlank(commaSeparatedPolicyTypes)) {
for (ToscaConceptIdentifier id : controller.getPolicyTypes()) {
PolicyTypeDroolsController ptDc = (PolicyTypeDroolsController) policyTypesMap.get(id); //NOSONAR
if (ptDc == null) {
- policyTypesMap.put(id, new PolicyTypeDroolsController(this, id, controller));
+ policyTypesMap.put(id, new PolicyTypeDroolsController(id, this, controller));
logger.info("policy-type {} added", id);
} else {
ptDc.add(controller);
* Creates a Policy Type Drools Controller.
*/
public PolicyTypeDroolsController(
- LifecycleFsm fsm, ToscaConceptIdentifier policyType, PolicyController controller) {
+ ToscaConceptIdentifier policyType, LifecycleFsm fsm, PolicyController controller) {
this.policyType = policyType;
this.controllers.put(controller.getName(), controller);
this.fsm = fsm;
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.drools.lifecycle;
+import lombok.AllArgsConstructor;
import lombok.Getter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.utils.coder.CoderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@AllArgsConstructor
public class PolicyTypeNativeArtifactController implements PolicyTypeController {
private static final Logger logger = LoggerFactory.getLogger(PolicyTypeNativeArtifactController.class);
@GsonJsonIgnore
protected final LifecycleFsm fsm;
- public PolicyTypeNativeArtifactController(LifecycleFsm fsm, ToscaConceptIdentifier policyType) {
- this.policyType = policyType;
- this.fsm = fsm;
- }
-
@Override
public boolean deploy(ToscaPolicy policy) {
NativeArtifactPolicy nativePolicy;
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
+import lombok.AllArgsConstructor;
import lombok.Getter;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@AllArgsConstructor
public class PolicyTypeNativeDroolsController implements PolicyTypeController {
private static final Logger logger = LoggerFactory.getLogger(PolicyTypeNativeDroolsController.class);
@GsonJsonIgnore
protected final LifecycleFsm fsm;
- public PolicyTypeNativeDroolsController(LifecycleFsm fsm, ToscaConceptIdentifier policyType) {
- this.policyType = policyType;
- this.fsm = fsm;
- }
-
@Override
public boolean deploy(ToscaPolicy policy) {
var controllerProps = new Properties();
policy = getExamplesPolicy(VCPE_OPERATIONAL_DROOLS_POLICY_JSON, OP_POLICY_NAME_VCPE);
fsm.getDomainMaker().convertTo(policy, OperationalPolicy.class);
controller = new PolicyTypeDroolsController(
- fsm, PolicyTypeDroolsController.compliantType, controllerSupport.getController());
+ PolicyTypeDroolsController.compliantType, fsm, controllerSupport.getController());
assertTrue(controllerSupport.getController().getDrools().isBrained());
assertFalse(controllerSupport.getController().isAlive());
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
fsm = makeFsmWithPseudoTime();
policy = getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_POLICY_NAME);
nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
- controller =
- new PolicyTypeNativeArtifactController(fsm,
- new ToscaConceptIdentifier("onap.policies.native.drools.Artifact", "1.0.0"));
+ controller = new PolicyTypeNativeArtifactController(
+ new ToscaConceptIdentifier("onap.policies.native.drools.Artifact", "1.0.0"), fsm);
assertTrue(controllerSupport.getController().getDrools().isBrained());
assertFalse(controllerSupport.getController().isAlive());
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. 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.
ToscaPolicy policy = getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_POLICY_NAME);
ControllerPolicy controllerPolicy = fsm.getDomainMaker().convertTo(policy, ControllerPolicy.class);
PolicyTypeNativeDroolsController controller =
- new PolicyTypeNativeDroolsController(fsm, policy.getTypeIdentifier());
+ new PolicyTypeNativeDroolsController(policy.getTypeIdentifier(), fsm);
assertTrue(controller.undeploy(policy));
assertThatIllegalArgumentException().isThrownBy(
() -> PolicyControllerConstants.getFactory().get(controllerPolicy.getName()));
ToscaPolicy nativeControllerPolicy =
getExamplesPolicy("policies/usecases.native.controller.policy.input.tosca.json", "usecases");
PolicyTypeNativeDroolsController controller =
- new PolicyTypeNativeDroolsController(fsm, nativeControllerPolicy.getTypeIdentifier());
+ new PolicyTypeNativeDroolsController(nativeControllerPolicy.getTypeIdentifier(), fsm);
assertTrue(controller.deploy(nativeControllerPolicy));
Properties properties = PolicyControllerConstants.getFactory().get("usecases").getProperties();
assertTrue(controller.undeploy(nativeControllerPolicy));
}
-}
\ No newline at end of file
+}
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
private final Map<String, FilterRule> rules = new HashMap<>();
@Getter
+ @AllArgsConstructor
public static class FilterRule {
private String mdcKey;
private List<String> paths;
this.paths = Arrays.asList(path);
}
- /**
- * Constructor.
- *
- * @param mdcKey the key to the filter rule
- * @param paths the list of potential paths to the key
- */
- public FilterRule(String mdcKey, List<String> paths) {
- this.mdcKey = mdcKey;
- this.paths = paths;
- }
-
protected void setMdcKey(String mdcKey) {
if (StringUtils.isBlank(mdcKey)) {
throw new IllegalArgumentException(MDC_KEY_ERROR);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling;
import java.util.List;
+import lombok.Getter;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
/**
* Name of the DMaaP topic.
*/
+ @Getter
private final String topic;
/**
}
}
- public String getTopic() {
- return topic;
- }
-
/**
* Finds the topic source associated with the internal DMaaP topic.
*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
+import lombok.AccessLevel;
+import lombok.Getter;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
/**
* ID of this host.
*/
+ @Getter
private final String host;
/**
/**
* Decremented each time a manager enters the Active state. Used by junit tests.
*/
+ @Getter(AccessLevel.PROTECTED)
private final CountDownLatch activeLatch = new CountDownLatch(1);
/**
this.host = UUID.randomUUID().toString();
}
- public String getHost() {
- return host;
- }
-
- /**
- * Get active latch.
- *
- * @return a latch that will be decremented when a manager enters the active state
- */
- protected CountDownLatch getActiveLatch() {
- return activeLatch;
- }
-
@Override
public int getSequenceNumber() {
return 0;
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
+import lombok.Getter;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicListener;
import org.onap.policy.drools.controller.DroolsController;
/**
* ID of this host.
*/
+ @Getter
private final String host;
/**
* Properties with which this was configured.
*/
- private final PoolingProperties props;
+ @Getter
+ private final PoolingProperties properties;
/**
* Associated controller.
/**
* Internal DMaaP topic used by this controller.
*/
+ @Getter
private final String topic;
/**
/**
* Current bucket assignments or {@code null}.
*/
+ @Getter
private BucketAssignments assignments = null;
/**
CountDownLatch activeLatch) {
this.host = host;
this.controller = controller;
- this.props = props;
+ this.properties = props;
this.activeLatch = activeLatch;
try {
}
}
- @Override
- public String getHost() {
- return host;
- }
-
- @Override
- public String getTopic() {
- return topic;
- }
-
- @Override
- public PoolingProperties getProperties() {
- return props;
- }
-
/**
* Indicates that the controller is about to start. Starts the publisher for the
* internal topic, and creates a thread pool for the timers.
* stop the publisher, but allow time for any Offline message to be
* transmitted
*/
- dmaapMgr.stopPublisher(props.getOfflinePubWaitMs());
+ dmaapMgr.stopPublisher(properties.getOfflinePubWaitMs());
}
}
}
}
- @Override
- public BucketAssignments getAssignments() {
- return assignments;
- }
-
@Override
public State goStart() {
return new StartState(this);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling;
import java.util.Properties;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.common.utils.properties.BeanConfigurator;
import org.onap.policy.common.utils.properties.Property;
import org.onap.policy.common.utils.properties.SpecProperties;
/**
* Properties used by the pooling feature, specific to a controller.
*/
+@Getter
+@Setter
public class PoolingProperties {
/**
new BeanConfigurator().configureFromProperties(this, new SpecProperties(PREFIX, controllerName, props));
}
-
- public Properties getSource() {
- return source;
- }
-
- public String getPoolingTopic() {
- return poolingTopic;
- }
-
- public int getOfflineLimit() {
- return offlineLimit;
- }
-
- public long getOfflineAgeMs() {
- return offlineAgeMs;
- }
-
- public long getOfflinePubWaitMs() {
- return offlinePubWaitMs;
- }
-
- public long getStartHeartbeatMs() {
- return startHeartbeatMs;
- }
-
- public long getReactivateMs() {
- return reactivateMs;
- }
-
- public long getIdentificationMs() {
- return identificationMs;
- }
-
- public long getActiveHeartbeatMs() {
- return activeHeartbeatMs;
- }
-
- public long getInterHeartbeatMs() {
- return interHeartbeatMs;
- }
-
- public void setPoolingTopic(String poolingTopic) {
- this.poolingTopic = poolingTopic;
- }
-
- public void setOfflineLimit(int offlineLimit) {
- this.offlineLimit = offlineLimit;
- }
-
- public void setOfflineAgeMs(long offlineAgeMs) {
- this.offlineAgeMs = offlineAgeMs;
- }
-
- public void setOfflinePubWaitMs(long offlinePubWaitMs) {
- this.offlinePubWaitMs = offlinePubWaitMs;
- }
-
- public void setStartHeartbeatMs(long startHeartbeatMs) {
- this.startHeartbeatMs = startHeartbeatMs;
- }
-
- public void setReactivateMs(long reactivateMs) {
- this.reactivateMs = reactivateMs;
- }
-
- public void setIdentificationMs(long identificationMs) {
- this.identificationMs = identificationMs;
- }
-
- public void setActiveHeartbeatMs(long activeHeartbeatMs) {
- this.activeHeartbeatMs = activeHeartbeatMs;
- }
-
- public void setInterHeartbeatMs(long interHeartbeatMs) {
- this.interHeartbeatMs = interHeartbeatMs;
- }
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
class2type.forEach((clazz, type) -> type2class.put(type, clazz));
}
- /**
- * Constructor.
- */
- public Serializer() {
- super();
- }
-
/**
* Encodes a filter.
*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2021 AT&T Intellectual Property. 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.
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
import org.onap.policy.drools.pooling.PoolingFeatureException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Bucket assignments, which is simply an array of host names.
*/
+@Getter
+@Setter
+@NoArgsConstructor
public class BucketAssignments {
private static final Logger logger = LoggerFactory.getLogger(BucketAssignments.class);
*/
private String[] hostArray = null;
- /**
- * Constructor.
- */
- public BucketAssignments() {
- super();
- }
/**
* Constructor.
this.hostArray = hostArray;
}
- public String[] getHostArray() {
- return hostArray;
- }
-
- public void setHostArray(String[] hostArray) {
- this.hostArray = hostArray;
- }
-
/**
* Gets the leader, which is the host with the minimum UUID.
*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
/**
* Heart beat message sent to self, or to the succeeding host.
*/
+@Getter
+@Setter
+@NoArgsConstructor
public class Heartbeat extends Message {
/**
/**
* Constructor.
- */
- public Heartbeat() {
- super();
-
- }
-
- /**
- * Constructor.
- *
+ *
* @param source host on which the message originated
* @param timestampMs time, in milliseconds, associated with the message
*/
this.timestampMs = timestampMs;
}
-
- public long getTimestampMs() {
- return timestampMs;
- }
-
- public void setTimestampMs(long timestampMs) {
- this.timestampMs = timestampMs;
- }
-
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.NoArgsConstructor;
+
/**
* Identifies the source host and the bucket assignments which it knows about.
*/
+@NoArgsConstructor
public class Identification extends MessageWithAssignments {
/**
* Constructor.
- */
- public Identification() {
- super();
-
- }
-
- /**
- * Constructor.
- *
+ *
* @param source host on which the message originated
* @param assignments assignments
*/
public Identification(String source, BucketAssignments assignments) {
super(source, assignments);
}
-
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.NoArgsConstructor;
import org.onap.policy.drools.pooling.PoolingFeatureException;
/**
* Indicates that the "source" of this message is now the "lead" host.
*/
+@NoArgsConstructor
public class Leader extends MessageWithAssignments {
/**
* Constructor.
- */
- public Leader() {
- super();
- }
-
- /**
- * Constructor.
- *
+ *
* @param source host on which the message originated
* @param assignments assignments
*/
}
String leader = getSource();
-
+
if (!assignments.hasAssignment(leader)) {
- throw new PoolingFeatureException("leader " + leader + " has no bucket assignments");
+ throw new PoolingFeatureException("leader " + leader + " has no bucket assignments");
}
-
+
for (String host : assignments.getHostArray()) {
if (host.compareTo(leader) < 0) {
throw new PoolingFeatureException("invalid leader " + leader + ", should be " + host);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
import org.onap.policy.drools.pooling.PoolingFeatureException;
/**
* Messages sent on the internal topic.
*/
+@Getter
+@Setter
+@NoArgsConstructor
public class Message {
/**
*/
private String channel;
- /**
- * Constructor.
- */
- public Message() {
- super();
- }
/**
* Constructor.
- *
+ *
* @param source host on which the message originated
*/
public Message(String source) {
this.source = source;
}
- public String getSource() {
- return source;
- }
-
- public void setSource(String source) {
- this.source = source;
- }
-
- public String getChannel() {
- return channel;
- }
-
- public void setChannel(String channel) {
- this.channel = channel;
- }
-
/**
* Checks the validity of the message, including verifying that required
* fields are not missing.
- *
+ *
* @throws PoolingFeatureException if the message is invalid
*/
public void checkValidity() throws PoolingFeatureException {
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
import org.onap.policy.drools.pooling.PoolingFeatureException;
/**
* A Message that includes bucket assignments.
*/
+@NoArgsConstructor
public class MessageWithAssignments extends Message {
/**
* Bucket assignments, as known by the source host.
*/
+ @Getter
+ @Setter
private BucketAssignments assignments;
- /**
- * Constructor.
- */
- public MessageWithAssignments() {
- super();
- }
/**
* Constructor.
- *
+ *
* @param source host on which the message originated
* @param assignments assignements
*/
super(source);
this.assignments = assignments;
-
- }
-
- public BucketAssignments getAssignments() {
- return assignments;
- }
-
- public void setAssignments(BucketAssignments assignments) {
- this.assignments = assignments;
}
/**
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.NoArgsConstructor;
+
/**
* Indicates that the source host is going offline and will be unable to process
* any further requests.
*/
+@NoArgsConstructor
public class Offline extends Message {
/**
* Constructor.
- */
- public Offline() {
- super();
-
- }
-
- /**
- * Constructor.
- *
+ *
* @param source host on which the message originated
*/
public Offline(String source) {
super(source);
}
-
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.message;
+import lombok.NoArgsConstructor;
+
/**
* Query the other hosts for their identification.
*/
+@NoArgsConstructor
public class Query extends Message {
/**
* Constructor.
- */
- public Query() {
- super();
-
- }
-
- /**
- * Constructor.
- *
+ *
* @param source host on which the message originated
*/
public Query(String source) {
super(source);
}
-
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. 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.
import java.util.Arrays;
import java.util.TreeSet;
+import lombok.AccessLevel;
+import lombok.Getter;
import org.onap.policy.drools.pooling.PoolingManager;
import org.onap.policy.drools.pooling.message.Heartbeat;
import org.onap.policy.drools.pooling.message.Leader;
* processes any events associated with one of its buckets. Other events are forwarded to
* appropriate target hosts.
*/
+@Getter(AccessLevel.PROTECTED)
public class ActiveState extends ProcessingState {
private static final Logger logger = LoggerFactory.getLogger(ActiveState.class);
/**
* Set of hosts that have been assigned a bucket.
*/
+ @Getter(AccessLevel.NONE)
private final TreeSet<String> assigned = new TreeSet<>();
/**
*/
private boolean predHeartbeatSeen = false;
+
/**
* Constructor.
*
return null;
}
}
-
- protected String getSuccHost() {
- return succHost;
- }
-
- protected String getPredHost() {
- return predHost;
- }
-
- protected boolean isMyHeartbeatSeen() {
- return myHeartbeatSeen;
- }
-
- protected boolean isPredHeartbeatSeen() {
- return predHeartbeatSeen;
- }
-
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2021 AT&T Intellectual Property. 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.
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
import org.onap.policy.drools.pooling.PoolingManager;
import org.onap.policy.drools.pooling.message.BucketAssignments;
import org.onap.policy.drools.pooling.message.Leader;
/**
* Any state in which events are being processed locally and forwarded, as appropriate.
*/
+@Getter
public class ProcessingState extends State {
private static final Logger logger = LoggerFactory.getLogger(ProcessingState.class);
/**
* Current known leader, never {@code null}.
*/
+ @NonNull
+ @Setter
private String leader;
/**
* Constructor.
- *
+ *
* @param mgr pooling manager
* @param leader current known leader, which need not be the same as the assignment
* leader. Never {@code null}
/**
* Sets the assignments.
- *
+ *
* @param assignments new assignments, or {@code null}
*/
protected final void setAssignments(BucketAssignments assignments) {
}
}
- public String getLeader() {
- return leader;
- }
-
- /**
- * Sets the leader.
- *
- * @param leader the new leader
- * @throws IllegalArgumentException if an argument is invalid
- */
- protected void setLeader(String leader) {
- if (leader == null) {
- throw new IllegalArgumentException("null leader");
- }
-
- this.leader = leader;
- }
-
/**
* Determines if this host is the leader, based on the current assignments.
- *
+ *
* @return {@code true} if this host is the leader, {@code false} otherwise
*/
public boolean isLeader() {
/**
* Becomes the leader. Publishes a Leader message and enters the {@link ActiveState}.
- *
+ *
* @param alive hosts that are known to be alive
- *
+ *
* @return the new state
*/
protected State becomeLeader(SortedSet<String> alive) {
/**
* Makes a leader message. Assumes "this" host is the leader, and thus appears as the
* first host in the set of hosts that are still alive.
- *
+ *
* @param alive hosts that are known to be alive
- *
+ *
* @return a new message
*/
private Leader makeLeader(Set<String> alive) {
/**
* Makes a set of bucket assignments. Assumes "this" host is the leader.
- *
+ *
* @param alive hosts that are known to be alive
- *
+ *
* @return a new set of bucket assignments
*/
private BucketAssignments makeAssignments(Set<String> alive) {
/**
* Makes a bucket array, copying the current assignments, if available.
- *
+ *
* @return a new bucket array
*/
private String[] makeBucketArray() {
/**
* Removes excess hosts from the set of available hosts. Assumes "this" host is the
* leader, and thus appears as the first host in the set.
- *
+ *
* @param maxHosts maximum number of hosts to be retained
* @param avail available hosts
*/
* Adds bucket indices to {@link HostBucket} objects. Buckets that are unassigned or
* assigned to a host that does not appear within the map are re-assigned to a host
* that appears within the map.
- *
+ *
* @param bucket2host bucket assignments
* @param host2data maps a host name to its {@link HostBucket}
*/
/**
* Assigns null buckets (i.e., those having no assignment) to available hosts.
- *
+ *
* @param buckets buckets that still need to be assigned to hosts
* @param coll collection of current host-bucket assignments
*/
* Re-balances the buckets, taking from those that have a larger count and giving to
* those that have a smaller count. Populates an output array with the new
* assignments.
- *
+ *
* @param coll current bucket assignment
* @param bucket2host array to be populated with the new assignments
*/
/**
* Fills the array with the host assignments.
- *
+ *
* @param coll the host assignments
* @param bucket2host array to be filled
*/
/**
* Constructor.
- *
+ *
* @param host host
*/
public HostBucket(String host) {
/**
* Removes the next bucket from the list.
- *
+ *
* @return the next bucket
*/
public final Integer remove() {
/**
* Adds a bucket to the list.
- *
+ *
* @param index index of the bucket to add
*/
public final void add(Integer index) {
/**
* Size.
- *
+ *
* @return the number of buckets assigned to this host
*/
public final int size() {
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. 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.
package org.onap.policy.drools.pooling.state;
+import lombok.Getter;
import org.onap.policy.drools.pooling.PoolingManager;
import org.onap.policy.drools.pooling.message.Heartbeat;
import org.slf4j.Logger;
* to look for just that particular message. Once the message is seen, it goes into the
* {@link QueryState}.
*/
+@Getter
public class StartState extends State {
private static final Logger logger = LoggerFactory.getLogger(StartState.class);
super(mgr);
}
- /**
- * Get Heart beat time stamp in milliseconds.
- *
- * @return the time stamp inserted into the heart beat message
- */
- public long getHbTimestampMs() {
- return hbTimestampMs;
- }
-
@Override
public void start() {
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. 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.
assertEquals(MY_HOST, state.getLeader());
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = NullPointerException.class)
public void testSetLeader_Null() {
state.setLeader(null);
}