diff options
author | Patrick Brady <pb071s@att.com> | 2017-06-01 10:45:37 -0700 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-06-02 13:05:15 -0700 |
commit | c7d0075d223eab9f89fd28853c4b138792059be9 (patch) | |
tree | 40aa3e41e598ea7a59bcf6899a2004c1abab11c2 /appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main | |
parent | 8aac2df744820304ee29354333661699e9695939 (diff) |
Merge of new rebased code
Change-Id: I9b8d1f69eb3e0af1935ed8304fea4bf54c1aac47
Signed-off-by: Patrick Brady <pb071s@att.com>
Diffstat (limited to 'appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main')
12 files changed, 398 insertions, 96 deletions
diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/messageadapter/impl/MessageAdapterDmaapImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/messageadapter/impl/MessageAdapterImpl.java index 21c21db93..676c62871 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/messageadapter/impl/MessageAdapterDmaapImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/messageadapter/impl/MessageAdapterImpl.java @@ -21,26 +21,33 @@ package org.openecomp.appc.messageadapter.impl; -import java.util.HashSet; -import java.util.Properties; -import org.apache.commons.lang.ObjectUtils; -import org.openecomp.appc.adapter.dmaap.Producer; -import org.openecomp.appc.adapter.dmaap.DmaapProducer; +import org.openecomp.appc.adapter.factory.DmaapMessageAdapterFactoryImpl; +import org.openecomp.appc.adapter.factory.MessageService; +import org.openecomp.appc.adapter.message.MessageAdapterFactory; +import org.openecomp.appc.adapter.message.Producer; import org.openecomp.appc.configuration.Configuration; import org.openecomp.appc.configuration.ConfigurationFactory; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang.ObjectUtils; import org.openecomp.appc.domainmodel.lcm.ResponseContext; import org.openecomp.appc.domainmodel.lcm.VNFOperation; import org.openecomp.appc.messageadapter.MessageAdapter; import org.openecomp.appc.requesthandler.conv.Converter; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; -import com.fasterxml.jackson.core.JsonProcessingException; +import java.util.HashSet; +import java.util.Properties; -public class MessageAdapterDmaapImpl implements MessageAdapter{ +public class MessageAdapterImpl implements MessageAdapter{ - private Producer dmaapProducer; + private MessageService messageService; + private Producer producer; private String partition ; private Configuration configuration; private HashSet<String> pool; @@ -48,21 +55,28 @@ public class MessageAdapterDmaapImpl implements MessageAdapter{ private String apiKey; private String apiSecret; - private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterDmaapImpl.class); + private static final EELFLogger logger = EELFManager.getInstance().getLogger(MessageAdapterImpl.class); /** - * Initialize dmaapProducer client to post messages using configuration properties + * Initialize producer client to post messages using configuration properties */ @Override public void init(){ - this.dmaapProducer = getDmaapProducer(); + this.producer = getProducer(); } - private Producer getDmaapProducer() { + + private Producer getProducer() { configuration = ConfigurationFactory.getConfiguration(); Properties properties=configuration.getProperties(); updateProperties(properties); - Producer producer=new DmaapProducer(pool,writeTopic); - producer.updateCredentials(apiKey, apiSecret); + + BundleContext ctx = FrameworkUtil.getBundle(MessageAdapterImpl.class).getBundleContext(); + if (ctx != null) { + ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName()); + if (svcRef != null) { + producer = ((MessageAdapterFactory) ctx.getService(svcRef)).createProducer(pool, writeTopic,apiKey, apiSecret); + } + } return producer; } @@ -73,10 +87,13 @@ public class MessageAdapterDmaapImpl implements MessageAdapter{ } pool = new HashSet<>(); if (props != null) { - writeTopic = props.getProperty("dmaap.topic.write"); - apiKey = props.getProperty("dmaap.client.key"); - apiSecret = props.getProperty("dmaap.client.secret"); - String hostnames = props.getProperty("dmaap.poolMembers"); + // readTopic = props.getProperty("dmaap.topic.read"); + writeTopic = props.getProperty("appc.LCM.topic.write"); + apiKey = props.getProperty("appc.LCM.client.key"); + apiSecret = props.getProperty("appc.LCM.client.secret"); + messageService = MessageService.parse(props.getProperty("message.service.type")); + // READ_TIMEOUT = Integer.valueOf(props.getProperty("dmaap.topic.read.timeout", String.valueOf(READ_TIMEOUT))); + String hostnames = props.getProperty("appc.LCM.poolMembers"); if (hostnames != null && !hostnames.isEmpty()) { for (String name : hostnames.split(",")) { pool.add(name); @@ -103,9 +120,9 @@ public class MessageAdapterDmaapImpl implements MessageAdapter{ if (logger.isDebugEnabled()) { logger.debug("DMaaP Response = " + jsonMessage); } - success = dmaapProducer.post(this.partition, jsonMessage); + success = producer.post(this.partition, jsonMessage); } catch (JsonProcessingException e1) { - logger.error("Error generating Jason from DMaaP message "+ e1.getMessage()); + logger.error("Error generating Json from DMaaP message "+ e1.getMessage()); success= false; }catch (Exception e){ logger.error("Error sending message to DMaaP "+e.getMessage()); diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java index 3513516ae..272e02bca 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/conv/Converter.java @@ -21,38 +21,6 @@ package org.openecomp.appc.requesthandler.conv; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; - -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.Action; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.AuditOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.HealthCheckOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.LiveUpgradeOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.LockOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.ModifyConfigOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.Payload; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.RollbackOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.SnapshotOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.SoftwareUploadOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.StopOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.SyncOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.TerminateOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.TestOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.UnlockOutputBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.ZULU; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.CommonHeader; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.CommonHeaderBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.FlagsBuilder; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.status.Status; -import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.status.StatusBuilder; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataContainer; -import org.openecomp.appc.domainmodel.lcm.ResponseContext; -import org.openecomp.appc.domainmodel.lcm.VNFOperation; -import org.openecomp.appc.requesthandler.impl.DmaapOutgoingMessage; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -65,6 +33,23 @@ import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.*; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.CommonHeaderBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.FlagsBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.status.Status; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.status.StatusBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.openecomp.appc.domainmodel.lcm.ResponseContext; +import org.openecomp.appc.domainmodel.lcm.VNFOperation; +import org.openecomp.appc.requesthandler.impl.DmaapOutgoingMessage; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; public class Converter { @@ -90,6 +75,7 @@ public class Converter { Action action = Action.valueOf(vnfOperation.name()); CommonHeader commonHeader = convAsyncResponseTorev160108CommonHeader(response); Status status = convAsyncResponseTorev160108Status(response); + Payload payload = convAsyncResponseTorev160108Payload(response); switch (action){ case Rollback: outObj = new RollbackOutputBuilder(); @@ -110,6 +96,7 @@ public class Converter { outObj = new AuditOutputBuilder(); ((AuditOutputBuilder)outObj).setCommonHeader(commonHeader); ((AuditOutputBuilder)outObj).setStatus(status); + ((AuditOutputBuilder)outObj).setPayload(payload); return outObj; case HealthCheck: outObj = new HealthCheckOutputBuilder(); @@ -126,10 +113,29 @@ public class Converter { ((LockOutputBuilder)outObj).setCommonHeader(commonHeader); ((LockOutputBuilder)outObj).setStatus(status); return outObj; - case ModifyConfig: - outObj = new ModifyConfigOutputBuilder(); - ((ModifyConfigOutputBuilder)outObj).setCommonHeader(commonHeader); - ((ModifyConfigOutputBuilder)outObj).setStatus(status); + case Configure: + outObj = new ConfigureOutputBuilder(); + ((ConfigureOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigureOutputBuilder)outObj).setStatus(status); + ((ConfigureOutputBuilder)outObj).setPayload(payload); + return outObj; + case ConfigModify: + outObj = new ConfigModifyOutputBuilder(); + ((ConfigModifyOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigModifyOutputBuilder)outObj).setStatus(status); + ((ConfigModifyOutputBuilder)outObj).setPayload(payload); + return outObj; + case ConfigScaleOut: + outObj = new ConfigScaleoutOutputBuilder(); + ((ConfigScaleoutOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigScaleoutOutputBuilder)outObj).setStatus(status); + ((ConfigScaleoutOutputBuilder)outObj).setPayload(payload); + return outObj; + case ConfigRestore: + outObj = new ConfigRestoreOutputBuilder(); + ((ConfigRestoreOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigRestoreOutputBuilder)outObj).setStatus(status); + ((ConfigRestoreOutputBuilder)outObj).setPayload(payload); return outObj; case SoftwareUpload: outObj = new SoftwareUploadOutputBuilder(); @@ -145,6 +151,7 @@ public class Converter { outObj = new SyncOutputBuilder(); ((SyncOutputBuilder)outObj).setCommonHeader(commonHeader); ((SyncOutputBuilder)outObj).setStatus(status); + ((SyncOutputBuilder)outObj).setPayload(payload); return outObj; case Terminate: outObj = new TerminateOutputBuilder(); @@ -161,12 +168,54 @@ public class Converter { ((UnlockOutputBuilder)outObj).setCommonHeader(commonHeader); ((UnlockOutputBuilder)outObj).setStatus(status); return outObj; + case Restart: + outObj = new RestartOutputBuilder(); + ((RestartOutputBuilder)outObj).setCommonHeader(commonHeader); + ((RestartOutputBuilder)outObj).setStatus(status); + return outObj; + case Rebuild: + outObj = new RebuildOutputBuilder(); + ((RebuildOutputBuilder)outObj).setCommonHeader(commonHeader); + ((RebuildOutputBuilder)outObj).setStatus(status); + return outObj; + case Migrate: + outObj = new MigrateOutputBuilder(); + ((MigrateOutputBuilder)outObj).setCommonHeader(commonHeader); + ((MigrateOutputBuilder)outObj).setStatus(status); + return outObj; + case Evacuate: + outObj = new EvacuateOutputBuilder(); + ((EvacuateOutputBuilder)outObj).setCommonHeader(commonHeader); + ((EvacuateOutputBuilder)outObj).setStatus(status); + return outObj; + case ConfigBackup: + outObj = new ConfigBackupOutputBuilder(); + ((ConfigBackupOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigBackupOutputBuilder)outObj).setStatus(status); + ((ConfigBackupOutputBuilder)outObj).setPayload(payload); + return outObj; + case ConfigBackupDelete: + outObj = new ConfigBackupDeleteOutputBuilder(); + ((ConfigBackupDeleteOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigBackupDeleteOutputBuilder)outObj).setStatus(status); + ((ConfigBackupDeleteOutputBuilder)outObj).setPayload(payload); + return outObj; + case ConfigExport: + outObj = new ConfigExportOutputBuilder(); + ((ConfigExportOutputBuilder)outObj).setCommonHeader(commonHeader); + ((ConfigExportOutputBuilder)outObj).setStatus(status); + return outObj; + case Start: + outObj = new StartOutputBuilder(); + ((StartOutputBuilder)outObj).setCommonHeader(commonHeader); + ((StartOutputBuilder)outObj).setStatus(status); + return outObj; default: throw new IllegalArgumentException(action+" action is not supported"); } } - public static Payload convAsyncResponseTorev160108Payload(ResponseContext inObj) throws ParseException { + public static Payload convAsyncResponseTorev160108Payload(ResponseContext inObj) { Payload payload = null; if(inObj.getPayload() != null) { payload = new Payload(inObj.getPayload()); @@ -208,7 +257,7 @@ public class Converter { } CommonHeaderBuilder commonHeaderBuilder = new CommonHeaderBuilder(); - org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags commonHeaderFlags = null; + org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags commonHeaderFlags = null; if(inObj.getCommonHeader().getFlags() != null){ commonHeaderFlags = Converter.convFlagsMapTorev160108Flags(inObj.getCommonHeader().getFlags()); commonHeaderBuilder.setFlags(commonHeaderFlags); @@ -239,7 +288,7 @@ public class Converter { return isoFormatter.format(timeStamp); } - public static org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags + public static org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags convFlagsMapTorev160108Flags(org.openecomp.appc.domainmodel.lcm.Flags flags) { Flags rev160108flags = null; boolean anyFlag = false; @@ -249,14 +298,14 @@ public class Converter { */ /* if(flags.containsKey(FORCE_FLAG)){ - org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags.Force force = - org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags.Force.valueOf(flags.get(FORCE_FLAG).toString()); + org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags.Force force = + org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags.Force.valueOf(flags.get(FORCE_FLAG).toString()); flagsBuilder.setForce(force); anyFlag = true; } if(flags.containsKey(MODE_FLAG)){ - org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags.Mode mode = - org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160108.common.header.common.header.Flags.Mode.valueOf(flags.get(MODE_FLAG).toString()); + org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags.Mode mode = + org.opendaylight.yang.gen.v1.org.openecomp.appc.lcm.rev160108.common.header.common.header.Flags.Mode.valueOf(flags.get(MODE_FLAG).toString()); flagsBuilder.setMode(mode); anyFlag = true; } @@ -307,6 +356,9 @@ public class Converter { public static DmaapOutgoingMessage convAsyncResponseToDmaapOutgoingMessage(VNFOperation vnfOperation, String rpcName, ResponseContext asyncResponse) throws JsonProcessingException { DmaapOutgoingMessage outObj = new DmaapOutgoingMessage(); + String correlationID = getCorrelationID(asyncResponse); + outObj.setCorrelationID(correlationID); + outObj.setType("response"); outObj.setRpcName(rpcName); Builder<?> builder = Converter.convAsyncResponseToBuilder(vnfOperation, rpcName, asyncResponse); Object messageBody = builder.build(); @@ -315,6 +367,12 @@ public class Converter { return outObj; } + private static String getCorrelationID(ResponseContext context) { + return context.getCommonHeader().getRequestId() + + (context.getCommonHeader().getSubRequestId() == null ? + "":"-" + context.getCommonHeader().getSubRequestId()); + } + abstract class MixIn { @JsonIgnore abstract Class<? extends DataContainer> getImplementedInterface(); // to be removed during serialization diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/exceptions/LCMOperationsDisabledException.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/exceptions/LCMOperationsDisabledException.java new file mode 100644 index 000000000..c067f303f --- /dev/null +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/exceptions/LCMOperationsDisabledException.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.requesthandler.exceptions; + +/** + */ +public class LCMOperationsDisabledException extends Exception { + + /** + * Constructs a new exception with the specified detail message. + * + * @param message the detail message. + */ + public LCMOperationsDisabledException(String message) { + super(message); + } +} diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/exceptions/MissingVNFDataInAAIException.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/exceptions/MissingVNFDataInAAIException.java new file mode 100644 index 000000000..7ffdb3801 --- /dev/null +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/exceptions/MissingVNFDataInAAIException.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.requesthandler.exceptions; + +public class MissingVNFDataInAAIException extends Exception { + String missingAttributeName; + public MissingVNFDataInAAIException(String attributeName) { + this.missingAttributeName = attributeName; + } + + public String getMissingAttributeName() { + return missingAttributeName; + } +} diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestRegistry.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestRegistry.java index 874626c78..e51d4b978 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestRegistry.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestRegistry.java @@ -76,4 +76,15 @@ public class RequestRegistry { set.remove(requestIdentifier); } + /** + * This method returns the count of currently registered requests + * in the request registry + * * @return currently registered requests count + */ + public int getRegisteredRequestCount() { + if (logger.isTraceEnabled()) { + logger.trace("Entering to getRegisteredRequestCount"); + } + return set.size(); + } } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestValidator.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestValidator.java index 4f2986d74..a4a2beee5 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestValidator.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/helper/RequestValidator.java @@ -28,10 +28,12 @@ import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException; import org.openecomp.appc.requesthandler.exceptions.DGWorkflowNotFoundException; import org.openecomp.appc.requesthandler.exceptions.DuplicateRequestException; import org.openecomp.appc.requesthandler.exceptions.InvalidInputException; +import org.openecomp.appc.requesthandler.exceptions.LCMOperationsDisabledException; +import org.openecomp.appc.requesthandler.exceptions.MissingVNFDataInAAIException; import org.openecomp.appc.requesthandler.exceptions.RequestExpiredException; import org.openecomp.appc.requesthandler.exceptions.VNFNotFoundException; import org.openecomp.appc.requesthandler.exceptions.WorkflowNotFoundException; public interface RequestValidator { - public void validateRequest(RuntimeContext runtimeContext) throws VNFNotFoundException, RequestExpiredException, UnstableVNFException, InvalidInputException, DuplicateRequestException, NoTransitionDefinedException, LifecycleException, WorkflowNotFoundException,DGWorkflowNotFoundException; + public void validateRequest(RuntimeContext runtimeContext) throws VNFNotFoundException, RequestExpiredException, UnstableVNFException, InvalidInputException, DuplicateRequestException, NoTransitionDefinedException, LifecycleException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException; } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/DmaapOutgoingMessage.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/DmaapOutgoingMessage.java index 4546726e9..c2455a3b4 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/DmaapOutgoingMessage.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/DmaapOutgoingMessage.java @@ -36,6 +36,15 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; @JsonIgnoreProperties(ignoreUnknown = true) public class DmaapOutgoingMessage { + @JsonProperty("version") + private String version; + + @JsonProperty("type") + private String type; + + @JsonProperty("correlation-id") + private String correlationID; + private final static String defaultCambriaPartition = "MSO"; @JsonProperty("cambria.partition") private String cambriaPartition = defaultCambriaPartition; @@ -49,6 +58,30 @@ public class DmaapOutgoingMessage { public DmaapOutgoingMessage() { } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getCorrelationID() { + return correlationID; + } + + public void setCorrelationID(String correlationID) { + this.correlationID = correlationID; + } + public String getCambriaPartition() { return cambriaPartition; } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/LCMStateManagerImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/LCMStateManagerImpl.java new file mode 100644 index 000000000..0c97ebcbe --- /dev/null +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/LCMStateManagerImpl.java @@ -0,0 +1,62 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.requesthandler.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.openecomp.appc.requesthandler.LCMStateManager; + +public class LCMStateManagerImpl implements LCMStateManager { + private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMStateManagerImpl.class); + private static AtomicBoolean isLCMEnabled = new AtomicBoolean(true); + + /** + * This method checks if the LCM operations are enabled or not + * * @return true if enabled else false + */ + public boolean isLCMOperationEnabled() { + return isLCMEnabled.get(); + } + + /** + * This method disables the LCM operations + */ + public void disableLCMOperations() { + if (logger.isTraceEnabled()) { + logger.trace("Entering to disableLCMOperations"); + } + isLCMEnabled.set(false); + } + + /** + * This method enables the LCM operations + */ + public void enableLCMOperations() { + if (logger.isTraceEnabled()) { + logger.trace("Entering to enableLCMOperations"); + } + isLCMEnabled.set(true); + } +} diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java index d63cb8bb8..e6f7452c9 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestHandlerImpl.java @@ -40,7 +40,7 @@ import org.openecomp.appc.lockmanager.api.LockManager; import org.openecomp.appc.logging.LoggingConstants; import org.openecomp.appc.logging.LoggingUtils; import org.openecomp.appc.messageadapter.MessageAdapter; -import org.openecomp.appc.messageadapter.impl.MessageAdapterDmaapImpl; +import org.openecomp.appc.messageadapter.impl.MessageAdapterImpl; import org.openecomp.appc.metricservice.MetricRegistry; import org.openecomp.appc.metricservice.MetricService; import org.openecomp.appc.metricservice.metric.DispatchingFuntionMetric; @@ -133,7 +133,7 @@ public class RequestHandlerImpl implements RequestHandler { public RequestHandlerImpl() { requestRegistry = new RequestRegistry(); - messageAdapter = new MessageAdapterDmaapImpl(); + messageAdapter = new MessageAdapterImpl(); messageAdapter.init(); Properties properties = configuration.getProperties(); if (properties != null && properties.getProperty("metric.enabled") != null) { @@ -215,7 +215,7 @@ public class RequestHandlerImpl implements RequestHandler { } catch (LifecycleException e) { errorMessage = e.getMessage(); params = new Params().addParam("actionName", input.getRequestContext().getAction()).addParam("currentState", e.currentState); - output = buildRequestHandlerOutput(LCMCommandStatus.ACTION_NOT_SUPPORTED, params); + output = buildRequestHandlerOutput(LCMCommandStatus.INVALID_VNF_STATE, params); } catch (UnstableVNFException e) { errorMessage = e.getMessage(); params = new Params().addParam("vnfId", vnfId); @@ -246,6 +246,15 @@ public class RequestHandlerImpl implements RequestHandler { } catch (DuplicateRequestException e) { errorMessage = e.getMessage(); output = buildRequestHandlerOutput(LCMCommandStatus.DUPLICATE_REQUEST, null); + } catch (MissingVNFDataInAAIException e) { + params = new Params().addParam("attributeName",e.getMissingAttributeName()) + .addParam("vnfId",vnfId); + output = buildRequestHandlerOutput(LCMCommandStatus.MISSING_VNF_DATA_IN_AAI,params); + errorMessage = output.getResponseContext().getStatus().getMessage(); + } catch (LCMOperationsDisabledException e) { + errorMessage = e.getMessage(); + params = new Params().addParam("errorMsg", errorMessage); + output = buildRequestHandlerOutput(LCMCommandStatus.REJECTED, params); } catch (Exception e) { storeErrorMessageToLog(runtimeContext, "", "", "Exception = " + e.getMessage()); errorMessage = e.getMessage() != null ? e.getMessage() : e.toString(); @@ -261,7 +270,11 @@ public class RequestHandlerImpl implements RequestHandler { runtimeContext.setResponseContext(output.getResponseContext()); if ((null == output) || !(output.getResponseContext().getStatus().getCode() == LCMCommandStatus.ACCEPTED.getResponseCode())) { if (isMetricEnabled) { - ((DispatchingFuntionMetric) metricRegistry.metric("DISPATCH_FUNCTION")).incrementRejectedRequest(); + if((output.getResponseContext().getStatus().getCode() == LCMCommandStatus.SUCCESS.getResponseCode())) { + ((DispatchingFuntionMetric) metricRegistry.metric("DISPATCH_FUNCTION")).incrementAcceptedRequest(); + }else { + ((DispatchingFuntionMetric) metricRegistry.metric("DISPATCH_FUNCTION")).incrementRejectedRequest(); + } } removeRequestFromRegistry(input.getRequestContext().getCommonHeader()); } @@ -580,14 +593,18 @@ public class RequestHandlerImpl implements RequestHandler { if (logger.isTraceEnabled()) { logger.trace("Entering to onRequestExecutionStart with vnfId = " + vnfId + "and requestIdentifierString = " + requestIdentifierString); } - try { - boolean updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, requestIdentifierString, forceFlag); + + if(!readOnlyActivity || !forceFlag || workingStateManager.isVNFStable(vnfId)) { + boolean updated = false; + try { + updated = workingStateManager.setWorkingState(vnfId, VNFWorkingState.UNSTABLE, requestIdentifierString, forceFlag); + } catch (Exception e) { + logger.error("Error updating working state for vnf " + vnfId + e); + throw new RuntimeException(e); + } if (!updated) { throw new UnstableVNFException("VNF is not stable for vnfID = " + vnfId); } - } catch (Exception e) { - logger.error("Error updating working state for vnf " + vnfId + e); - throw new RuntimeException(e); } if (logger.isTraceEnabled()) @@ -805,4 +822,16 @@ public class RequestHandlerImpl implements RequestHandler { return null; } } + + /** + * This method returns the count of in progress requests + * * @return in progress requests count + */ + @Override + public int getInprogressRequestCount() { + if (logger.isTraceEnabled()) { + logger.trace("Entering to getInprogressRequestCount"); + } + return requestRegistry.getRegisteredRequestCount(); + } } diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java index 509c351ea..8499937c7 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/openecomp/appc/requesthandler/impl/RequestValidatorImpl.java @@ -24,6 +24,7 @@ package org.openecomp.appc.requesthandler.impl; import java.time.Instant; import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; import org.openecomp.appc.common.constant.Constants; import org.openecomp.appc.configuration.Configuration; import org.openecomp.appc.configuration.ConfigurationFactory; @@ -40,6 +41,8 @@ import org.openecomp.appc.lifecyclemanager.objects.LifecycleException; import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException; import org.openecomp.appc.logging.LoggingConstants; import org.openecomp.appc.logging.LoggingUtils; +import org.openecomp.appc.requesthandler.LCMStateManager; +import org.openecomp.appc.requesthandler.exceptions.*; import org.openecomp.appc.requesthandler.exceptions.DGWorkflowNotFoundException; import org.openecomp.appc.requesthandler.exceptions.DuplicateRequestException; import org.openecomp.appc.requesthandler.exceptions.InvalidInputException; @@ -74,6 +77,7 @@ public class RequestValidatorImpl implements RequestValidator { private WorkFlowManager workflowManager; private WorkingStateManager workingStateManager; + private LCMStateManager lcmStateManager; private final RequestRegistry requestRegistry = new RequestRegistry(); @@ -93,14 +97,26 @@ public class RequestValidatorImpl implements RequestValidator { this.workingStateManager = workingStateManager; } + public void setLcmStateManager(LCMStateManager lcmStateManager) { + this.lcmStateManager = lcmStateManager; + } + public RequestValidatorImpl() { } @Override - public void validateRequest(RuntimeContext runtimeContext) throws VNFNotFoundException, RequestExpiredException, UnstableVNFException, InvalidInputException, DuplicateRequestException, NoTransitionDefinedException, LifecycleException, WorkflowNotFoundException,DGWorkflowNotFoundException { + public void validateRequest(RuntimeContext runtimeContext) throws VNFNotFoundException, RequestExpiredException, UnstableVNFException, InvalidInputException, DuplicateRequestException, NoTransitionDefinedException, LifecycleException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException { if (logger.isTraceEnabled()){ logger.trace("Entering to validateRequest with RequestHandlerInput = "+ ObjectUtils.toString(runtimeContext)); } + if(!lcmStateManager.isLCMOperationEnabled()) { + LoggingUtils.logErrorMessage( + LoggingConstants.TargetNames.REQUEST_VALIDATOR, + EELFResourceManager.format(Msg.LCM_OPERATIONS_DISABLED), + this.getClass().getCanonicalName()); + throw new LCMOperationsDisabledException("APPC LCM operations have been administratively disabled"); + } + getAAIservice(); validateInput(runtimeContext.getRequestContext()); checkVNFWorkingState(runtimeContext); @@ -114,9 +130,9 @@ public class RequestValidatorImpl implements RequestValidator { // for built-in operations skip WF presence check queryWFM(vnfContext, runtimeContext.getRequestContext()); } - } + } - private boolean isValidTTL(String ttl) { + private boolean isValidTTL(String ttl) { if (logger.isTraceEnabled()){ logger.trace("Entering to isValidTTL where ttl = "+ ObjectUtils.toString(ttl)); } @@ -206,7 +222,7 @@ public class RequestValidatorImpl implements RequestValidator { } } - private VNFContext queryAAI(String vnfId) throws VNFNotFoundException { + private VNFContext queryAAI(String vnfId) throws VNFNotFoundException, MissingVNFDataInAAIException { SvcLogicContext ctx = new SvcLogicContext(); ctx = getVnfdata(vnfId, "vnf", ctx); @@ -267,9 +283,17 @@ public class RequestValidatorImpl implements RequestValidator { } } - private void populateVnfContext(VNFContext vnfContext, SvcLogicContext ctx) { - vnfContext.setType(ctx.getAttribute("vnf.vnf-type")); - vnfContext.setStatus(ctx.getAttribute("vnf.orchestration-status")); + private void populateVnfContext(VNFContext vnfContext, SvcLogicContext ctx) throws MissingVNFDataInAAIException { + String vnfType = ctx.getAttribute("vnf.vnf-type"); + String orchestrationStatus = ctx.getAttribute("vnf.orchestration-status"); + if(StringUtils.isEmpty(vnfType)){ + throw new MissingVNFDataInAAIException("vnf-type"); + } + else if(StringUtils.isEmpty(orchestrationStatus)){ + throw new MissingVNFDataInAAIException("orchestration-status"); + } + vnfContext.setType(vnfType); + vnfContext.setStatus(orchestrationStatus); vnfContext.setId(ctx.getAttribute("vnf.vnf-id")); // TODO: Uncomment once A&AI supports VNF version //vnfContext.setVersion(ctx.getAttribute("vnf.vnf-version")); diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 785b6cb04..984de9878 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -39,9 +39,13 @@ <property name="lifecyclemanager" ref="lifecyclemanagerRef" /> <property name="workflowManager" ref="workflowManagerRef" /> <property name="workingStateManager" ref="workingStateManagerBean" /> + <property name="lcmStateManager" ref="lcmStateManagerBean" /> </bean> + <bean id="lcmStateManagerBean" class="org.openecomp.appc.requesthandler.impl.LCMStateManagerImpl" scope="singleton" /> + <service id="requestHandlerService" interface="org.openecomp.appc.requesthandler.RequestHandler" ref="requestHandlerBean"/> + <service id="lcmStateManagerService" interface="org.openecomp.appc.requesthandler.LCMStateManager" ref="lcmStateManagerBean"/> <reference id="lifecyclemanagerRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.lifecyclemanager.LifecycleManager" /> <reference id="workflowManagerRef" availability="mandatory" activation="eager" interface="org.openecomp.appc.workflow.WorkFlowManager" /> <reference id="commandExecutorRef" availability="optional" activation="eager" interface="org.openecomp.appc.executor.CommandExecutor" /> diff --git a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/org/openecomp/appc/default.properties b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/org/openecomp/appc/default.properties index 2e2763f9a..ba24304f9 100644 --- a/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/org/openecomp/appc/default.properties +++ b/appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/resources/org/openecomp/appc/default.properties @@ -25,21 +25,14 @@ org.openecomp.appc.bootstrap.file=appc.properties org.openecomp.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. #Property below provided by appc.properties -#dmaap.poolMembers=<DMAAP_IP>:3904 +appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm +appc.LCM.poolMembers=<DMAAP_IP>:3904 +appc.LCM.service=dmaap +appc.LCM.topic.write=APPC-TEST2 +appc.LCM.client.name=APPC-TEST-CLIENT-REQ-HLDR-MAIN +appc.LCM.provider.user=test +appc.LCM.provider.pass=test -dmaap.topic.read=APPC-TEST2 -dmaap.topic.write=APPC-TEST2 -#dmaap.topic.read.filter={"class":"Assigned","field":"request"} -dmaap.topic.read.filter={"class": "And","filters": [{"class": "Assigned","field": "request"},{"class": "Unassigned","field": "response"}]} -dmaap.client.name=APPC-TEST-CLIENT-REQ-HDLR-MAIN -dmaap.client.name.id=0 -#dmaap.client.key=random -#dmaap.client.secret=random - -dmaap.threads.queuesize.min=1 -dmaap.threads.queuesize.max=1000 -dmaap.threads.poolsize.min=1 -dmaap.threads.poolsize.max=2 org.openecomp.appc.db.url.sdnctl=jdbc:mysql://127.0.0.1:3306/test org.openecomp.appc.db.user.sdnctl=test |