Make use of Lombok 51/2351/2
authorelinuxhenrik <henrik.b.andersson@est.tech>
Tue, 28 Jan 2020 07:59:39 +0000 (08:59 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Tue, 28 Jan 2020 09:40:47 +0000 (10:40 +0100)
Change-Id: I1f7f3c1a46f82f317cf5c97ed6c67a79ae78276f
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
15 files changed:
policy-agent/pom.xml
policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfig.java
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java
policy-agent/src/main/java/org/oransc/policyagent/configuration/AsyncConfiguration.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/PolicyController.java
policy-agent/src/main/java/org/oransc/policyagent/controllers/ServiceController.java
policy-agent/src/main/java/org/oransc/policyagent/repository/Ric.java
policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java
policy-agent/src/main/java/org/oransc/policyagent/repository/Services.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/RepositorySupervision.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/RicRecoveryTask.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/ServiceSupervision.java
policy-agent/src/test/java/org/oransc/policyagent/tasks/RepositorySupervisionTest.java
policy-agent/src/test/java/org/oransc/policyagent/tasks/StartupServiceTest.java

index f2a9411..06f77c5 100644 (file)
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
-         <scope>provided</scope>
+            <scope>provided</scope>
         </dependency>
                <!--REQUIRED TO GENERATE DOCUMENTATION -->
                <dependency>
index e05eb95..8ed1c21 100644 (file)
@@ -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();
     }
 
 }
index 1ed3fdb..86fd556 100644 (file)
@@ -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<Observer> observers = new Vector<>();
     private Map<String, RicConfig> 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
     }
index 34d1d97..807b12f 100644 (file)
@@ -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) {
index 085320c..882f30c 100644 (file)
@@ -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);
index f794ab5..4376f04 100644 (file)
@@ -145,7 +145,7 @@ public class PolicyController {
     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)) //
@@ -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) //
index cc1d711..8996376 100644 (file)
@@ -71,7 +71,7 @@ public class ServiceController {
         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));
                 }
             }
@@ -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<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);
             }
index 4169150..220477f 100644 (file)
@@ -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<String, PolicyType> 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;
-
-    }
-
 }
index 18a85a9..bcdc2ee 100644 (file)
@@ -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;
     }
index 01d6a7a..369b258 100644 (file)
@@ -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<Service> getAll() {
index 022ca0f..d95272b 100644 (file)
@@ -100,9 +100,9 @@ public class RepositorySupervision {
     }
 
     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);
index 543fdf8..b67dbe0 100644 (file)
@@ -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);
index c10e004..d4b32e0 100644 (file)
@@ -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<Policy> getAllPolicies(Service service) {
         synchronized (policies) {
-            return Flux.fromIterable(policies.getForService(service.name()));
+            return Flux.fromIterable(policies.getForService(service.getName()));
         }
     }
 
index 20e54f0..92f48de 100644 (file)
@@ -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);
index bd1b058..164aca8 100644 (file)
@@ -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