aboutsummaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-vcpe/pom.xml
blob: 78c2b454738a4764598fdb612fcb857ac0d3681f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!--
  ============LICENSE_START=======================================================
   Copyright (C) 2018 Ericsson. All rights reserved.
   Modifications Copyright (C) 2019-2020 Nordix Foundation.
  ================================================================================
  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.

  SPDX-License-Identifier: Apache-2.0
  ============LICENSE_END=========================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.onap.policy.apex-pdp.examples</groupId>
        <artifactId>examples</artifactId>
        <version>2.4.3-SNAPSHOT</version>
    </parent>

    <artifactId>examples-onap-vcpe</artifactId>
    <name>${project.artifactId}</name>
    <description>Specific code for the APEX ONAP vCPE Example</description>

    <properties>
        <policymodel.name>ONAPvCPEPolicyModel</policymodel.name>
        <toscapolicy.name>ONAPvCPEToscaPolicy</toscapolicy.name>
        <policymodelstandalone.name>ONAPvCPEPolicyModelStandalone</policymodelstandalone.name>
        <toscapolicystandalone.name>ONAPvCPEToscaPolicyStandalone</toscapolicystandalone.name>
        <apex-domains-onap-vcpe-dir>${project.basedir}/src</apex-domains-onap-vcpe-dir>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.auth</groupId>
            <artifactId>cli-editor</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.services</groupId>
            <artifactId>services-engine</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema</groupId>
            <artifactId>plugins-context-schema-avro</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
            <artifactId>plugins-executor-javascript</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
            <artifactId>plugins-event-carrier-restrequestor</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
            <artifactId>plugins-event-carrier-restclient</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
            <artifactId>aai</artifactId>
            <version>${version.policy.models}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
            <artifactId>appclcm</artifactId>
            <version>${version.policy.models}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
            <artifactId>events</artifactId>
            <version>${version.policy.models}</version>
        </dependency>
        <dependency>
            <groupId>org.onap.policy.common</groupId>
            <artifactId>policy-endpoints</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <!-- Generate the APEX Policy JSON from the APEX CLI command -->
                    <execution>
                        <id>generate-policy</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain</mainClass>
                            <classpathScope>compile</classpathScope>
                            <arguments>
                                <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodel.name}.apex</argument>
                                <argument>--output-model-file=${project.build.directory}/classes/${policymodel.name}.json</argument>
                                <argument>--log-file=${project.build.directory}/${policymodel.name}_policygeneration.log</argument>
                                <argument>--working-dir=${project.basedir}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <!-- Generate the APEX ToscaPolicy JSON file-->
                    <execution>
                        <id>generate-tosca-policy</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain</mainClass>
                            <classpathScope>compile</classpathScope>
                            <arguments>
                                <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodel.name}.apex</argument>
                                <argument>--output-tosca-file=${project.build.directory}/classes/${toscapolicy.name}.json</argument>
                                <argument>--log-file=${project.build.directory}/${policymodel.name}_policygeneration.log</argument>
                                <argument>--apex-config-file=${project.basedir}/src/main/resources/examples/config/ONAPvCPE/ApexConfig.json</argument>
                                <argument>--tosca-template-file=${project.basedir}/src/main/resources/tosca/ToscaTemplate.json</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <!-- Generate the Standalone APEX Policy JSON from the APEX CLI command -->
                    <execution>
                        <id>generate-standalone-policy</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain</mainClass>
                            <classpathScope>compile</classpathScope>
                            <arguments>
                                <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodelstandalone.name}.apex</argument>
                                <argument>--output-model-file=${project.build.directory}/classes/${policymodelstandalone.name}.json</argument>
                                <argument>--log-file=${project.build.directory}/${policymodelstandalone.name}_policygeneration.log</argument>
                                <argument>--working-dir=${project.basedir}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <!-- Generate the standalone APEX ToscaPolicy JSON file-->
                    <execution>
                        <id>generate-standalone-tosca-policy</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain</mainClass>
                            <classpathScope>compile</classpathScope>
                            <arguments>
                                <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodelstandalone.name}.apex</argument>
                                <argument>--output-tosca-file=${project.build.directory}/classes/${toscapolicystandalone.name}.json</argument>
                                <argument>--log-file=${project.build.directory}/${policymodelstandalone.name}_policygeneration.log</argument>
                                <argument>--apex-config-file=${project.basedir}/src/main/resources/examples/config/ONAPvCPEStandalone/ApexConfig.json</argument>
                                <argument>--tosca-template-file=${project.basedir}/src/main/resources/tosca/ToscaTemplate.json</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
an class="n">url) for catalog in aa.jsonget('/catalogs'): if catalogs is not None and catalog['catalogId'] not in catalogs and catalog['name'] not in catalogs: continue for solution in aa.jsonget('/solutions?catalogId={}', catalog['catalogId']): for revision in aa.jsonget('/solutions/{}/revisions', solution['solutionId']): onboard(aa, callback, solution, revision['revisionId']) def onboard(aa, callback, solution, revid): xrev = aa.jsonget('/solutions/{}/revisions/{}', solution['solutionId'], revid) callback(model_name=solution['name'], model_version=xrev['version'], model_last_updated=xrev['modified'], rating=solution['ratingAverageTenths'] / 10.0, proto_getter=aa.artgetter(xrev, _x_proto_matcher), zip_getter=aa.artgetter(xrev, _x_zip_matcher), metadata_getter=aa.artgetter(xrev, _md_json_matcher)) def _pullfile(source, dest): with open(dest, 'wb') as f: for chunk in source().iter_content(65536): f.write(chunk) _loadedformats = set() _loadedcomponents = set() def scan(config): _walk(config) def _makecallback(config): workdir = config.tmpdir obauth = config.obauth() oburl = config.oburl def callback(model_name, model_version, model_last_updated, rating, proto_getter, zip_getter, metadata_getter): model_name = model_name.lower() model_version = model_version.lower() compid = (model_name, model_version) if compid in _loadedcomponents: print('Skipping component {}: already analyzed'.format(compid)) return if proto_getter is None or zip_getter is None or metadata_getter is None: print('Skipping component {}: does not have required artifacts'.format(compid)) _loadedcomponents.add(compid) return modeldir = '{}/{}'.format(workdir, model_name) shutil.rmtree(modeldir, True) os.makedirs(modeldir) try: _pullfile(proto_getter, '{}/model.proto'.format(modeldir)) _pullfile(zip_getter, '{}/model.zip'.format(modeldir)) _pullfile(metadata_getter, '{}/metadata.json'.format(modeldir)) except Exception: print('Skipping component {}: artifact access error'.format(compid)) _loadedcomponents.add(compid) return try: docker_uri, data_formats, spec = convert.gen_dcae_artifacts_for_model(config, model_name, model_version) shutil.rmtree(modeldir) except Exception: print('Error analyzing artifacts for {}'.format(compid)) traceback.print_exc() return for data_format in data_formats: fmtid = (data_format['self']['name'], data_format['self']['version']) if fmtid in _loadedformats: print('Skipping data format {}: already analyzed'.format(fmtid)) continue try: resp = requests.post(oburl('/dataformats'), json={'owner': config.dcaeuser, 'spec': data_format}, auth=obauth) if resp.status_code == 409: print('Skipping data format {}: previously loaded'.format(fmtid)) _loadedformats.add(fmtid) continue resp.raise_for_status() requests.patch(resp.json()['dataFormatUrl'], json={'owner': config.dcaeuser, 'status': 'published'}, auth=obauth).raise_for_status() print('Loaded data format {}'.format(fmtid)) _loadedformats.add(fmtid) except Exception: print('Error loading data format {}'.format(fmtid)) traceback.print_exc() raise try: resp = requests.post(oburl('/components'), json={'owner': config.dcaeuser, 'spec': spec}, auth=obauth) if resp.status_code == 409: print('Skipping component {}: previously loaded'.format(compid)) _loadedcomponents.add(compid) return resp.raise_for_status() requests.patch(resp.json()['componentUrl'], json={'owner': config.dcaeuser, 'status': 'published'}, auth=obauth).raise_for_status() print('Loaded component {}'.format(compid)) _loadedcomponents.add(compid) except Exception: print('Error loading component {}'.format(compid)) traceback.print_exc() raise return callback class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): protocol_version = "HTTP/1.1" class Apihandler(BaseHTTPRequestHandler): def doqp(self): self.qparams = {} if not self.path or '?' not in self.path: return self.path, qp = self.path.split('?', 1) for x in qp.split('&'): k, v = x.split('=', 1) self.qparams[unquote_plus(k)] = unquote_plus(v) def replyjson(self, body, ctype='application/json'): self.replyraw(json.dumps(body).encode('utf-8'), ctype) def replyraw(self, data, ctype): self.send_response(200) self.send_header('Content-Type', ctype) self.send_header('Content-Length', len(data)) self.end_headers() self.wfile.write(data) def do_GET(self): self.doqp() if self.path == '/' or self.path == '/index.html' or self.path == '/acumos-adapter/' or self.path == '/acumos-adapter/index.html': self.replyraw(self.server.index, 'text/html') return if 'acumos' not in self.qparams: self.send_error(400) return aa = _AcumosAccess(self.server.config, self.qparams['acumos']) if self.path == '/acumos-adapter/listCatalogs.js': self.replyjson([{'name': x['name'], 'id': x['catalogId']} for x in aa.jsonget('/catalogs')]) return if self.path == '/acumos-adapter/listSolutions.js': if 'catalogId' not in self.qparams: self.send_error(400) return self.replyjson([{'name': x['name'], 'id': x['solutionId']} for x in aa.jsonget('/solutions?catalogId={}', self.qparams['catalogId'])]) return if self.path == '/acumos-adapter/listRevisions.js': if 'solutionId' not in self.qparams: self.send_error(400) return self.replyjson([{'name': x['version'], 'id': x['revisionId']} for x in aa.jsonget('/solutions/{}/revisions', self.qparams['solutionId'])]) return self.send_error(404) def do_POST(self): self.doqp() if self.path == '/acumos-adapter/onboard.js': if 'acumos' not in self.qparams: self.send_error(400) return aa = _AcumosAccess(self.server.config, self.qparams['acumos']) callback = self.server.callback if 'catalogId' not in self.qparams: for catalog in aa.jsonget('/catalogs'): for solution in aa.jsonget('/solutions?catalogId={}', catalog['catalogId']): for revision in aa.jsonget('/solutions/{}/revisions', solution['solutionId']): onboard(aa, callback, solution, revision['revisionId']) elif 'solutionId' not in self.qparams: for solution in aa.jsonget('/solutions?catalogId={}', self.qparams['catalogId']): for revision in aa.jsonget('/solutions/{}/revisions', solution['solutionId']): onboard(aa, callback, solution, revision['revisionId']) elif 'revisionId' not in self.qparams: solution = aa.jsonget('/solutions/{}', self.qparams['solutionId']) for revision in aa.jsonget('/solutions/{}/revisions', solution['solutionId']): onboard(aa, callback, solution, revision['revisionId']) else: solution = aa.jsonget('/solutions/{}', self.qparams['solutionId']) onboard(aa, callback, solution, self.qparams['revisionId']) self.replyraw('OK'.encode('utf-8'), 'text/plain') return self.send_error(400) def serve(config): server = ThreadedHTTPServer(('', config.port), Apihandler) server.config = config server.callback = _makecallback(config) server.index = resource_string(__name__, 'index.html') server.serve_forever()