/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.
*/
<T extends PfConcept> List<T> getAllVersions(Class<T> someClass, final String name);
+ /**
+ * Get all the objects in the database of a given type.
+ *
+ * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
+ * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
+ * @param parentKeyName the name of the concepts for which to get all versions
+ * @return the objects or null if no objects were retrieved
+ */
+ <T extends PfConcept> List<T> getAllVersionsByParent(Class<T> someClass, final String parentKeyName);
+
/**
* Get a concept from the database with the given concept key.
*
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
private static final String SELECT_ALL_FOR_PARENT =
SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER;
+ private static final String SELECT_ALL_VERSIONS_FOR_PARENT =
+ SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER;
+
private static final String SELECT_ALL_VERSIONS = SELECT_FROM_TABLE + WHERE + NAME_FILTER;
private static final String SELECT_BY_CONCEPT_KEY =
}
}
+ @Override
+ public <T extends PfConcept> List<T> getAllVersionsByParent(final Class<T> someClass, final String parentKeyName) {
+ if (someClass == null || parentKeyName == null) {
+ return Collections.emptyList();
+ }
+ final EntityManager mg = getEntityManager();
+ try {
+ // @formatter:off
+ return mg.createQuery(setQueryTable(SELECT_ALL_VERSIONS_FOR_PARENT, someClass), someClass)
+ .setParameter(PARENT_NAME, parentKeyName)
+ .getResultList();
+ // @formatter:on
+ } finally {
+ mg.close();
+ }
+ }
+
@Override
public <T extends PfConcept> List<T> getAllVersions(final Class<T> someClass, final String conceptName) {
if (someClass == null || conceptName == null) {
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Bell Canada.
+ * Copyright (C) 2019-2021 Bell Canada.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<ExecutionServiceOutput>() {
@Override
public void onNext(ExecutionServiceOutput output) {
- LOGGER.info(LOG_MSG, EventType.IN, CommInfrastructure.REST, url, NetLoggerUtil.SYSTEM_LS,
- output);
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, url, output.toString());
-
listener.onMessage(output);
}
public void onError(Throwable throwable) {
LOGGER.info(LOG_MSG, EventType.IN, CommInfrastructure.REST, url, NetLoggerUtil.SYSTEM_LS,
throwable);
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, url, throwable.toString());
listener.onError(throwable);
finishLatch.countDown();
}
final StreamObserver<ExecutionServiceInput> requestObserver = asyncStub.process(responseObserver);
try {
- LOGGER.info(LOG_MSG, EventType.OUT, CommInfrastructure.REST, url, NetLoggerUtil.SYSTEM_LS,
- request);
NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, url, request.toString());
// Send the message to CDS backend for processing
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpPolicyStatus;
import org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
/**
* This class provides the provision of information on PAP concepts in the database to callers.
// Not implemented yet
}
+ /**
+ * Gets all policy deployments.
+ *
+ * @param dao the DAO to use to access the database
+ * @return the deployments found
+ * @throws PfModelException on errors getting PDP groups
+ */
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull final PfDao dao)
+ throws PfModelException {
+
+ return dao.getAll(JpaPdpPolicyStatus.class).stream().map(JpaPdpPolicyStatus::toAuthorative)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Gets all deployments for a policy.
+ *
+ * @param dao the DAO to use to access the database
+ * @return the deployments found
+ * @throws PfModelException on errors getting PDP groups
+ */
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull final PfDao dao,
+ @NonNull ToscaConceptIdentifierOptVersion policy) throws PfModelException {
+
+ if (policy.getVersion() != null) {
+ return dao.getAll(JpaPdpPolicyStatus.class, new PfConceptKey(policy.getName(), policy.getVersion()))
+ .stream().map(JpaPdpPolicyStatus::toAuthorative).collect(Collectors.toList());
+
+ } else {
+ return dao.getAllVersionsByParent(JpaPdpPolicyStatus.class, policy.getName()).stream()
+ .map(JpaPdpPolicyStatus::toAuthorative).collect(Collectors.toList());
+ }
+ }
+
/**
* Gets the policy deployments for a PDP group.
*
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
/**
private static final String PDP_GROUP0 = "PdpGroup0";
private static final String GROUP_A = "groupA";
private static final String GROUP_B = "groupB";
+ private static final ToscaConceptIdentifier MY_POLICY = new ToscaConceptIdentifier("MyPolicy", "1.2.3");
+ private static final ToscaConceptIdentifier MY_POLICY2 = new ToscaConceptIdentifier("MyPolicyB", "2.3.4");
+
private PfDao pfDao;
private StandardCoder standardCoder;
private PdpPolicyStatusBuilder statusBuilder;
*/
@Before
public void setupBuilder() {
- ToscaConceptIdentifier policy = new ToscaConceptIdentifier("MyPolicy", "1.2.3");
ToscaConceptIdentifier policyType = new ToscaConceptIdentifier("MyPolicyType", "1.2.4");
- statusBuilder = PdpPolicyStatus.builder().deploy(true).pdpType("MyPdpType").policy(policy)
+ statusBuilder = PdpPolicyStatus.builder().deploy(true).pdpType("MyPdpType").policy(MY_POLICY)
.policyType(policyType).state(State.SUCCESS);
}
new PdpProvider().updatePdpStatistics(pfDao, "name", "TYPE", "inst", new PdpStatistics());
}
+ @Test
+ public void testGetAllPolicyStatusPfDao() throws PfModelException {
+ assertThatThrownBy(() -> {
+ new PdpProvider().getAllPolicyStatus(null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThat(new PdpProvider().getAllPolicyStatus(pfDao)).isEmpty();
+
+ PdpProvider provider = loadDeployments();
+ assertThat(provider.getAllPolicyStatus(pfDao)).hasSize(5);
+ }
+
+ private PdpProvider loadDeployments() {
+ PdpProvider provider = new PdpProvider();
+
+ // same name, different version
+ final ToscaConceptIdentifier policy3 = new ToscaConceptIdentifier(MY_POLICY.getName(), "10.20.30");
+
+ PdpPolicyStatus id1 = statusBuilder.pdpGroup(GROUP_A).pdpId("pdp1").policy(MY_POLICY).build();
+ PdpPolicyStatus id2 = statusBuilder.pdpGroup(GROUP_A).pdpId("pdp2").policy(MY_POLICY2).build();
+ PdpPolicyStatus id3 = statusBuilder.pdpGroup(GROUP_A).pdpId("pdp3").policy(policy3).build();
+ PdpPolicyStatus id4 = statusBuilder.pdpGroup(GROUP_B).pdpId("pdp4").policy(MY_POLICY).build();
+ PdpPolicyStatus id5 = statusBuilder.pdpGroup(GROUP_B).pdpId("pdp5").policy(MY_POLICY2).build();
+ provider.cudPolicyStatus(pfDao, List.of(id1, id2, id3, id4, id5), null, null);
+
+ return provider;
+ }
+
+ @Test
+ public void testGetAllPolicyStatusPfDaoToscaConceptIdentifierOptVersion() throws PfModelException {
+ assertThatThrownBy(() -> {
+ new PdpProvider().getAllPolicyStatus(null, new ToscaConceptIdentifierOptVersion("somePdp", null));
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new PdpProvider().getAllPolicyStatus(pfDao, null);
+ }).hasMessageContaining("policy").hasMessageContaining("null");
+
+ assertThat(new PdpProvider().getAllPolicyStatus(pfDao, new ToscaConceptIdentifierOptVersion("somePdp", null)))
+ .isEmpty();
+
+ PdpProvider provider = loadDeployments();
+ assertThat(provider.getAllPolicyStatus(pfDao, new ToscaConceptIdentifierOptVersion(MY_POLICY))).hasSize(2);
+ assertThat(provider.getAllPolicyStatus(pfDao, new ToscaConceptIdentifierOptVersion(MY_POLICY.getName(), null)))
+ .hasSize(3);
+ }
+
@Test
public void testGetGroupPolicyStatus() throws PfModelException {
assertThatThrownBy(() -> {
}).hasMessageContaining("group").hasMessageContaining("null");
assertThat(new PdpProvider().getGroupPolicyStatus(pfDao, PDP_GROUP0)).isEmpty();
+
+ PdpProvider provider = loadDeployments();
+ assertThat(provider.getGroupPolicyStatus(pfDao, GROUP_A)).hasSize(3);
}
@Test
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
*/
public List<PdpStatistics> deletePdpStatistics(@NonNull String name, Date timestamp) throws PfModelException;
+ /**
+ * Gets all policy deployments.
+ *
+ * @return the deployments found
+ * @throws PfModelException on errors getting PDP groups
+ */
+ public List<PdpPolicyStatus> getAllPolicyStatus()
+ throws PfModelException;
+
+ /**
+ * Gets all deployments for a policy.
+ *
+ * @return the deployments found
+ * @throws PfModelException on errors getting PDP groups
+ */
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
+ throws PfModelException;
+
/**
* Gets the policy deployments for a PDP group.
*
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
return new PdpStatisticsProvider().deletePdpStatistics(pfDao, name, timestamp);
}
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
+ assertInitialized();
+ return new PdpProvider().getAllPolicyStatus(pfDao);
+ }
+
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
+ throws PfModelException {
+ assertInitialized();
+ return new PdpProvider().getAllPolicyStatus(pfDao, policy);
+ }
+
@Override
public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull String groupName)
throws PfModelException {
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
return new ArrayList<>();
}
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
+ throws PfModelException {
+ // Not implemented
+ return new ArrayList<>();
+ }
+
@Override
public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
// Not implemented
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId());
assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
+ assertThat(databaseProvider.getAllPolicyStatus()).isEmpty();
+ assertThat(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null)))
+ .isEmpty();
assertThat(databaseProvider.getGroupPolicyStatus(GROUP)).isEmpty();
assertThatCode(() -> databaseProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException();
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
return null;
}
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
+ // Not implemented
+ return null;
+ }
+
+ @Override
+ public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
+ throws PfModelException {
+ // Not implemented
+ return null;
+ }
+
@Override
public List<PdpPolicyStatus> getGroupPolicyStatus(@NonNull String groupName) throws PfModelException {
// Not implemented
@Override
public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
- // TODO Auto-generated method stub
+ // Not implemented
return null;
}
}
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
assertTrue(dummyProvider.updatePdpStatistics(null).isEmpty());
assertTrue(dummyProvider.deletePdpStatistics(null, new Date()).isEmpty());
+ assertThat(dummyProvider.getAllPolicyStatus()).isEmpty();
+ assertThat(dummyProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null))).isEmpty();
assertThat(dummyProvider.getGroupPolicyStatus("name")).isEmpty();
assertThatCode(() -> dummyProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException();
}