}
/*
- * This is needed to satisfy drools.
+ * This is needed to satisfy drools, thus disabling sonar.
*/
@Override
- public Deque<Step2> getSteps() {
+ public Deque<Step2> getSteps() { // NOSONAR
return super.getSteps();
}
- /**
- * Loads the preprocessor steps needed by the step that's at the front of the queue.
- */
+ @Override
public void loadPreprocessorSteps() {
super.loadPreprocessorSteps();
final Step2 step = getSteps().peek();
// determine if any A&AI queries are needed
- boolean needCq = false;
- boolean needPnf = false;
- boolean needTenant = false;
- boolean needTargetEntity = false;
+ var needCq = false;
+ var needPnf = false;
+ var needTenant = false;
+ var needTargetEntity = false;
for (String propName : step.getPropertyNames()) {
needCq = needCq || CQ_PROPERTIES.contains(propName);
}
}
- /**
- * Determines if the TOSCA should be aborted due to the given outcome.
- *
- * @param outcome outcome to examine
- * @return {@code true} if the TOSCA should be aborted, {@code false} otherwise
- */
+ @Override
public boolean isAbort(OperationOutcome outcome) {
return (super.isAbort(outcome) && ABORT_ACTORS.contains(outcome.getActor()));
}
storeInDataBase(outcome, getProperty(OperationProperties.AAI_TARGET_ENTITY));
}
- /**
- * Makes a control loop response.
- *
- * @param outcome operation outcome
- * @return a new control loop response, or {@code null} if none is required
- */
+ @Override
public ControlLoopResponse makeControlLoopResponse(OperationOutcome outcome) {
- ControlLoopResponse clRsp = super.makeControlLoopResponse(outcome);
+ var clRsp = super.makeControlLoopResponse(outcome);
Object obj = outcome.getResponse();
if (!(obj instanceof PciMessage)) {
return clRsp;
}
- /**
- * Check an event syntax.
- *
- * @param event the event syntax
- * @throws ControlLoopException if an error occurs
- */
+ @Override
protected void checkEventSyntax(VirtualControlLoopEvent event) throws ControlLoopException {
super.checkEventSyntax(event);
validateAaiData(event);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
params.getPayload().put(PAYLOAD_KEY_VNF_ID, targetEntity);
AaiCqResponse cq = this.getCustomQueryData();
- GenericVnf vnf = cq.getGenericVnfByVnfId(targetEntity);
+ var vnf = cq.getGenericVnfByVnfId(targetEntity);
if (vnf == null) {
return;
}
StandardCoderObject tenant = stepContext.getProperty(AaiGetTenantOperation.getKey(vserver));
verifyNotNull("tenant data", tenant);
- String resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
+ var resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
verifyNotNull("tenant data resource-link", resourceLink);
return stripPrefix(resourceLink, 3);
}
protected String getEnrichment(String propName) {
- String enrichmentKey = propName.substring(ENRICHMENT_PREFIX.length());
+ var enrichmentKey = propName.substring(ENRICHMENT_PREFIX.length());
String value = event.getAai().get(enrichmentKey);
verifyNotNull(propName, value);
protected static String stripPrefix(String resourceLink, int ncomponents) {
int previdx = -1;
- for (int nslashes = 0; nslashes < ncomponents; ++nslashes) {
+ for (var nslashes = 0; nslashes < ncomponents; ++nslashes) {
int idx = resourceLink.indexOf('/', previdx + 1);
if (idx < 0) {
break;
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * 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.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
* @return the CoordinationDirective
*/
public static CoordinationDirective loadCoordinationDirectiveFromFile(String directiveFilename) {
- try (InputStream is = new FileInputStream(new File(directiveFilename))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
+ try (var is = new FileInputStream(new File(directiveFilename))) {
+ var contents = IOUtils.toString(is, StandardCharsets.UTF_8);
//
// Read the yaml into our Java Object
//
- Yaml yaml = new Yaml(new Constructor(CoordinationDirective.class));
+ var yaml = new Yaml(new Constructor(CoordinationDirective.class));
Object obj = yaml.load(contents);
logger.debug(contents);
/*
* Values to be used for placeholders
*/
- final String uniqueId = UUID.randomUUID().toString();
+ final var uniqueId = UUID.randomUUID().toString();
final String cLOne = cd.getControlLoop(0);
final String cLTwo = cd.getControlLoop(1);
/*
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ClEventManagerWithEvent(EventManagerServices services, ControlLoopParams params,
+ protected ClEventManagerWithEvent(EventManagerServices services, ControlLoopParams params,
VirtualControlLoopEvent event, WorkingMemory workMem) throws ControlLoopException {
super(services, params, event.getRequestId(), workMem);
@Override
public ControlLoopResponse makeControlLoopResponse(OperationOutcome outcome) {
- ControlLoopResponse clRsp = super.makeControlLoopResponse(outcome);
+ var clRsp = super.makeControlLoopResponse(outcome);
clRsp.setTarget("DCAE");
clRsp.setClosedLoopControlName(event.getClosedLoopControlName());
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ClEventManagerWithOutcome(EventManagerServices services, ControlLoopParams params, UUID requestId,
+ protected ClEventManagerWithOutcome(EventManagerServices services, ControlLoopParams params, UUID requestId,
WorkingMemory workMem) throws ControlLoopException {
super(services, params, requestId, workMem);
}
}
- OperationOutcome2 outcome2 = makeOperationOutcome2(outcome);
+ var outcome2 = makeOperationOutcome2(outcome);
partialHistory.add(outcome2);
fullHistory.add(outcome2);
}
* @return a new notification
*/
public VirtualControlLoopNotification makeNotification() {
- VirtualControlLoopNotification notif = new VirtualControlLoopNotification();
+ var notif = new VirtualControlLoopNotification();
populateNotification(notif);
if (getFinalResult() != null) {
* @return a new control loop response, or {@code null} if none is required
*/
public ControlLoopResponse makeControlLoopResponse(OperationOutcome outcome) {
- ControlLoopResponse clRsp = new ControlLoopResponse();
+ var clRsp = new ControlLoopResponse();
clRsp.setFrom(outcome.getActor());
return clRsp;
import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-import org.onap.policy.drools.domain.models.operational.ActorOperation;
import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.drools.domain.models.operational.OperationalTarget;
import org.onap.policy.drools.system.PolicyEngine;
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ClEventManagerWithSteps(EventManagerServices services, ControlLoopParams params, UUID requestId,
+ protected ClEventManagerWithSteps(EventManagerServices services, ControlLoopParams params, UUID requestId,
WorkingMemory workMem) throws ControlLoopException {
super(services, params, requestId);
policy = getProcessor().getCurrentPolicy();
- ActorOperation actor = policy.getActorOperation();
+ var actor = policy.getActorOperation();
OperationalTarget target = actor.getTarget();
String targetType = (target != null ? target.getTargetType() : null);
int remainingSec = 15 + Math.max(0, (int) TimeUnit.SECONDS.convert(remainingMs, TimeUnit.MILLISECONDS));
LockData data = target2lock.computeIfAbsent(targetEntity, key -> {
- LockData data2 = new LockData(key, requestId);
+ var data2 = new LockData(key, requestId);
makeLock(targetEntity, requestId.toString(), remainingSec, data2);
data2.addUnavailableCallback(this::onComplete);
}
private OperationOutcome makeUnlockOutcome(String targetEntity) {
- OperationOutcome outcome = new OperationOutcome();
+ var outcome = new OperationOutcome();
outcome.setActor(ActorConstants.LOCK_ACTOR);
outcome.setOperation(ActorConstants.UNLOCK_OPERATION);
outcome.setTarget(targetEntity);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
*/
public Properties startActorService(String configFileName) {
try {
- Properties props = SystemPersistenceConstants.getManager().getProperties(configFileName);
+ var props = SystemPersistenceConstants.getManager().getProperties(configFileName);
Map<String, Object> parameters = PropertyObjectUtils.toObject(props, ACTOR_SERVICE_PROPERTIES);
PropertyObjectUtils.compressLists(parameters);
throw new IllegalArgumentException("invalid data manager properties:\n" + result.getResult());
}
- OperationHistoryDataManagerImpl mgr = new OperationHistoryDataManagerImpl(params);
+ var mgr = new OperationHistoryDataManagerImpl(params);
mgr.start();
return mgr;
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
* @return a new lock operation outcome
*/
private OperationOutcome makeOutcome() {
- OperationOutcome outcome = new OperationOutcome();
+ var outcome = new OperationOutcome();
outcome.setActor(ActorConstants.LOCK_ACTOR);
outcome.setOperation(ActorConstants.LOCK_OPERATION);
outcome.setTarget(targetEntity);
this.batchSize = params.getBatchSize();
// create the factory using the properties
- Properties props = toProperties(params);
+ var props = toProperties(params);
this.emFactory = makeEntityManagerFactory(params.getPersistenceUnit(), props);
}
private void storeBatch(EntityManager entityManager, Record firstRecord) {
logger.info("store operation history record batch");
- try (EntityMgrCloser emc = new EntityMgrCloser(entityManager);
- EntityTransCloser trans = new EntityTransCloser(entityManager.getTransaction())) {
+ try (var emc = new EntityMgrCloser(entityManager);
+ var trans = new EntityTransCloser(entityManager.getTransaction())) {
- int nrecords = 0;
- Record record = firstRecord;
+ var nrecords = 0;
+ var rec = firstRecord;
- while (record != null && record != END_MARKER) {
- storeRecord(entityManager, record);
+ while (rec != null && rec != END_MARKER) {
+ storeRecord(entityManager, rec);
if (++nrecords >= batchSize) {
break;
}
- record = operations.poll();
+ rec = operations.poll();
}
trans.commit();
* Stores a record.
*
* @param entityManager entity manager
- * @param record record to be stored
+ * @param rec record to be stored
*/
- private void storeRecord(EntityManager entityMgr, Record record) {
+ private void storeRecord(EntityManager entityMgr, Record rec) {
- final String reqId = record.getRequestId();
- final String clName = record.getClName();
- final ControlLoopOperation operation = record.getOperation();
+ final String reqId = rec.getRequestId();
+ final String clName = rec.getClName();
+ final ControlLoopOperation operation = rec.getOperation();
logger.info("store operation history record for {}", reqId);
.createQuery("select e from OperationsHistory e" + " where e.closedLoopName= ?1"
+ " and e.requestId= ?2" + " and e.subrequestId= ?3" + " and e.actor= ?4"
+ " and e.operation= ?5" + " and e.target= ?6", OperationsHistory.class)
- .setParameter(1, clName).setParameter(2, record.getRequestId())
+ .setParameter(1, clName).setParameter(2, rec.getRequestId())
.setParameter(3, operation.getSubRequestId()).setParameter(4, operation.getActor())
- .setParameter(5, operation.getOperation()).setParameter(6, record.getTargetEntity())
+ .setParameter(5, operation.getOperation()).setParameter(6, rec.getTargetEntity())
.getResultList();
if (results.size() > 1) {
OperationsHistory entry = (results.isEmpty() ? new OperationsHistory() : results.get(0));
entry.setClosedLoopName(clName);
- entry.setRequestId(record.getRequestId());
+ entry.setRequestId(rec.getRequestId());
entry.setActor(operation.getActor());
entry.setOperation(operation.getOperation());
- entry.setTarget(record.getTargetEntity());
+ entry.setTarget(rec.getTargetEntity());
entry.setSubrequestId(operation.getSubRequestId());
entry.setMessage(operation.getMessage());
entry.setOutcome(operation.getOutcome());
* @return a new property set
*/
private Properties toProperties(OperationHistoryDataManagerParams params) {
- Properties props = new Properties();
+ var props = new Properties();
props.put(PersistenceUnitProperties.JDBC_DRIVER, params.getDriver());
props.put(PersistenceUnitProperties.JDBC_URL, params.getUrl());
props.put(PersistenceUnitProperties.JDBC_USER, params.getUserName());
* Get ControlLoopParams.
*/
public ControlLoopParams getControlLoopParams() {
- ControlLoopParams controlLoopParams = new ControlLoopParams();
+ var controlLoopParams = new ControlLoopParams();
controlLoopParams.setClosedLoopControlName(this.policy.getProperties().getId());
controlLoopParams.setPolicyScope(policy.getType() + ":" + policy.getTypeVersion());
return controller.getDrools()
.facts(sessionName, ControlLoopParams.class.getName(), false)
.stream()
- .filter(c -> c instanceof ControlLoopParams)
+ .filter(ControlLoopParams.class::isInstance)
.map(ControlLoopParams.class::cast);
}
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
import org.onap.policy.aai.AaiManager;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.drools.apps.controlloop.feature.management.ControlLoopManagementFeature;
-import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.rest.RestManager;
import org.slf4j.Logger;
@Path("engine/tools/controlloops/aai/customQuery/{vserverId}")
@ApiOperation(value = "AAI Custom Query")
public Response aaiCustomQuery(@ApiParam(value = "vserver Identifier") String vserverId) {
- PolicyEngine mgr = PolicyEngineConstants.getManager();
+ var mgr = PolicyEngineConstants.getManager();
return Response
.status(Status.OK)
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.commons.collections4.CollectionUtils;
public CacheBasedControlLoopMetricsManager() {
- Properties properties = SystemPersistenceConstants.getManager()
+ var properties = SystemPersistenceConstants.getManager()
.getProperties(ControlLoopMetricsFeature.CONFIGURATION_PROPERTIES_NAME);
/* cache size */
}
protected void metric(VirtualControlLoopNotification notification) {
- MdcTransaction trans = getMdcTransaction(notification);
+ var trans = getMdcTransaction(notification);
List<ControlLoopOperation> operations = notification.getHistory();
switch (notification.getNotification()) {
case ACTIVE:
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
waitForLockAndPermit(policy, policyClMgt);
// restart request should be sent and fail four times (i.e., because retry=3)
- for (int count = 0; count < 4; ++count) {
+ for (var count = 0; count < 4; ++count) {
AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
topics.inject(DCAE_TOPIC, DUPLICATES_ONSET_1, UUID.randomUUID().toString());
// should see two restarts
- for (int count = 0; count < 2; ++count) {
+ for (var count = 0; count < 2; ++count) {
AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
// indicate success
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
package org.onap.policy.controlloop.common.rules.test;
import org.junit.Ignore;
-import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
- Description description = describeChild(method);
+ var description = describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
pdpdRepo.setConfigurationDir("src/test/resources/config");
try {
- File kmoduleFile = new File(resourceDir + "/META-INF/kmodule.xml");
- File pomFile = new File("src/test/resources/" + controllerName + ".pom");
- String resourceDir2 = resourceDir + "/org/onap/policy/controlloop/";
- File ruleFile = new File(resourceDir + File.separator + controllerName + ".drl");
+ var kmoduleFile = new File(resourceDir + "/META-INF/kmodule.xml");
+ var pomFile = new File("src/test/resources/" + controllerName + ".pom");
+ var resourceDir2 = resourceDir + "/org/onap/policy/controlloop/";
+ var ruleFile = new File(resourceDir + File.separator + controllerName + ".drl");
List<File> ruleFiles = Collections.singletonList(ruleFile);
installArtifact(kmoduleFile, pomFile, resourceDir2, ruleFiles);
}
private ToscaPolicy getPolicyFromTemplate(String resourcePath, String policyName) throws CoderException {
- String policyJson = ResourceUtils.getResourceAsString(resourcePath);
+ var policyJson = ResourceUtils.getResourceAsString(resourcePath);
if (policyJson == null) {
throw new CoderException(new FileNotFoundException(resourcePath));
}
* Get policy from file.
*/
public static ToscaPolicy getPolicyFromFile(String policyPath) throws CoderException {
- String policyJson = ResourceUtils.getResourceAsString(policyPath);
+ var policyJson = ResourceUtils.getResourceAsString(policyPath);
if (policyJson == null) {
throw new CoderException(new FileNotFoundException(policyPath));
}
* Sets up Drools Logging for events of interest.
*/
private void setupDroolsLogging() {
- KieSession session = getKieSession();
+ var session = getKieSession();
session.addEventListener(new RuleListenerLogger());
session.addEventListener(new AgendaListenerLogger());
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
*/
public void inject(String topicName, String file, String newText) {
try {
- String text = ResourceUtils.getResourceAsString(file);
+ var text = ResourceUtils.getResourceAsString(file);
if (text == null) {
throw new FileNotFoundException(file);
}