diff options
Diffstat (limited to 'tools/model-generator/src')
4 files changed, 51 insertions, 40 deletions
diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetter.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetter.java index f7dfe8456..73bb1269d 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetter.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetter.java @@ -116,7 +116,7 @@ public class KeyInfoGetter { * @param key the key to process * @return local name of the parent, null if key was null */ - public String getPLName(final AxReferenceKey key) { + public String getPlName(final AxReferenceKey key) { if (key == null) { return null; } @@ -129,7 +129,7 @@ public class KeyInfoGetter { * @param key the key to extract version from * @return UUID of the key, null if key was null */ - public String getUUID(final AxArtifactKey key) { + public String getUuid(final AxArtifactKey key) { final AxKeyInfo ki = model.getKeyInformation().get(key); if (ki == null || ki.getUuid() == null) { return null; @@ -148,6 +148,6 @@ public class KeyInfoGetter { if (ki == null || ki.getDescription() == null) { return null; } - return ki.getDescription().toString(); + return ki.getDescription(); } } diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/SchemaUtils.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/SchemaUtils.java index 545d15eeb..14f84bb44 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/SchemaUtils.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/SchemaUtils.java @@ -129,11 +129,6 @@ public final class SchemaUtils { + " of type " + parameter.getSchema().getId() + " using Schema type " + schemaname, e); } if (alreadyseen != null) { - // logger.warn("parameter "+ parameter.getKey().getLocalName() + " of type " + parameter.getSchema().getID() - // + " tries to redfine AVRO type - // "+schemaname+", but it was previously defined. This parameter will use the previously defined version - // because AVRO does not support redefinition - // of types that have already been defined"); parameterSchema = alreadyseen; } diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java index 88ada24f6..e6002208c 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2Cli.java @@ -55,6 +55,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter; import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic; import org.onap.policy.apex.tools.common.OutputFile; import org.onap.policy.apex.tools.model.generator.KeyInfoGetter; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; import org.stringtemplate.v4.ST; /** @@ -63,6 +65,8 @@ import org.stringtemplate.v4.ST; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public class Model2Cli { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(Model2Cli.class); /** Application name, used as prompt. */ private final String appName; @@ -111,7 +115,8 @@ public class Model2Cli { final ApexApiResult result = model.loadFromFile(modelFile); if (result.isNok()) { - System.err.println(appName + ": " + result.getMessage()); + String message = appName + ": " + result.getMessage(); + LOGGER.error(message); return -1; } @@ -122,7 +127,8 @@ public class Model2Cli { final AxValidationResult val = new AxValidationResult(); policyModel.validate(val); if (!val.isOk()) { - System.err.println("Cannot translate the model. The model is not valid: \n" + val.toString()); + String message = "Cannot translate the model. The model is not valid: \n" + val.toString(); + LOGGER.error(message); return -1; } } @@ -132,13 +138,13 @@ public class Model2Cli { // Order is important. 0: model, 1: context schemas, 2: tasks, 3: events, 4: ContextAlbums, 5: Policies // 0: model final AxArtifactKey pmkey = policyModel.getKey(); - codeGen.addModelParams(kig.getName(pmkey), kig.getVersion(pmkey), kig.getUUID(pmkey), kig.getDesc(pmkey)); + codeGen.addModelParams(kig.getName(pmkey), kig.getVersion(pmkey), kig.getUuid(pmkey), kig.getDesc(pmkey)); // 1: Context Schemas for (final AxContextSchema s : policyModel.getSchemas().getSchemasMap().values()) { final AxArtifactKey key = s.getKey(); - codeGen.addSchemaDeclaration(kig.getName(key), kig.getVersion(key), kig.getUUID(key), kig.getDesc(key), + codeGen.addSchemaDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), s.getSchemaFlavour(), s.getSchema()); } @@ -151,7 +157,7 @@ public class Model2Cli { final List<ST> parameters = getParametersForTask(codeGen, t); final List<ST> contextRefs = getCtxtRefsForTask(codeGen, t); - codeGen.addTaskDeclaration(kig.getName(key), kig.getVersion(key), kig.getUUID(key), kig.getDesc(key), + codeGen.addTaskDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), infields, outfields, logic, parameters, contextRefs); } @@ -160,7 +166,7 @@ public class Model2Cli { final AxArtifactKey key = e.getKey(); final List<ST> fields = getParametersForEvent(codeGen, e); - codeGen.addEventDeclaration(kig.getName(key), kig.getVersion(key), kig.getUUID(key), kig.getDesc(key), + codeGen.addEventDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), e.getNameSpace(), e.getSource(), e.getTarget(), fields); } @@ -168,7 +174,7 @@ public class Model2Cli { for (final AxContextAlbum a : policyModel.getAlbums().getAlbumsMap().values()) { final AxArtifactKey key = a.getKey(); - codeGen.addContextAlbumDeclaration(kig.getName(key), kig.getVersion(key), kig.getUUID(key), + codeGen.addContextAlbumDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), a.getScope(), a.isWritable(), kig.getName(a.getItemSchema()), kig.getVersion(a.getItemSchema())); } @@ -177,26 +183,27 @@ public class Model2Cli { for (final AxPolicy p : policyModel.getPolicies().getPolicyMap().values()) { final AxArtifactKey key = p.getKey(); final List<ST> states = getStatesForPolicy(codeGen, p); - codeGen.addPolicyDefinition(kig.getName(key), kig.getVersion(key), kig.getUUID(key), kig.getDesc(key), + codeGen.addPolicyDefinition(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), p.getTemplate(), p.getFirstState(), states); } final String out = codeGen.getModel().render(); if (outFile != null) { + String message = "Error writing output to file " + outFile; try { final Writer w = outFile.toWriter(); if (w == null) { - System.err.println("Error writing output to file " + outFile); + LOGGER.error(message); return -1; } w.write(out); w.close(); } catch (final IOException e) { - System.err.println("Error writing output to file " + outFile + ": " + e.getMessage()); + LOGGER.error(message, e); return -1; } } else { - System.err.println(out); + LOGGER.error(out); } return 0; } @@ -275,10 +282,7 @@ public class Model2Cli { final AxArtifactKey tkey = task.getKey(); final AxTaskLogic tl = task.getTaskLogic(); - final ST val = - cg.createTaskDefLogic(kig.getName(tkey), kig.getVersion(tkey), tl.getLogicFlavour(), tl.getLogic()); - - return val; + return cg.createTaskDefLogic(kig.getName(tkey), kig.getVersion(tkey), tl.getLogicFlavour(), tl.getLogic()); } /** @@ -338,7 +342,7 @@ public class Model2Cli { final List<ST> outputs = getStateOutputsForState(cg, st); final List<ST> finalizerLogics = getFinalizersForState(cg, st); final List<ST> tasks = getTaskRefsForState(cg, st); - final List<ST> tsLogic = getTSLForState(cg, st); + final List<ST> tsLogic = getTslForState(cg, st); final List<ST> ctxRefs = getCtxtRefsForState(cg, st); final ST val = cg.createPolicyStateDef(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), @@ -400,7 +404,7 @@ public class Model2Cli { * @param st the state * @return the TSL for state (if any) in a list */ - private List<ST> getTSLForState(final CodeGeneratorCliEditor cg, final AxState st) { + private List<ST> getTslForState(final CodeGeneratorCliEditor cg, final AxState st) { final AxReferenceKey skey = st.getKey(); if (st.checkSetTaskSelectionLogic()) { final AxTaskSelectionLogic tsl = st.getTaskSelectionLogic(); diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java index 0bc9a27f8..6acbbbc02 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java @@ -41,6 +41,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState; import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; import org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters; import org.onap.policy.apex.tools.model.generator.SchemaUtils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupFile; @@ -51,6 +53,14 @@ import org.stringtemplate.v4.STGroupFile; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public class Model2JsonEventSchema { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(Model2JsonEventSchema.class); + + // Recurring string constants + private static final String TARGET = "target"; + private static final String SOURCE = "source"; + private static final String VERSION = "version"; + private static final String NAME_SPACE = "nameSpace"; /** Application name, used as prompt. */ private final String appName; @@ -150,7 +160,8 @@ public class Model2JsonEventSchema { final ApexApiResult result = model.loadFromFile(modelFile); if (result.isNok()) { - System.err.println(appName + ": " + result.getMessage()); + String message = appName + ": " + result.getMessage(); + LOGGER.error(message); return -1; } @@ -200,7 +211,7 @@ public class Model2JsonEventSchema { } break; default: - System.err.println(appName + ": unknown type <" + type + ">, cannot proceed"); + LOGGER.error("{}: unknown type <{}>, cannot proceed", appName, type); return -1; } @@ -215,20 +226,20 @@ public class Model2JsonEventSchema { for (final AxEvent event : events) { final ST stEvent = stg.getInstanceOf("event"); stEvent.add("name", event.getKey().getName()); - stEvent.add("nameSpace", event.getNameSpace()); - stEvent.add("version", event.getKey().getVersion()); - stEvent.add("source", event.getSource()); - stEvent.add("target", event.getTarget()); + stEvent.add(NAME_SPACE, event.getNameSpace()); + stEvent.add(VERSION, event.getKey().getVersion()); + stEvent.add(SOURCE, event.getSource()); + stEvent.add(TARGET, event.getTarget()); final Schema avro = SchemaUtils.getEventSchema(event); for (final Field field : avro.getFields()) { // filter magic names switch (field.name()) { case "name": - case "nameSpace": - case "version": - case "source": - case "target": + case NAME_SPACE: + case VERSION: + case SOURCE: + case TARGET: break; default: stEvent.add("fields", this.setField(field, stg)); @@ -236,7 +247,8 @@ public class Model2JsonEventSchema { } stEvents.add("event", stEvent); } - System.err.println(stEvents.render()); + String renderMessage = stEvents.render(); + LOGGER.error(renderMessage); return 0; } @@ -251,10 +263,10 @@ public class Model2JsonEventSchema { final ST st = stg.getInstanceOf("field"); switch (field.name()) { case "name": - case "nameSpace": - case "version": - case "source": - case "target": + case NAME_SPACE: + case VERSION: + case SOURCE: + case TARGET: break; default: st.add("name", field.name()); |