diff options
Diffstat (limited to 'src/main')
12 files changed, 363 insertions, 257 deletions
diff --git a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java index c3b24bc81..f178ce039 100644 --- a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java @@ -36,7 +36,7 @@ public class CamelConfiguration extends RouteBuilder { @Override public void configure() { - restConfiguration().component("servlet").bindingMode(RestBindingMode.json).jsonDataFormat("json-gson") + restConfiguration().component("servlet").bindingMode(RestBindingMode.json).jsonDataFormat("clamp-gson") .dataFormatProperty("prettyPrint", "true")// .enableCORS(true) // turn on swagger api-doc .apiContextPath("api-doc").apiVendorExtension(true).apiProperty("api.title", "Clamp Rest API") diff --git a/src/main/java/org/onap/clamp/configuration/CamelGsonConfiguration.java b/src/main/java/org/onap/clamp/configuration/CamelGsonConfiguration.java deleted file mode 100644 index f71d2f091..000000000 --- a/src/main/java/org/onap/clamp/configuration/CamelGsonConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP CLAMP - * ================================================================================ - * Copyright (C) 2019 Nokia 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.onap.clamp.configuration; - -import com.google.gson.ExclusionStrategy; -import com.google.gson.FieldAttributes; -import com.google.gson.annotations.Expose; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import org.apache.camel.component.gson.GsonDataFormat; -import org.apache.camel.spi.DataFormatCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class CamelGsonConfiguration { - - @Bean - public List<DataFormatCustomizer<GsonDataFormat>> provideGsonCustomizers() { - DataFormatCustomizer<GsonDataFormat> dataFormatCustomizer = dataformat -> - dataformat.setExclusionStrategies( - Collections.singletonList(new ExcludeFieldsWithoutExposedAnnotation()) - ); - return Collections.singletonList(dataFormatCustomizer); - } - - private static class ExcludeFieldsWithoutExposedAnnotation implements ExclusionStrategy { - - @Override - public boolean shouldSkipField(FieldAttributes f) { - return Optional.ofNullable(f.getAnnotation(Expose.class)) - .map(expose -> !expose.serialize()) - .orElse(true); - } - - @Override - public boolean shouldSkipClass(Class<?> clazz) { - return false; - } - } -} diff --git a/src/main/java/org/onap/clamp/configuration/ClampGsonDataFormat.java b/src/main/java/org/onap/clamp/configuration/ClampGsonDataFormat.java new file mode 100644 index 000000000..aad1ab4c7 --- /dev/null +++ b/src/main/java/org/onap/clamp/configuration/ClampGsonDataFormat.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 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.onap.clamp.configuration; + +import com.google.gson.Gson; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.lang.reflect.Type; +import java.nio.charset.StandardCharsets; + +import org.apache.camel.Exchange; +import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.DataFormatName; +import org.apache.camel.support.ServiceSupport; +import org.apache.camel.util.IOHelper; +import org.onap.clamp.clds.util.JsonUtils; + +public class ClampGsonDataFormat extends ServiceSupport implements DataFormat, DataFormatName { + private Gson gson; + private Class<?> unmarshalType; + private Type unmarshalGenericType; + private boolean contentTypeHeader = true; + + public ClampGsonDataFormat() { + this(Object.class); + } + + /** + * Use the default Gson {@link Gson} and with a custom unmarshal type + * + * @param unmarshalType + * the custom unmarshal type + */ + public ClampGsonDataFormat(Class<?> unmarshalType) { + this(null, unmarshalType); + } + + /** + * Use a custom Gson mapper and and unmarshal type + * + * @param gson + * the custom mapper + * @param unmarshalType + * the custom unmarshal type + */ + public ClampGsonDataFormat(Gson gson, Class<?> unmarshalType) { + this.gson = gson; + this.unmarshalType = unmarshalType; + } + + /** + * Use the default Gson {@link Gson} and with a custom unmarshal generic type + * + * @param unmarshalGenericType + * the custom unmarshal generic type + */ + public ClampGsonDataFormat(Type unmarshalGenericType) { + this(null, unmarshalGenericType); + } + + /** + * Use a custom Gson mapper and and unmarshal token type + * + * @param gson + * the custom mapper + * @param unmarshalGenericType + * the custom unmarshal generic type + */ + public ClampGsonDataFormat(Gson gson, Type unmarshalGenericType) { + this.gson = gson; + this.unmarshalGenericType = unmarshalGenericType; + } + + @Override + public String getDataFormatName() { + return "clamp-gson"; + } + + @Override + public void marshal(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { + try (final OutputStreamWriter osw = new OutputStreamWriter(stream, StandardCharsets.UTF_8); + final BufferedWriter writer = IOHelper.buffered(osw)) { + gson.toJson(graph, writer); + } + + if (contentTypeHeader) { + if (exchange.hasOut()) { + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } else { + exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); + } + } + } + + @Override + public Object unmarshal(final Exchange exchange, final InputStream stream) throws Exception { + try (final InputStreamReader isr = new InputStreamReader(stream, StandardCharsets.UTF_8); + final BufferedReader reader = IOHelper.buffered(isr)) { + if (unmarshalGenericType == null) { + return gson.fromJson(reader, unmarshalType); + } else { + return gson.fromJson(reader, unmarshalGenericType); + } + } + } + + @Override + protected void doStart() throws Exception { + if (gson == null) { + gson = JsonUtils.GSON_JPA_MODEL; + } + } + + @Override + protected void doStop() throws Exception { + // noop + } + + // Properties + // ------------------------------------------------------------------------- + + public Class<?> getUnmarshalType() { + return this.unmarshalType; + } + + public void setUnmarshalType(Class<?> unmarshalType) { + this.unmarshalType = unmarshalType; + } + + public Type getUnmarshalGenericType() { + return this.unmarshalType; + } + + public void setUnmarshalGenericType(Type unmarshalGenericType) { + this.unmarshalGenericType = unmarshalGenericType; + } + + public boolean isContentTypeHeader() { + return contentTypeHeader; + } + + /** + * If enabled then Gson will set the Content-Type header to + * <tt>application/json</tt> when marshalling. + */ + public void setContentTypeHeader(boolean contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + + public Gson getGson() { + return this.gson; + } +} diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index a24d3449f..83f938dde 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -23,6 +23,8 @@ package org.onap.clamp.loop; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; @@ -257,6 +259,30 @@ public class Loop implements Serializable { return buffer.toString().replace('.', '_').replaceAll(" ", ""); } + public String createPoliciesPayloadPdpGroup() { + JsonObject jsonObject = new JsonObject(); + JsonArray jsonArray = new JsonArray(); + jsonObject.add("policies", jsonArray); + + for (OperationalPolicy opPolicy : this.getOperationalPolicies()) { + JsonObject policyNode = new JsonObject(); + jsonArray.add(policyNode); + policyNode.addProperty("policy-id", opPolicy.getName()); + + for (String guardName : opPolicy.createGuardPolicyPayloads().keySet()) { + JsonObject guardPolicyNode = new JsonObject(); + jsonArray.add(guardPolicyNode); + guardPolicyNode.addProperty("policy-id", guardName); + } + } + for (MicroServicePolicy microServicePolicy : this.getMicroServicePolicies()) { + JsonObject policyNode = new JsonObject(); + jsonArray.add(policyNode); + policyNode.addProperty("policy-id", microServicePolicy.getName()); + } + return new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject); + } + @Override public int hashCode() { final int prime = 31; diff --git a/src/main/java/org/onap/clamp/loop/LoopOperation.java b/src/main/java/org/onap/clamp/loop/LoopOperation.java index 5b55ab0de..d9ea24871 100644 --- a/src/main/java/org/onap/clamp/loop/LoopOperation.java +++ b/src/main/java/org/onap/clamp/loop/LoopOperation.java @@ -31,7 +31,6 @@ import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import java.io.IOException; import java.lang.reflect.Array; import java.util.Collection; import java.util.Date; @@ -213,163 +212,4 @@ public class LoopOperation { return new JsonPrimitive(String.valueOf(o)); } - /** - * Submit the Ms policies. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws IOException - * IO exception - * @throws Exceptions - * during the operation - */ - public Loop submitMsPolicies(String loopName) throws OperationException, IOException { - util.entering(request, "LoopOperation: delete microservice policies"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Submit MS policies exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED && loop.getLastComputedState() != LoopState.DESIGN) { - String msg = "Submit MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to create the ms services - // policyOp.createMsPolicy(loop.getMicroServicePolicies()); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of MS policies completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } - - /** - * Delete the Ms policies. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws IOException - * IO exception - * @throws Exceptions - * during the operation - */ - public Loop deleteMsPolicies(Exchange camelExchange, String loopName) throws OperationException, IOException { - util.entering(request, "LoopOperation: delete microservice policies"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Delete MS policies exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED) { - String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to create the ms services - // policyOp.deleteMsPolicy(loop.getMicroServicePolicies()); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of MS policies completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } - - /** - * Delete the operational policy. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws Exceptions - * during the operation - */ - public Loop deleteOpPolicy(Exchange camelExchange, String loopName) throws OperationException { - util.entering(request, "LoopOperation: delete guard policy"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Delete guard policy exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED) { - String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to delete operational policy - // client.deleteOpPolicy(); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of Guard policy completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } - - /** - * Delete the Guard policy. - * - * @param loopName - * the loop name - * @return the updated loop - * @throws Exceptions - * during the operation - */ - public Loop deleteGuardPolicy(Exchange camelExchange, String loopName) throws OperationException { - util.entering(request, "LoopOperation: delete operational policy"); - Date startTime = new Date(); - Loop loop = loopService.getLoop(loopName); - - if (loop == null) { - String msg = "Delete operational policy exception: Not able to find closed loop:" + loopName; - util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO, - ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // verify the current closed loop state - if (loop.getLastComputedState() != LoopState.SUBMITTED) { - String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState() - + ". It could be deleted only when it is in SUBMITTED state."; - util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO, ONAPLogConstants.ResponseStatus.ERROR); - throw new OperationException(msg); - } - - // Establish the api call to Policy to delete Guard policy - // client.deleteOpPolicy(); - - // audit log - LoggingUtils.setTimeContext(startTime, new Date()); - auditLogger.info("Deletion of operational policy completed"); - util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED); - return loop; - } } diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index 8d61b877b..4c1392253 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -67,6 +67,10 @@ public class LoopService { return loopsRepository.findById(loopName).orElse(null); } + public void deleteLoop(String loopName) { + loopsRepository.deleteById(loopName); + } + Loop updateAndSaveOperationalPolicies(String loopName, List<OperationalPolicy> newOperationalPolicies) { Loop loop = findClosedLoopByName(loopName); Set<OperationalPolicy> newPolicies = operationalPolicyService.updatePolicies(loop, newOperationalPolicies); diff --git a/src/main/java/org/onap/clamp/loop/log/LoopLogService.java b/src/main/java/org/onap/clamp/loop/log/LoopLogService.java index b593b41ed..b02bc11c4 100644 --- a/src/main/java/org/onap/clamp/loop/log/LoopLogService.java +++ b/src/main/java/org/onap/clamp/loop/log/LoopLogService.java @@ -40,4 +40,8 @@ public class LoopLogService { public void addLog(String message, String logType, Loop loop) { repository.save(new LoopLog(message, LogType.valueOf(logType), loop)); } + + public boolean isExisting(Long logId) { + return repository.existsById(logId); + } } diff --git a/src/main/resources/META-INF/services/org/apache/camel/dataformat/clamp-gson b/src/main/resources/META-INF/services/org/apache/camel/dataformat/clamp-gson new file mode 100644 index 000000000..3fa78e040 --- /dev/null +++ b/src/main/resources/META-INF/services/org/apache/camel/dataformat/clamp-gson @@ -0,0 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2019 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============================================ + * =================================================================== + */ + +class=org.onap.clamp.configuration.ClampGsonDataFormat
\ No newline at end of file diff --git a/src/main/resources/application-noaaf.properties b/src/main/resources/application-noaaf.properties index 84e97ea30..56ad7e846 100644 --- a/src/main/resources/application-noaaf.properties +++ b/src/main/resources/application-noaaf.properties @@ -110,7 +110,7 @@ spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.use-new-id-generator-mappings=true # Whether to enable logging of SQL statements. -spring.jpa.show-sql=true +#spring.jpa.show-sql=true #Async Executor default Parameters async.core.pool.size=10 @@ -135,7 +135,7 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment- # # # Configuration Settings for Policy Engine Components -clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081/policy/api/v1 +clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081 clamp.config.policy.userName=test clamp.config.policy.password=test clamp.config.policy.pdpUrl1=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123 diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b1077d382..640120230 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -125,7 +125,7 @@ spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.use-new-id-generator-mappings=true # Whether to enable logging of SQL statements. -spring.jpa.show-sql=true +#spring.jpa.show-sql=true #Async Executor default Parameters async.core.pool.size=10 @@ -150,7 +150,7 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment- # # # Configuration Settings for Policy Engine Components -clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081/policy/api/v1 +clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081 clamp.config.policy.userName=test clamp.config.policy.password=test clamp.config.policy.pdpUrl1=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123 diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index 810c9d205..ffa4719f0 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -97,14 +97,14 @@ </put> <put uri="/v2/loop/submit/{loopName}"> <route> - <setBody> - <simple>${header.loopName}</simple> - </setBody> <log loggingLevel="INFO" - message="Receive SUBMIT request for loop: ${body}" /> + message="Receive SUBMIT request for loop: ${header.loopName}" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> + <setBody> + <simple>${header.loopName}</simple> + </setBody> <to uri="direct:load-loop" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Receive SUBMIT request','INFO',${header.LoopObject})" /> @@ -120,12 +120,12 @@ <log loggingLevel="INFO" message="Processing Micro Service Policy: ${header.microServicePolicy.getName()}" /> - <setHeader headerName="HttpQueryExceptionFlag"> + <setHeader headerName="RaiseHttpExceptionFlag"> <simple resultType="java.lang.Boolean">false</simple> </setHeader> <to uri="direct:delete-micro-service-policy" /> - <setHeader headerName="HttpQueryExceptionFlag"> + <setHeader headerName="RaiseHttpExceptionFlag"> <simple resultType="java.lang.Boolean">true</simple> </setHeader> <to uri="direct:create-micro-service-policy" /> @@ -143,12 +143,12 @@ <log loggingLevel="INFO" message="Processing Operational Policy: ${header.operationalPolicy.getName()}" /> - <setHeader headerName="HttpQueryExceptionFlag"> + <setHeader headerName="RaiseHttpExceptionFlag"> <simple resultType="java.lang.Boolean">false</simple> </setHeader> <to uri="direct:delete-operational-policy" /> - <setHeader headerName="HttpQueryExceptionFlag"> + <setHeader headerName="RaiseHttpExceptionFlag"> <simple resultType="java.lang.Boolean">true</simple> </setHeader> <to uri="direct:create-operational-policy" /> @@ -165,30 +165,98 @@ loggingLevel="INFO" message="Processing Guard Policy: ${header.guardPolicy.getKey()}" /> - <setHeader headerName="HttpQueryExceptionFlag"> + <setHeader headerName="RaiseHttpExceptionFlag"> <simple resultType="java.lang.Boolean">false</simple> </setHeader> <to uri="direct:delete-guard-policy" /> - <setHeader headerName="HttpQueryExceptionFlag"> + <setHeader headerName="RaiseHttpExceptionFlag"> <simple resultType="java.lang.Boolean">true</simple> </setHeader> <to uri="direct:create-guard-policy" /> </split> - </split> + <setHeader headerName="RaiseHttpExceptionFlag"> + <simple resultType="java.lang.Boolean">true</simple> + </setHeader> + <to uri="direct:create-pdp-group-policy" /> + + <log + loggingLevel="INFO" + message="SUBMIT request successfully executed for loop: ${body}" /> + <to + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('SUBMIT request successfully executed','INFO',${header.LoopObject})" /> </route> </put> <put uri="/v2/loop/delete/{loopName}"> <route> + <log + loggingLevel="INFO" + message="Receive DELETE request for loop: ${header.loopName}" /> <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" /> + <setBody> + <simple>${header.loopName}</simple> + </setBody> + <to uri="direct:load-loop" /> <to - uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteMsPolicies(${header.loopName})" /> - <to - uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteOpPolicy(${header.loopName})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Receive DELETE request','INFO',${header.LoopObject})" /> + <split> + <simple>${header.LoopObject.getMicroServicePolicies()} + </simple> + <setHeader headerName="microServicePolicy"> + <simple>${body}</simple> + </setHeader> + <log + loggingLevel="INFO" + message="Processing Micro Service Policy: ${header.microServicePolicy.getName()}" /> + <setHeader headerName="RaiseHttpExceptionFlag"> + <simple resultType="java.lang.Boolean">true</simple> + </setHeader> + <to uri="direct:delete-micro-service-policy" /> + </split> + + <log + loggingLevel="INFO" + message="Processing all OPERATIONAL policies defined in loop ${header.LoopObject.getName()}" /> + <split> + <simple>${header.LoopObject.getOperationalPolicies()} + </simple> + <setHeader headerName="operationalPolicy"> + <simple>${body}</simple> + </setHeader> + <log + loggingLevel="INFO" + message="Processing Operational Policy: ${header.operationalPolicy.getName()}" /> + <setHeader headerName="RaiseHttpExceptionFlag"> + <simple resultType="java.lang.Boolean">true</simple> + </setHeader> + <to uri="direct:delete-operational-policy" /> + <log + loggingLevel="INFO" + message="Processing all GUARD policies defined in loop ${header.LoopObject.getName()}" /> + <split> + <simple>${header.operationalPolicy.createGuardPolicyPayloads().entrySet()} + </simple> + <setHeader headerName="guardPolicy"> + <simple>${body}</simple> + </setHeader> + <log + loggingLevel="INFO" + message="Processing Guard Policy: ${header.guardPolicy.getKey()}" /> + + <setHeader headerName="RaiseHttpExceptionFlag"> + <simple resultType="java.lang.Boolean">true</simple> + </setHeader> + <to uri="direct:delete-guard-policy" /> + </split> + </split> + <to uri="bean:org.onap.clamp.loop.log.LoopService?method=deleteLoop(${header.loopName})" /> + <log + loggingLevel="INFO" + message="DELETE request successfully executed for loop: ${body}" /> <to - uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteGuardPolicy(${header.loopName})" /> + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('DELETE request successfully executed','INFO',${header.LoopObject})" /> </route> </put> </rest> diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index 33419c219..1f3e01e27 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -113,14 +113,14 @@ <constant>application/json</constant> </setHeader> <setHeader headerName="CamelHttpUri"> - <simple>{{clamp.config.policy.url}}/policyTypes/${header.microServicePolicy.getModelType()}/versions/1.0.0/policies + <simple>{{clamp.config.policy.url}}/policy/api/v1/policyTypes/${header.microServicePolicy.getModelType()}/versions/1.0.0/policies </simple> </setHeader> <log loggingLevel="INFO" message="Endpoint to create microservice policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> <toD - uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}" /> + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('MicroService policy created successfully','INFO',${header.LoopObject})" /> </route> @@ -136,14 +136,14 @@ <constant>DELETE</constant> </setHeader> <setHeader headerName="CamelHttpUri"> - <simple>{{clamp.config.policy.url}}/policyTypes/${header.microServicePolicy.getModelType()}/versions/1.0.0/policies/${header.microServicePolicy.getName()} + <simple>{{clamp.config.policy.url}}/policy/api/v1/policyTypes/${header.microServicePolicy.getModelType()}/versions/1.0.0/policies/${header.microServicePolicy.getName()} </simple> </setHeader> <log loggingLevel="INFO" message="Endpoint to delete microservice policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> <toD - uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false" /> + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('MicroService policy deleted successfully','INFO',${header.LoopObject})" /> </route> @@ -161,17 +161,17 @@ <constant>POST</constant> </setHeader> <setHeader headerName="Content-Type"> - <constant>application/json</constant> + <constant>application/yaml; legacy-version</constant> </setHeader> <setHeader headerName="CamelHttpUri"> - <simple>{{clamp.config.policy.url}}/policyTypes/onap.policies.controloop.operational/versions/1.0.0/policies + <simple>{{clamp.config.policy.url}}/policy/api/v1/policyTypes/onap.policies.controloop.operational/versions/1.0.0/policies </simple> </setHeader> <log loggingLevel="INFO" message="Endpoint to create operational policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> <toD - uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}" /> + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Operational policy created successfully','INFO',${header.LoopObject})" /> </route> @@ -187,14 +187,14 @@ <constant>DELETE</constant> </setHeader> <setHeader headerName="CamelHttpUri"> - <simple>{{clamp.config.policy.url}}/policyTypes/onap.policies.controloop.operational/versions/1.0.0/policies/${header.operationalPolicy.getName()} + <simple>{{clamp.config.policy.url}}/policy/api/v1/policyTypes/onap.policies.controloop.operational/versions/1.0.0/policies/${header.operationalPolicy.getName()} </simple> </setHeader> <log loggingLevel="INFO" message="Endpoint to delete operational policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> <toD - uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false" /> + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Operational policy deleted successfully','INFO',${header.LoopObject})" /> </route> @@ -215,14 +215,14 @@ <constant>application/json</constant> </setHeader> <setHeader headerName="CamelHttpUri"> - <simple>{{clamp.config.policy.url}}/policyTypes/onap.policies.controlloop.Guard/versions/1.0.0/policies + <simple>{{clamp.config.policy.url}}/policy/api/v1/policyTypes/onap.policies.controlloop.Guard/versions/1.0.0/policies </simple> </setHeader> <log loggingLevel="INFO" message="Endpoint to create guard policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> <toD - uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}" /> + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Guard policy created successfully','INFO',${header.LoopObject})" /> </route> @@ -238,16 +238,43 @@ <constant>DELETE</constant> </setHeader> <setHeader headerName="CamelHttpUri"> - <simple>{{clamp.config.policy.url}}/policyTypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/${header.guardPolicy.getKey()} + <simple>{{clamp.config.policy.url}}/policy/api/v1/policyTypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/${header.guardPolicy.getKey()} </simple> </setHeader> <log loggingLevel="INFO" message="Endpoint to delete guard policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> <toD - uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false" /> + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> <to uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Guard policy deleted successfully','INFO',${header.LoopObject})" /> </route> - + + <route id="create-pdp-group-policy"> + <from uri="direct:create-pdp-group-policy" /> + <log + loggingLevel="INFO" + message="Creating PDP Group Policy: ${header.guardPolicy.getKey()}" /> + <setBody> + <simple>${header.LoopObject.createPoliciesPayloadPdpGroup()} + </simple> + </setBody> + <setHeader headerName="CamelHttpMethod"> + <constant>POST</constant> + </setHeader> + <setHeader headerName="Content-Type"> + <constant>application/json</constant> + </setHeader> + <setHeader headerName="CamelHttpUri"> + <simple>{{clamp.config.policy.url}}/policy/pap/v1/pdps + </simple> + </setHeader> + <log + loggingLevel="INFO" + message="Endpoint to create PDP Group policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log> + <toD + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.RaiseHttpExceptionFlag}&httpClient.connectTimeout=10000&authUsername={{clamp.config.policy.userName}}&authPassword={{clamp.config.policy.password}}" /> + <to + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Pdp Group created successfully','INFO',${header.LoopObject})" /> + </route> </routes>
\ No newline at end of file |