<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
- <scope>provided</scope>
+ <scope>provided</scope>
</dependency>
<!--REQUIRED TO GENERATE DOCUMENTATION -->
<dependency>
package org.oransc.policyagent;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import org.oransc.policyagent.clients.A1ClientFactory;
import org.oransc.policyagent.configuration.ApplicationConfig;
import org.oransc.policyagent.repository.Policies;
@Bean
public ObjectMapper mapper() {
- return new ObjectMapper();
+ return new ObjectMapper();
}
}
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
+import lombok.Getter;
+
import org.oransc.policyagent.exceptions.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
private Collection<Observer> observers = new Vector<>();
private Map<String, RicConfig> ricConfigs = new HashMap<>();
+ @Getter
private Properties dmaapPublisherConfig;
+ @Getter
private Properties dmaapConsumerConfig;
@Autowired
throw new ServiceException("Could not find ric: " + ricName);
}
- public Properties getDmaapPublisherConfig() {
- return dmaapConsumerConfig;
- }
-
- public Properties getDmaapConsumerConfig() {
- return dmaapConsumerConfig;
- }
-
public static enum RicConfigUpdate {
ADDED, CHANGED, REMOVED
}
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
+
import javax.validation.constraints.NotNull;
+
import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
import org.oransc.policyagent.exceptions.ServiceException;
import org.springframework.http.MediaType;
String urlPath = url.getPath();
DmaapUrlPath path = parseDmaapUrlPath(urlPath);
- dmaapProps.put("ServiceName", url.getHost()+":"+url.getPort()+"/events");
+ dmaapProps.put("ServiceName", url.getHost() + ":" + url.getPort() + "/events");
dmaapProps.put("topic", path.dmaapTopicName);
- dmaapProps.put("host", url.getHost()+":"+url.getPort());
+ dmaapProps.put("host", url.getHost() + ":" + url.getPort());
dmaapProps.put("contenttype", MediaType.APPLICATION_JSON.toString());
dmaapProps.put("userName", userName);
dmaapProps.put("password", passwd);
throw new ServiceException("The path has incorrect syntax: " + urlPath);
}
- final String dmaapTopicName = tokens[2]; // /events/A1-P
+ final String dmaapTopicName = tokens[2]; // /events/A1-P
String consumerGroup = ""; // users
String consumerId = ""; // sdnc1
if (tokens.length == 5) {
package org.oransc.policyagent.configuration;
import java.util.concurrent.Executor;
+
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
@Override
@Bean(name = "threadPoolTaskExecutor")
public Executor getAsyncExecutor() {
- //Set this configuration value from common properties file
+ // Set this configuration value from common properties file
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setMaxPoolSize(10);
public Mono<ResponseEntity<Void>> deletePolicy( //
@RequestParam(name = "instance", required = true) String id) {
Policy policy = policies.get(id);
- if (policy != null && policy.ric().state().equals(Ric.RicState.IDLE)) {
+ if (policy != null && policy.ric().getState() == (Ric.RicState.IDLE)) {
policies.remove(policy);
return a1ClientFactory.createA1Client(policy.ric()) //
.flatMap(client -> client.deletePolicy(policy)) //
Ric ric = rics.get(ricName);
PolicyType type = policyTypes.get(typeName);
- if (ric != null && type != null && ric.state().equals(Ric.RicState.IDLE)) {
+ if (ric != null && type != null && ric.getState() == (Ric.RicState.IDLE)) {
Policy policy = ImmutablePolicy.builder() //
.id(instanceId) //
.json(jsonBody) //
Collection<ServiceStatus> servicesStatus = new Vector<>();
synchronized (this.services) {
for (Service s : this.services.getAll()) {
- if (name == null || name.equals(s.name())) {
+ if (name == null || name.equals(s.getName())) {
servicesStatus.add(toServiceStatus(s));
}
}
private ServiceStatus toServiceStatus(Service s) {
return ImmutableServiceStatus.builder() //
- .name(s.name()) //
+ .name(s.getName()) //
.keepAliveInterval(s.getKeepAliveInterval().toSeconds()) //
.timeSincePing(s.timeSinceLastPing().toSeconds()) //
.build();
private Service removeService(String name) throws ServiceException {
synchronized (this.services) {
Service service = this.services.getService(name);
- this.services.remove(service.name());
+ this.services.remove(service.getName());
return service;
}
}
private void removePolicies(Service service) {
synchronized (this.policies) {
- Vector<Policy> policyList = new Vector<>(this.policies.getForService(service.name()));
+ Vector<Policy> policyList = new Vector<>(this.policies.getForService(service.getName()));
for (Policy policy : policyList) {
this.policies.remove(policy);
}
import java.util.Map;
import java.util.Vector;
+import lombok.Getter;
+import lombok.Setter;
+
import org.oransc.policyagent.clients.A1Client.A1ProtocolType;
import org.oransc.policyagent.configuration.RicConfig;
*/
public class Ric {
private final RicConfig ricConfig;
+ @Getter
+ @Setter
private RicState state = RicState.UNDEFINED;
private Map<String, PolicyType> supportedPolicyTypes = new HashMap<>();
+ @Getter
+ @Setter
private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN;
/**
return ricConfig.name();
}
- public RicState state() {
- return state;
- }
-
- public void setState(RicState newState) {
- state = newState;
- }
-
public RicConfig getConfig() {
return this.ricConfig;
}
*/
public static enum RicState {
/**
- * The agent view of the agent may be inconsistent
+ * The agent view of the agent may be inconsistent.
*/
UNDEFINED,
/**
*/
IDLE,
/**
- * The Ric states are recovered
+ * The Ric states are recovered.
*/
RECOVERING
}
-
- public A1ProtocolType getProtocolVersion() {
- return protocolVersion;
- }
-
- public void setProtocolVersion(A1ProtocolType version) {
- protocolVersion = version;
-
- }
-
}
import java.time.Duration;
import java.time.Instant;
+import lombok.Getter;
+
public class Service {
+ @Getter
private final String name;
private final Duration keepAliveInterval;
private Instant lastPing;
ping();
}
- public synchronized String name() {
- return this.name;
- }
-
public synchronized Duration getKeepAliveInterval() {
return this.keepAliveInterval;
}
}
public synchronized void put(Service service) {
- logger.debug("Put service: " + service.name());
- services.put(service.name(), service);
+ logger.debug("Put service: " + service.getName());
+ services.put(service.getName(), service);
}
public synchronized Iterable<Service> getAll() {
}
private Mono<RicData> checkRicState(RicData ric) {
- if (ric.ric.state() == RicState.UNDEFINED) {
+ if (ric.ric.getState() == RicState.UNDEFINED) {
return startRecovery(ric);
- } else if (ric.ric.state() == RicState.RECOVERING) {
+ } else if (ric.ric.getState() == RicState.RECOVERING) {
return Mono.empty();
} else {
return Mono.just(ric);
logger.debug("Handling ric: {}", ric.getConfig().name());
synchronized (ric) {
- if (ric.state().equals(Ric.RicState.RECOVERING)) {
+ if (ric.getState() == (Ric.RicState.RECOVERING)) {
return; // Already running
}
ric.setState(Ric.RicState.RECOVERING);
synchronized (services) {
return Flux.fromIterable(services.getAll()) //
.filter(service -> service.isExpired()) //
- .doOnNext(service -> logger.info("Service is expired:" + service.name())) //
+ .doOnNext(service -> logger.info("Service is expired:" + service.getName())) //
.flatMap(service -> getAllPolicies(service)) //
.doOnNext(policy -> this.policies.remove(policy)) //
.flatMap(policy -> deletePolicyInRic(policy));
private Flux<Policy> getAllPolicies(Service service) {
synchronized (policies) {
- return Flux.fromIterable(policies.getForService(service.name()));
+ return Flux.fromIterable(policies.getForService(service.getName()));
}
}
supervisorUnderTest.checkAllRics();
- await().untilAsserted(() -> RicState.IDLE.equals(ric1.state()));
- await().untilAsserted(() -> RicState.IDLE.equals(ric2.state()));
- await().untilAsserted(() -> RicState.IDLE.equals(ric3.state()));
+ await().untilAsserted(() -> RicState.IDLE.equals(ric1.getState()));
+ await().untilAsserted(() -> RicState.IDLE.equals(ric2.getState()));
+ await().untilAsserted(() -> RicState.IDLE.equals(ric3.getState()));
verify(a1ClientMock, times(3)).deleteAllPolicies();
verifyNoMoreInteractions(a1ClientMock);
Ric firstRic = rics.get(FIRST_RIC_NAME);
assertNotNull(firstRic, "Ric " + FIRST_RIC_NAME + " not added to repository");
assertEquals(FIRST_RIC_NAME, firstRic.name(), FIRST_RIC_NAME + " not added to Rics");
- assertEquals(IDLE, firstRic.state(), "Not correct state for ric " + FIRST_RIC_NAME);
+ assertEquals(IDLE, firstRic.getState(), "Not correct state for ric " + FIRST_RIC_NAME);
assertEquals(1, firstRic.getSupportedPolicyTypes().size(),
"Not correct no of types supported for ric " + FIRST_RIC_NAME);
assertTrue(firstRic.isSupportingType(POLICY_TYPE_1_NAME),
Ric secondRic = rics.get(SECOND_RIC_NAME);
assertNotNull(secondRic, "Ric " + SECOND_RIC_NAME + " not added to repository");
assertEquals(SECOND_RIC_NAME, secondRic.name(), SECOND_RIC_NAME + " not added to Rics");
- assertEquals(IDLE, secondRic.state(), "Not correct state for " + SECOND_RIC_NAME);
+ assertEquals(IDLE, secondRic.getState(), "Not correct state for " + SECOND_RIC_NAME);
assertEquals(2, secondRic.getSupportedPolicyTypes().size(),
"Not correct no of types supported for ric " + SECOND_RIC_NAME);
assertTrue(secondRic.isSupportingType(POLICY_TYPE_1_NAME),
serviceUnderTest.onRicConfigUpdate(getRicConfig(FIRST_RIC_NAME, FIRST_RIC_URL, MANAGED_NODE_A),
ApplicationConfig.RicConfigUpdate.ADDED);
- assertEquals(RicState.UNDEFINED, rics.get(FIRST_RIC_NAME).state(), "Not correct state for " + FIRST_RIC_NAME);
+ assertEquals(RicState.UNDEFINED, rics.get(FIRST_RIC_NAME).getState(),
+ "Not correct state for " + FIRST_RIC_NAME);
}
@Test
serviceUnderTest.onRicConfigUpdate(getRicConfig(FIRST_RIC_NAME, FIRST_RIC_URL, MANAGED_NODE_A),
ApplicationConfig.RicConfigUpdate.ADDED);
- assertEquals(RicState.UNDEFINED, rics.get(FIRST_RIC_NAME).state(), "Not correct state for " + FIRST_RIC_NAME);
+ assertEquals(RicState.UNDEFINED, rics.get(FIRST_RIC_NAME).getState(),
+ "Not correct state for " + FIRST_RIC_NAME);
}
@SafeVarargs