2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.artifact.handler.dbservices;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import java.util.Optional;
30 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
35 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
37 import java.sql.SQLException;
38 import java.util.HashMap;
39 import org.apache.commons.lang.StringUtils;
40 import org.apache.commons.configuration.PropertiesConfiguration;
41 import org.apache.commons.configuration.ConfigurationException;
43 public class DBService {
45 private static final EELFLogger log = EELFManager.getInstance().getLogger(DBService.class);
46 private SvcLogicResource serviceLogic;
47 private static DBService dgGeneralDBService = null;
49 public static DBService initialise() {
50 if (dgGeneralDBService == null) {
51 dgGeneralDBService = new DBService();
53 return dgGeneralDBService;
57 if (serviceLogic == null) {
58 serviceLogic = new SqlResource();
62 protected DBService(SqlResource svcLogic) {
63 if (serviceLogic == null) {
64 serviceLogic = svcLogic;
68 public String getInternalVersionNumber(SvcLogicContext ctx, String artifactName, String prefix)
69 throws SvcLogicException {
70 String fn = "DBService.getInternalVersionNumber";
71 QueryStatus status = null;
72 String artifactInternalVersion = null;
73 if (serviceLogic != null && ctx != null) {
74 String key = "select max(internal_version) as maximum from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '"
76 log.info("Getting internal Versoin :" + key);
77 status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx);
78 if (status.toString().equals("FAILURE"))
79 throw new SvcLogicException("Error - getting internal Artifact Number");
80 artifactInternalVersion = ctx.getAttribute("maximum");
81 log.info("Internal Version received as : " + artifactInternalVersion);
82 log.info("Internal Version received as1 : " + ctx.getAttribute("max(internal_version)"));
83 log.info("Internal Version received as1 : " + ctx.getAttribute("max"));
84 log.info("Internal Version received as1 : " + ctx.getAttribute("internal_version"));
85 log.info("Internal Version received as1 : " + ctx.getAttributeKeySet().toString());
87 return artifactInternalVersion;
90 public String getArtifactID(SvcLogicContext ctx, String artifactName) throws SvcLogicException {
91 String fn = "DBService.getArtifactID";
92 QueryStatus status = null;
93 String artifactID = null;
94 if (serviceLogic != null && ctx != null) {
95 String key = "select max(ASDC_ARTIFACTS_ID) as id from ASDC_ARTIFACTS WHERE ARTIFACT_NAME = '"
97 log.info("Getting Artifact ID String :" + key);
98 status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
99 if (status.toString().equals("FAILURE"))
100 throw new SvcLogicException("Error - getting Artifact ID from database");
101 artifactID = ctx.getAttribute("id");
102 log.info("SDC_ARTIFACTS_ID received as : " + ctx.getAttribute("id"));
107 public QueryStatus saveArtifacts(SvcLogicContext ctx, int intversion) throws SvcLogicException {
108 String fn = "DBService.saveArtifacts";
109 QueryStatus status = null;
110 if (serviceLogic != null && ctx != null) {
111 String key = "INSERT INTO ASDC_ARTIFACTS " + "SET SERVICE_UUID = $service-uuid , "
112 + " DISTRIBUTION_ID = $distribution-id ," + " SERVICE_NAME = $service-name ,"
113 + " SERVICE_DESCRIPTION = $service-description ," + " RESOURCE_UUID = $resource-uuid ,"
114 + " RESOURCE_INSTANCE_NAME = $resource-instance-name ," + " RESOURCE_NAME = $resource-name ,"
115 + " RESOURCE_VERSION = $resource-version ," + " RESOURCE_TYPE = $resource-type ,"
116 + " ARTIFACT_UUID = $artifact-uuid ," + " ARTIFACT_TYPE = $artifact-type ,"
117 + " ARTIFACT_VERSION = $artifact-version ," + " ARTIFACT_DESCRIPTION = $artifact-description ,"
118 + " INTERNAL_VERSION = " + intversion + "," + " ARTIFACT_NAME = $artifact-name ,"
119 + " ARTIFACT_CONTENT = $artifact-contents ";
121 status = serviceLogic.save("SQL", false, false, key, null, null, ctx);
122 if (status.toString().equals("FAILURE"))
123 throw new SvcLogicException("Error While processing storing Artifact: "
124 + ctx.getAttribute(SdcArtifactHandlerConstants.ARTIFACT_NAME));
130 public QueryStatus logData(SvcLogicContext ctx, String prefix) throws SvcLogicException {
131 String fn = "DBService.saveReferenceData";
132 QueryStatus status = null;
133 if (serviceLogic != null && ctx != null) {
134 String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , "
135 + " message_type = $log-message-type , " + " message = $log-message ;";
136 status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx);
137 if (status.toString().equals("FAILURE"))
138 throw new SvcLogicException("Error while loging data");
144 public void processConfigureActionDg(SvcLogicContext context, boolean isUpdate) {
145 String fn = "DBService.processConfigureActionDg";
146 log.info("Update Parameter for SDC Reference " + isUpdate);
148 QueryStatus status = null;
153 public void processSdcReferences(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
154 String fn = "DBService.processSdcReferences";
156 QueryStatus status = null;
158 if (isUpdate && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) {
159 log.info("Updating capability artifact in ASDC_REFERENCE");
160 key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $"
161 + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where " + "FILE_CATEGORY = $"
162 + SdcArtifactHandlerConstants.FILE_CATEGORY + " and VNF_TYPE = $"
163 + SdcArtifactHandlerConstants.VNF_TYPE ;
165 key = "update " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set ARTIFACT_NAME = $"
166 + SdcArtifactHandlerConstants.ARTIFACT_NAME + " where VNFC_TYPE = $"
167 + SdcArtifactHandlerConstants.VNFC_TYPE + " and FILE_CATEGORY = $"
168 + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
169 + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
172 if (context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY).equals(SdcArtifactHandlerConstants.CAPABILITY)) {
173 log.info("Inserting new record for capability artifact in ASDC_REFERENCE");
174 key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = null "
175 + " , FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
176 + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = null " + " , ARTIFACT_TYPE = null "
177 + " , ARTIFACT_NAME = $" + SdcArtifactHandlerConstants.ARTIFACT_NAME;
179 key = "insert into " + SdcArtifactHandlerConstants.DB_SDC_REFERENCE + " set VNFC_TYPE = $"
180 + SdcArtifactHandlerConstants.VNFC_TYPE + " , FILE_CATEGORY = $"
181 + SdcArtifactHandlerConstants.FILE_CATEGORY + " , VNF_TYPE = $"
182 + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION
183 + " , ARTIFACT_TYPE = $" + SdcArtifactHandlerConstants.ARTIFACT_TYPE + " , ARTIFACT_NAME = $"
184 + SdcArtifactHandlerConstants.ARTIFACT_NAME;
187 if (serviceLogic != null && context != null) {
188 log.info("Insert Key: " + key);
189 status = serviceLogic.save("SQL", false, false, key, null, null, context);
190 if (status.toString().equals("FAILURE"))
191 throw new SvcLogicException("Error While processing sdc_reference table ");
195 public boolean isArtifactUpdateRequired(SvcLogicContext context, String db) throws SvcLogicException, SQLException, ConfigurationException {
196 String fn = "DBService.isArtifactUpdateRequired";
197 log.info("Checking if Update required for this data");
200 log.info("ACTION=" + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
201 log.info("VNFC_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_TYPE));
202 log.info("VNFC_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
203 log.info("VM_INSTANCE=" + context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
204 log.info("VNF_TYPE=" + context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
205 String whereClause = "";
207 QueryStatus status = null;
208 whereClause = " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
211 if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)
212 && context.getAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY)
213 .equals(SdcArtifactHandlerConstants.CAPABILITY)
214 && context.getAttribute(SdcArtifactHandlerConstants.ACTION) == null) {
215 whereClause = whereClause + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY;
218 else if (db.equals(SdcArtifactHandlerConstants.DB_SDC_REFERENCE)) {
219 whereClause = whereClause + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
220 + " and FILE_CATEGORY = $" + SdcArtifactHandlerConstants.FILE_CATEGORY + " and ACTION = $"
221 + SdcArtifactHandlerConstants.ACTION;
224 else if (db.equals(SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE)) {
225 whereClause = " where PROTOCOL = $" + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
226 } else if (db.equals(SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG)) {
227 whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION;
228 } else if (db.equals(SdcArtifactHandlerConstants.DB_VNFC_REFERENCE)) {
229 int vm_instance = -1;
230 if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null)
231 vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
232 int vnfc_instance = -1;
233 if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
234 vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
235 whereClause = whereClause + " and ACTION = $" + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $"
236 + SdcArtifactHandlerConstants.VNFC_TYPE + " and VNFC_INSTANCE = $"
237 + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
238 + SdcArtifactHandlerConstants.VM_INSTANCE;
243 if (!db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION) && serviceLogic != null && context != null) {
244 String key = "select COUNT(*) from " + db + whereClause;
245 log.info("SELECT String : " + key);
246 status = serviceLogic.query("SQL", false, null, key, null, null, context);
247 if (status.toString().equals("FAILURE")) {
248 throw new SvcLogicException("Error while reading data from " + db);
250 String count = context.getAttribute("COUNT(*)");
251 log.info("Number of row Returned : " + count + ": " + status + ":");
252 if (count != null && Integer.parseInt(count) > 0) {
253 context.setAttribute(count, null);
258 if (db.equals(SdcArtifactHandlerConstants.DB_DEVICE_AUTHENTICATION) && serviceLogic != null && context != null) {
259 log.info("Check for update or insert for properties file");
260 String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
261 String action = context.getAttribute(SdcArtifactHandlerConstants.ACTION);
262 String vnf_type = context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE);
263 PropertiesConfiguration conf = new PropertiesConfiguration(System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
265 if (StringUtils.isNotBlank(vnf_type)) {
267 if (StringUtils.isNotBlank(protocol)) {
268 if (StringUtils.isNotBlank(action)) {
269 property = vnf_type + "." + protocol + "." + action;
273 if (conf.subset(property )!=null) {
274 if (conf.containsKey(property )) {
275 log.info("Key Exists for property"+property +"in southbound.properties file");
279 log.info("Key Doesnot exists and need to add the key for property"+property +"in southbound.properties file");
285 public void processDeviceInterfaceProtocol(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
286 String fn = "DBService.processDeviceInterfaceProtocol";
287 log.info("Starting DB operation for Device Interface Protocol " + isUpdate);
289 QueryStatus status = null;
291 key = "update " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set PROTOCOL = $"
292 + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' "
293 + " , MODULE = 'APPC' " + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
295 key = "insert into " + SdcArtifactHandlerConstants.DB_DEVICE_INTERFACE_PROTOCOL + " set VNF_TYPE = $"
296 + SdcArtifactHandlerConstants.VNF_TYPE + " , PROTOCOL = $"
297 + SdcArtifactHandlerConstants.DEVICE_PROTOCOL + " , DG_RPC = 'getDeviceRunningConfig' "
298 + " , MODULE = 'APPC' ";
300 if (serviceLogic != null && context != null) {
302 status = serviceLogic.save("SQL", false, false, key, null, null, context);
303 if (status.toString().equals("FAILURE"))
304 throw new SvcLogicException("Error While processing DEVICE_INTERFACE_PROTOCOL table ");
309 public void processDeviceAuthentication(SvcLogicContext context, boolean isUpdate) throws SvcLogicException, ConfigurationException {
310 String fn = "DBService.processDeviceAuthentication";
311 log.info(fn + "Starting DB operation for Device Authentication " + isUpdate);
312 String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
313 String action = context.getAttribute(SdcArtifactHandlerConstants.ACTION);
314 String vnf_type = context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE);
315 String url = context.getAttribute(SdcArtifactHandlerConstants.URL);
316 String port = context.getAttribute(SdcArtifactHandlerConstants.PORT_NUMBER);
317 String user = context.getAttribute(SdcArtifactHandlerConstants.USER_NAME);
318 String property = vnf_type + "." +protocol + "." + action;
319 log.info("property :"+property);
320 if (StringUtils.isBlank(url)) {
323 if (StringUtils.isBlank(port) ) {
326 if (StringUtils.isBlank(user)) {
329 if (((vnf_type == null) || ("".equals(vnf_type))) && ((action == null) || ("".equals(action)))
330 && ((protocol == null) || ("".equals(protocol))))
331 throw new SvcLogicException(
332 "Error While processing refernce File as few or all of parameters VNF_TYPE,PROTOCOL,ACTION are missing ");
333 PropertiesConfiguration conf = new PropertiesConfiguration(System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
334 log.info("is Updating to southbound properties : "+isUpdate);
335 if (conf.containsKey(property + "." + "user")) {
336 if(user!=null && !user.isEmpty())
337 conf.setProperty(property + "." + "user", user);
339 log.info("is Adding to southbound.properties"+isUpdate);
341 conf.addProperty(property + "." + "user", user);
344 if (conf.containsKey(property + "." + "port")) {
345 if (port != null && !port.isEmpty())
346 conf.setProperty(property + "." + "port", port);
348 conf.addProperty(property + "." + "port", port);
350 if (conf.containsKey(property + "." + "password")) {
352 conf.addProperty(property + "." + "password", "");
354 if (conf.containsKey(property + "." + "url")) {
355 if (url != null && !url.isEmpty())
356 conf.setProperty(property + "." + "url", url);
360 conf.addProperty(property + "." + "url", url);
362 log.info("About to save to properties file");
364 log.info("saved to properties file");
367 public void processVnfcReference(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
368 String fn = "DBService.processVnfcReference";
369 log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate);
371 int vm_instance = -1;
372 if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null)
373 vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE));
374 int vnfc_instance = -1;
375 if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null)
376 vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE));
377 QueryStatus status = null;
379 key = "update " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VM_INSTANCE = " + vm_instance
380 + " , VNFC_INSTANCE = " + vnfc_instance + " , VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
381 + " , VNFC_FUNCTION_CODE = $" + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE
382 + " , GROUP_NOTATION_TYPE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE
383 + " , GROUP_NOTATION_VALUE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE
384 + " , IPADDRESS_V4_OAM_VIP = $" + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP
385 + " where VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE + " and ACTION = $"
386 + SdcArtifactHandlerConstants.ACTION + " and VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE
387 + " and VNFC_INSTANCE = $" + SdcArtifactHandlerConstants.VNFC_INSTANCE + " and VM_INSTANCE = $"
388 + SdcArtifactHandlerConstants.VM_INSTANCE;
390 key = "insert into " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VNF_TYPE = $"
391 + SdcArtifactHandlerConstants.VNF_TYPE + " , ACTION = $" + SdcArtifactHandlerConstants.ACTION
392 + " , VM_INSTANCE = $" + SdcArtifactHandlerConstants.VM_INSTANCE + " , VNFC_INSTANCE = $"
393 + SdcArtifactHandlerConstants.VNFC_INSTANCE + " , VNFC_TYPE = $"
394 + SdcArtifactHandlerConstants.VNFC_TYPE + " , VNFC_FUNCTION_CODE = $"
395 + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , GROUP_NOTATION_TYPE = $"
396 + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + " , IPADDRESS_V4_OAM_VIP = $"
397 + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + " , GROUP_NOTATION_VALUE = $"
398 + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE;
400 if (serviceLogic != null && context != null) {
401 status = serviceLogic.save("SQL", false, false, key, null, null, context);
402 if (status.toString().equals("FAILURE"))
403 throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
407 public void processDownloadDgReference(SvcLogicContext context, boolean isUpdate)
408 throws SvcLogicException, SQLException {
409 String fn = "DBService.processDownloadDgReference";
410 log.info(fn + "Starting DB operation for Download DG Reference " + isUpdate);
412 QueryStatus status = null;
415 key = "update " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $"
416 + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where PROTOCOL = $"
417 + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
419 key = "insert into " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE + " set DOWNLOAD_CONFIG_DG = $"
420 + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , PROTOCOL = $"
421 + SdcArtifactHandlerConstants.DEVICE_PROTOCOL;
423 if (serviceLogic != null && context != null)
424 status = serviceLogic.save("SQL", false, false, key, null, null, context);
425 if ((status == null) || status.toString().equals("FAILURE"))
426 throw new SvcLogicException("Error While processing DOWNLOAD_DG_REFERENCE table ");
429 public void processConfigActionDg(SvcLogicContext context, boolean isUpdate) throws SvcLogicException {
430 String fn = "DBService.processConfigActionDg";
431 log.info(fn + "Starting DB operation for Config DG Action " + isUpdate);
433 QueryStatus status = null;
435 if (context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE) != null
436 && context.getAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE).length() > 0) {
438 key = "update " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $"
439 + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " where ACTION = $"
440 + SdcArtifactHandlerConstants.ACTION + " and VNF_TYPE = $"
441 + SdcArtifactHandlerConstants.VNF_TYPE;
443 key = "insert into " + SdcArtifactHandlerConstants.DB_CONFIG_ACTION_DG + " set DOWNLOAD_CONFIG_DG = $"
444 + SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE + " , ACTION = $"
445 + SdcArtifactHandlerConstants.ACTION + " , VNF_TYPE = $" + SdcArtifactHandlerConstants.VNF_TYPE;
447 if (serviceLogic != null && context != null)
448 status = serviceLogic.save("SQL", false, false, key, null, null, context);
449 if ((status == null) || status.toString().equals("FAILURE"))
450 throw new SvcLogicException("Error While processing Configure DG Action table ");
452 log.info("No Update required for Config DG Action");
456 public String getModelDataInformationbyArtifactName(String artifact_name) throws SvcLogicException {
457 String fn = "DBService.getVnfData";
459 SvcLogicContext con = new SvcLogicContext();
460 HashMap<String, String> modelData = new HashMap<String, String>();
461 QueryStatus status = null;
462 key = "select VNF_TYPE, VNFC_TYPE, ACTION, FILE_CATEGORY, ARTIFACT_TYPE from ASDC_REFERENCE where ARTIFACT_NAME = "
465 if (serviceLogic != null && con != null) {
466 log.info(fn + "select Key: " + key);
467 status = serviceLogic.query("SQL", false, null, key, null, null, con);
468 if (status.toString().equals("FAILURE"))
469 throw new SvcLogicException("Error While processing is ArtifactUpdateRequiredforPD table ");
473 log.info(fn + "Vnf_received :" + con.getAttribute("VNF_TYPE"));
475 return con.getAttribute("VNF_TYPE");
479 public void updateYangContents(SvcLogicContext context, String artifactId, String yangContents)
480 throws SvcLogicException {
481 String fn = "DBService.updateYangContents";
482 log.info(fn + "Starting DB operation for updateYangContents");
484 QueryStatus status = null;
486 key = "update ASDC_ARTIFACTS " + " set ARTIFACT_CONTENT = '" + yangContents + "'"
487 + " where ASDC_ARTIFACTS_ID = " + artifactId;
489 if (serviceLogic != null && context != null)
490 status = serviceLogic.save("SQL", false, false, key, null, null, context);
491 if ((status == null) || status.toString().equals("FAILURE"))
492 throw new SvcLogicException("Error While processing Configure DG Action table ");
497 public void insertProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
498 String action_level, String template) throws SvcLogicException {
499 String fn = "DBService.insertProtocolReference";
500 log.info(fn + "Starting DB operation for insertProtocolReference");
502 QueryStatus status = null;
504 key = "insert into PROTOCOL_REFERENCE (ACTION, VNF_TYPE, PROTOCOL, UPDATED_DATE, TEMPLATE, ACTION_LEVEL)"
505 + " values (" + "'" + action + "', '" + vnfType + "', '" + protocol + "', now(),'" + template + "', '"
506 + action_level + "')";
508 if (serviceLogic != null && context != null)
509 status = serviceLogic.save("SQL", false, false, key, null, null, context);
510 if ((status == null) || status.toString().equals("FAILURE"))
511 throw new SvcLogicException("Error While processing insertProtocolReference ");
515 public boolean isProtocolReferenceUpdateRequired(SvcLogicContext context, String vnfType, String protocol,
516 String action, String action_level, String template) throws SvcLogicException {
517 SvcLogicContext localContext = new SvcLogicContext();
518 String fn = "DBService.isProtocolReferenceUpdateRequired";
519 log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired");
521 QueryStatus status = null;
523 key = "select COUNT(*) from PROTOCOL_REFERENCE where ACTION='" + action + "' and ACTION_LEVEL='" + action_level
524 + "' and VNF_TYPE='" + vnfType + "'";
525 status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
526 String countStr = localContext.getAttribute("COUNT(*)");
527 int count = Integer.parseInt(countStr);
534 public void updateProtocolReference(SvcLogicContext context, String vnfType, String protocol, String action,
535 String action_level, String template) throws SvcLogicException {
537 String fn = "DBService.isProtocolReferenceUpdateRequired";
538 log.info(fn + "Starting DB operation for isProtocolReferenceUpdateRequired");
540 QueryStatus status = null;
542 key = "update PROTOCOL_REFERENCE set UPDATED_DATE=now(), template='" + template + "' where ACTION='" + action
543 + "' and ACTION_LEVEL='" + action_level + "' and VNF_TYPE='" + vnfType + "'";
544 status = serviceLogic.save("SQL", false, false, key, null, null, context);
545 if (status == QueryStatus.FAILURE) {
546 log.info("updateProtocolReference:: Error updating protocol reference");
547 throw new SvcLogicException("Error - updating PROTOCOL_REFERENCE_TABLE in updateProtocolReference");
552 public String getDownLoadDGReference(SvcLogicContext context) throws SvcLogicException, ConfigurationException {
553 String fn = "DBService.setDownLoadDGReference";
554 String downloadConfigDg = null;
555 log.info(fn + "Setting Download DG Reference from DB");
557 QueryStatus status = null;
558 String protocol = context.getAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL);
559 if (StringUtils.isBlank(protocol)) {
560 log.info(fn + " :: Protocol is Blank!! Returning without querying DB");
561 throw new ConfigurationException(fn+":: Protocol is Blank!! Returning without querying DB");
563 key = "select download_config_dg from " + SdcArtifactHandlerConstants.DB_DOWNLOAD_DG_REFERENCE
564 + " where protocol = '" + protocol + "'";
565 SvcLogicContext localContext = new SvcLogicContext();
566 status = serviceLogic.query("SQL", false, null, key, null, null, localContext);
567 if (status == QueryStatus.FAILURE) {
568 log.info(fn + ":: Error retrieving download_config_dg");
569 throw new SvcLogicException("Error retrieving download_config_dg");
571 if (status == QueryStatus.NOT_FOUND) {
572 log.info(fn + ":: NOT_FOUND! No data found for download_config_dg!!");
573 throw new SvcLogicException(fn + ":: NOT_FOUND! No data found for download_config_dg!");
575 downloadConfigDg = localContext.getAttribute("download-config-dg");
576 log.info(fn + "download_config_dg::" + downloadConfigDg);
577 return downloadConfigDg;
580 public void cleanUpVnfcReferencesForVnf(SvcLogicContext context) throws SvcLogicException {
582 String key1 = "delete from " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE
583 + " where action = $"+ SdcArtifactHandlerConstants.ACTION + " and vnf_type = $" + SdcArtifactHandlerConstants.VNF_TYPE;
584 log.debug("Action : " + context.getAttribute(SdcArtifactHandlerConstants.ACTION));
585 log.debug("vnfType: "+ context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));
586 QueryStatus status = null;
587 log.info("cleanUpVnfcReferencesForVnf()::Query:" + key1);
588 if (serviceLogic != null && context != null) {
589 status = serviceLogic.save("SQL", false, false, key1, null, null, context);
590 if (status.toString().equals("FAILURE")) {
591 log.debug("Error deleting from VNFC_REFERENCE table");
592 throw new SvcLogicException("Error While processing VNFC_REFERENCE table ");
597 log.debug("Error deleting from VNFC_REFERENCE table : "+context.getAttribute(SdcArtifactHandlerConstants.ACTION) +" and " +context.getAttribute(SdcArtifactHandlerConstants.VNF_TYPE));