From: elinuxhenrik Date: Tue, 28 Jan 2020 07:59:39 +0000 (+0100) Subject: Make use of Lombok X-Git-Tag: 1.0.1~22 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F51%2F2351%2F2;p=nonrtric.git Make use of Lombok Change-Id: I1f7f3c1a46f82f317cf5c97ed6c67a79ae78276f Signed-off-by: elinuxhenrik --- diff --git a/policy-agent/pom.xml b/policy-agent/pom.xml index f2a9411f..06f77c55 100644 --- a/policy-agent/pom.xml +++ b/policy-agent/pom.xml @@ -131,7 +131,7 @@ org.projectlombok lombok - provided + provided diff --git a/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java b/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java index e05eb95f..8ed1c218 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java @@ -21,6 +21,7 @@ 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; @@ -64,7 +65,7 @@ class BeanFactory { @Bean public ObjectMapper mapper() { - return new ObjectMapper(); + return new ObjectMapper(); } } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java index 1ed3fdb2..86fd5562 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java @@ -29,6 +29,8 @@ import java.util.Vector; 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; @@ -42,7 +44,9 @@ public class ApplicationConfig { private Collection observers = new Vector<>(); private Map ricConfigs = new HashMap<>(); + @Getter private Properties dmaapPublisherConfig; + @Getter private Properties dmaapConsumerConfig; @Autowired @@ -73,14 +77,6 @@ public class ApplicationConfig { 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 } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java index 34d1d97a..807b12f5 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java @@ -25,13 +25,16 @@ import com.google.gson.GsonBuilder; 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; @@ -122,9 +125,9 @@ public class ApplicationConfigParser { 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); @@ -162,7 +165,7 @@ public class ApplicationConfigParser { 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) { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/AsyncConfiguration.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/AsyncConfiguration.java index 085320c9..882f30c4 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/AsyncConfiguration.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/AsyncConfiguration.java @@ -21,6 +21,7 @@ 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; @@ -34,7 +35,7 @@ public class AsyncConfiguration implements 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); diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java index f794ab50..4376f04d 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java @@ -145,7 +145,7 @@ public class PolicyController { public Mono> 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)) // @@ -169,7 +169,7 @@ public class PolicyController { 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) // diff --git a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java index cc1d711b..8996376c 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java @@ -71,7 +71,7 @@ public class ServiceController { Collection 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)); } } @@ -83,7 +83,7 @@ public class ServiceController { private ServiceStatus toServiceStatus(Service s) { return ImmutableServiceStatus.builder() // - .name(s.name()) // + .name(s.getName()) // .keepAliveInterval(s.getKeepAliveInterval().toSeconds()) // .timeSincePing(s.timeSinceLastPing().toSeconds()) // .build(); @@ -118,14 +118,14 @@ public class ServiceController { 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 policyList = new Vector<>(this.policies.getForService(service.name())); + Vector policyList = new Vector<>(this.policies.getForService(service.getName())); for (Policy policy : policyList) { this.policies.remove(policy); } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java index 4169150b..220477f0 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java @@ -25,6 +25,9 @@ import java.util.HashMap; 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; @@ -33,8 +36,12 @@ import org.oransc.policyagent.configuration.RicConfig; */ public class Ric { private final RicConfig ricConfig; + @Getter + @Setter private RicState state = RicState.UNDEFINED; private Map supportedPolicyTypes = new HashMap<>(); + @Getter + @Setter private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN; /** @@ -50,14 +57,6 @@ public class Ric { return ricConfig.name(); } - public RicState state() { - return state; - } - - public void setState(RicState newState) { - state = newState; - } - public RicConfig getConfig() { return this.ricConfig; } @@ -152,7 +151,7 @@ public class Ric { */ public static enum RicState { /** - * The agent view of the agent may be inconsistent + * The agent view of the agent may be inconsistent. */ UNDEFINED, /** @@ -160,18 +159,8 @@ public class Ric { */ IDLE, /** - * The Ric states are recovered + * The Ric states are recovered. */ RECOVERING } - - public A1ProtocolType getProtocolVersion() { - return protocolVersion; - } - - public void setProtocolVersion(A1ProtocolType version) { - protocolVersion = version; - - } - } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java index 18a85a91..bcdc2ee0 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java @@ -23,7 +23,10 @@ package org.oransc.policyagent.repository; 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; @@ -36,10 +39,6 @@ public class Service { ping(); } - public synchronized String name() { - return this.name; - } - public synchronized Duration getKeepAliveInterval() { return this.keepAliveInterval; } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java index 01d6a7a8..369b2588 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java @@ -48,8 +48,8 @@ public class Services { } 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 getAll() { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RepositorySupervision.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RepositorySupervision.java index 022ca0f6..d95272b8 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RepositorySupervision.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RepositorySupervision.java @@ -100,9 +100,9 @@ public class RepositorySupervision { } private Mono 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); diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicRecoveryTask.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicRecoveryTask.java index 543fdf82..b67dbe0c 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicRecoveryTask.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicRecoveryTask.java @@ -68,7 +68,7 @@ public class RicRecoveryTask { 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); diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/ServiceSupervision.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/ServiceSupervision.java index c10e0047..d4b32e02 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/ServiceSupervision.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/ServiceSupervision.java @@ -72,7 +72,7 @@ public class ServiceSupervision { 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)); @@ -81,7 +81,7 @@ public class ServiceSupervision { private Flux getAllPolicies(Service service) { synchronized (policies) { - return Flux.fromIterable(policies.getForService(service.name())); + return Flux.fromIterable(policies.getForService(service.getName())); } } diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RepositorySupervisionTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RepositorySupervisionTest.java index 20e54f0c..92f48def 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/RepositorySupervisionTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/RepositorySupervisionTest.java @@ -124,9 +124,9 @@ public class RepositorySupervisionTest { 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); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java b/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java index bd1b0585..164aca82 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java @@ -122,7 +122,7 @@ public class StartupServiceTest { 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), @@ -134,7 +134,7 @@ public class StartupServiceTest { 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), @@ -161,7 +161,8 @@ public class StartupServiceTest { 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 @@ -181,7 +182,8 @@ public class StartupServiceTest { 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