@Value.Immutable
@Gson.TypeAdapters
interface RicInfo {
- public String name();
+ public String ricName();
public Collection<String> nodeNames();
List<RicInfo> rspParsed = gson.fromJson(rsp, listType);
Collection<String> result = new Vector<>(rspParsed.size());
for (RicInfo ric : rspParsed) {
- result.add(ric.name());
+ result.add(ric.ricName());
}
return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
} catch (Exception e) {
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.8.4</version>
+ <executions>
+ <execution>
+ <id>default-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
/**
* Creates an A1 client with the correct A1 protocol for the provided Ric.
*
- * <p>It detects the protocol version by trial and error, since there is no getVersion method specified in the A1
+ * <p>
+ * It detects the protocol version by trial and error, since there is no getVersion method specified in the A1
* api yet.
*
- * <p>As a side effect it also sets the protocol version in the provided Ric. This means that after the first
+ * <p>
+ * As a side effect it also sets the protocol version in the provided Ric. This means that after the first
* successful creation it won't have to try which protocol to use, but can create the client directly.
*
* @param ric The Ric to get a client for.
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Vector;
import org.oransc.policyagent.clients.A1ClientFactory;
import org.oransc.policyagent.configuration.ApplicationConfig;
.ownerServiceName(service) //
.lastModified(getTimeStampUtc()) //
.build();
- return a1ClientFactory.createA1Client(ric) //
+
+ return validateModifiedPolicy(policy) //
+ .flatMap(x -> a1ClientFactory.createA1Client(ric)) //
.flatMap(client -> client.putPolicy(policy)) //
.doOnNext(notUsed -> policies.put(policy)) //
.flatMap(notUsed -> Mono.just(new ResponseEntity<>(HttpStatus.OK)));
return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
+ private Mono<Object> validateModifiedPolicy(Policy policy) {
+ // Check that ric is not updated
+ Policy current = this.policies.get(policy.id());
+ if (current != null) {
+ if (!current.ric().name().equals(policy.ric().name())) {
+ return Mono.error(new Exception("Policy cannot change RIC or service"));
+ }
+ }
+ return Mono.just("OK");
+ }
+
@GetMapping("/policies")
@ApiOperation(value = "Query policies")
@ApiResponses(
@ApiModel(value = "RicInfo")
class RicInfo {
@ApiModelProperty(value = "identity of the ric")
- public final String name;
+ public final String ricName;
@ApiModelProperty(value = "O1 identities for managed entities")
public final Collection<String> managedElementIds;
public final Collection<String> policyTypes;
RicInfo(String name, Collection<String> managedElementIds, Collection<String> policyTypes) {
- this.name = name;
+ this.ricName = name;
this.managedElementIds = managedElementIds;
this.policyTypes = policyTypes;
}
public void testPutPolicy() throws Exception {
reset();
putService("service1");
+ this.addRic("ric1").setState(Ric.RicState.IDLE);
addPolicyType("type1", "ric1");
- String url = baseUrl() + "/policy?type=type1&instance=instance1&ric=ric1&service=service1";
final String json = jsonString();
- this.rics.getRic("ric1").setState(Ric.RicState.IDLE);
-
+ String url = baseUrl() + "/policy?type=type1&instance=instance1&ric=ric1&service=service1";
this.restTemplate.put(url, createJsonHttpEntity(json));
Policy policy = policies.getPolicy("instance1");
assertThat(policy).isNotNull();
assertThat(policy.id()).isEqualTo("instance1");
assertThat(policy.ownerServiceName()).isEqualTo("service1");
+ assertThat(policy.ric().name()).isEqualTo("ric1");
url = baseUrl() + "/policies";
String rsp = this.restTemplate.getForObject(url, String.class);
System.out.println(rsp);
+
+ }
+
+ @Test
+ public void testRefuseToUpdatePolicy() throws Exception {
+ // Test that only the json can be changed for a already created policy
+ // In this case service is attempted to be changed
+ reset();
+ this.addRic("ric1").setState(Ric.RicState.IDLE);
+ this.addRic("ricXXX").setState(Ric.RicState.IDLE);
+
+ this.addPolicy("instance1", "type1", "service1", "ric1");
+ String urlWrongRic = baseUrl() + "/policy?type=type1&instance=instance1&ric=ricXXX&service=service1";
+ this.restTemplate.put(urlWrongRic, createJsonHttpEntity(jsonString()));
+ Policy policy = policies.getPolicy("instance1");
+ assertThat(policy.ric().name()).isEqualTo("ric1"); // Not changed
}
private PolicyType addPolicyType(String policyTypeName, String ricName) {
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import java.util.Vector;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.oransc.policyagent.configuration.ImmutableRicConfig;
import org.oransc.policyagent.repository.Ric;
import org.oransc.policyagent.utils.LoggingUtils;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;