/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * Modifications Copyright 2023 Nordix Foundation.
* ================================================================================
* 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.models.simulators;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import lombok.AccessLevel;
import lombok.Getter;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
import org.onap.policy.models.sim.dmaap.provider.DmaapSimProvider;
import org.onap.policy.models.sim.dmaap.rest.CambriaMessageBodyHandler;
import org.onap.policy.models.sim.dmaap.rest.TextMessageBodyHandler;
+import org.onap.policy.simulators.CdsSimulator;
import org.onap.policy.simulators.TopicServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
DmaapSimParameterGroup dmaapProv = params.getDmaapProvider();
- String dmaapName = dmaapProv.getName();
- String provName = dmaapName.replace("simulator", "provider");
+ String dmaapName = (dmaapProv != null ? dmaapProv.getName() : null);
// dmaap provider
- AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
- addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
+ if (dmaapProv != null) {
+ String provName = dmaapName.replace("simulator", "provider");
+ AtomicReference<DmaapSimProvider> provRef = new AtomicReference<>();
+ addAction(provName, () -> provRef.set(buildDmaapProvider(dmaapProv)), () -> provRef.get().shutdown());
+ }
+
+ CdsServerParameters cdsServer = params.getGrpcServer();
+
+ // Cds Simulator
+ if (cdsServer != null) {
+ AtomicReference<CdsSimulator> cdsSim = new AtomicReference<>();
+ addAction(cdsServer.getName(), () -> cdsSim.set(buildCdsSimulator(cdsServer)), () -> cdsSim.get().stop());
+ }
// REST server simulators
// @formatter:off
for (ClassRestServerParameters restsim : params.getRestServers()) {
AtomicReference<HttpServletServer> ref = new AtomicReference<>();
+ if (StringUtils.isNotBlank(restsim.getResourceLocation())) {
+ String resourceLocationId = restsim.getProviderClass() + "_RESOURCE_LOCATION";
+ addAction(resourceLocationId,
+ () -> Registry.register(resourceLocationId, restsim.getResourceLocation()),
+ () -> Registry.unregister(resourceLocationId));
+ }
addAction(restsim.getName(),
() -> ref.set(buildRestServer(dmaapName, restsim)),
() -> ref.get().shutdown());
}
/**
- * The main method.
+ * The main method. The arguments are validated, thus adding the NOSONAR.
*
* @param args the arguments, the first of which is the name of the parameter file
*/
- public static void main(final String[] args) {
+ public static void main(final String[] args) { // NOSONAR
+ /*
+ * Only one argument is used and is validated implicitly by the constructor (i.e.,
+ * file-not-found), thus sonar is disabled.
+ */
+
try {
if (args.length != 1) {
throw new IllegalArgumentException("arg(s): parameter-file-name");
private SimulatorParameters readParameters(String paramFile) {
try {
- String paramsJson = getResourceAsString(paramFile);
+ var paramsJson = getResourceAsString(paramFile);
if (paramsJson == null) {
throw new IllegalArgumentException(new FileNotFoundException(paramFile));
}
}
private DmaapSimProvider buildDmaapProvider(DmaapSimParameterGroup params) {
- DmaapSimProvider prov = new DmaapSimProvider(params);
+ var prov = new DmaapSimProvider(params);
DmaapSimProvider.setInstance(prov);
prov.start();
-
return prov;
}
+ private CdsSimulator buildCdsSimulator(CdsServerParameters params) throws IOException {
+ var cdsSimulator = new CdsSimulator(params.getHost(), params.getPort(), params.getResourceLocation(),
+ params.getSuccessRepeatCount(), params.getRequestedResponseDelayMs());
+ cdsSimulator.start();
+ return cdsSimulator;
+ }
+
+
private TopicSink startSink(TopicParameters params) {
TopicSink sink = TopicEndpointManager.getManager().addTopicSinks(List.of(params)).get(0);
sink.start();
private HttpServletServer buildRestServer(String dmaapName, ClassRestServerParameters params) {
try {
- Properties props = getServerProperties(dmaapName, params);
+ var props = getServerProperties(dmaapName, params);
HttpServletServer testServer = makeServer(props);
testServer.waitedStart(5000);
* @return a set of properties representing the given parameters
*/
private static Properties getServerProperties(String dmaapName, ClassRestServerParameters params) {
- final Properties props = new Properties();
+ final var props = new Properties();
props.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, params.getName());
final String svcpfx = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + params.getName();
params.getProviderClass());
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "false");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SWAGGER_SUFFIX, "false");
+ props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SNI_HOST_CHECK_SUFFIX, "false");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
- if (dmaapName.equals(params.getName())) {
+ if (dmaapName != null && dmaapName.equals(params.getName())) {
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
String.join(",", CambriaMessageBodyHandler.class.getName(),
GsonMessageBodyHandler.class.getName(),