diff options
Diffstat (limited to 'src')
7 files changed, 84 insertions, 96 deletions
diff --git a/src/main/java/org/onap/music/JerseyConfig.java b/src/main/java/org/onap/music/JerseyConfig.java index 74958363..1b5f034a 100755 --- a/src/main/java/org/onap/music/JerseyConfig.java +++ b/src/main/java/org/onap/music/JerseyConfig.java @@ -1,64 +1,55 @@ -/* - * Copyright 2012-2015 the original author or authors. - * - * 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. - */ - -package org.onap.music; - -import javax.annotation.PostConstruct; -import javax.ws.rs.ApplicationPath; -import org.glassfish.jersey.server.ResourceConfig; -import org.onap.music.rest.RestMusicAdminAPI; -import org.onap.music.rest.RestMusicDataAPI; -import org.onap.music.rest.RestMusicHealthCheckAPI; -import org.onap.music.rest.RestMusicLocksAPI; -import org.onap.music.rest.RestMusicQAPI; -import org.onap.music.rest.RestMusicTestAPI; -import org.onap.music.rest.RestMusicVersionAPI; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +/* + * Copyright 2012-2015 the original author or authors. + * + * 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. + */ + +package org.onap.music; + import io.swagger.jaxrs.config.BeanConfig; import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; - -@Component -public class JerseyConfig extends ResourceConfig { - - @Value("${spring.jersey.application-path:/}") - private String apiPath; - - public JerseyConfig() { +import io.swagger.jaxrs.listing.SwaggerSerializers; +import org.glassfish.jersey.server.ResourceConfig; +import org.onap.music.rest.*; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component public class JerseyConfig extends ResourceConfig { + + @Value("${spring.jersey.application-path:/}") private String apiPath; + + public JerseyConfig() { this.registerEndpoints(); - } - - @PostConstruct - public void init() { + } + + @PostConstruct public void init() { this.configureSwagger(); } - + private void registerEndpoints() { - register(RestMusicAdminAPI.class); - register(RestMusicDataAPI.class); - register(RestMusicLocksAPI.class); - register(RestMusicQAPI.class); - register(RestMusicTestAPI.class); + register(RestMusicAdminAPI.class); + register(RestMusicDataAPI.class); + register(RestMusicLocksAPI.class); + register(RestMusicQAPI.class); + register(RestMusicTestAPI.class); register(RestMusicVersionAPI.class); register(RestMusicHealthCheckAPI.class); } - + private void configureSwagger() { - // Available at localhost:port/swagger.json + //Available at localhost:port/swagger.json this.register(ApiListingResource.class); this.register(SwaggerSerializers.class); @@ -67,11 +58,11 @@ public class JerseyConfig extends ResourceConfig { config.setTitle("MUSIC"); config.setVersion("v2"); config.setContact("Thomas Nelson"); - config.setSchemes(new String[] { "http", "https" }); + config.setSchemes(new String[] {"http", "https"}); config.setBasePath("/MUSIC/rest"); config.setResourcePackage("org.onap.music"); config.setPrettyPrint(true); config.setScan(true); } - + } diff --git a/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java b/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java index 93c44468..3e962a02 100644 --- a/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java +++ b/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java @@ -3,6 +3,8 @@ * org.onap.music * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property + * + * Modifications Copyright (C) 2019 IBM. * =================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,9 +67,7 @@ public class MusicHealthCheck { try { result = getAdminKeySpace(consistency); } catch (MusicServiceException e1) { - // TODO Auto-generated catch block - logger.error("Error", e); - e1.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN); } } else { logger.error("Error", e); @@ -106,9 +106,7 @@ public class MusicHealthCheck { try { rs = MusicCore.nonKeyRelatedPut(pQuery, ConsistencyLevel.ONE.toString()); } catch (MusicServiceException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - logger.error("Error", e); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN); } if(rs != null && rs.getResult().toLowerCase().contains("success")) return true; diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java index 9c975191..db74aceb 100755 --- a/src/main/java/org/onap/music/main/CachingUtil.java +++ b/src/main/java/org/onap/music/main/CachingUtil.java @@ -5,6 +5,7 @@ * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== * Modifications Copyright (c) 2018 IBM + * Modifications Copyright (c) 2019 Samsung * =================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,10 +37,6 @@ import javax.ws.rs.core.MediaType; import org.apache.commons.codec.binary.Base64; import org.apache.commons.jcs.JCS; import org.apache.commons.jcs.access.CacheAccess; -import org.apache.commons.jcs.engine.CompositeCacheAttributes; -import org.apache.commons.jcs.engine.ElementAttributes; -import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes; -import org.apache.commons.jcs.engine.behavior.IElementAttributes; import org.mindrot.jbcrypt.BCrypt; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.eelf.logging.EELFLoggerDelegate; @@ -47,7 +44,6 @@ import org.onap.music.eelf.logging.format.AppMessages; import org.onap.music.eelf.logging.format.ErrorSeverity; import org.onap.music.eelf.logging.format.ErrorTypes; import org.onap.music.exceptions.MusicServiceException; -import org.onap.music.service.impl.MusicZKCore; import com.datastax.driver.core.DataType; import com.datastax.driver.core.PreparedStatement; @@ -133,7 +129,6 @@ public class CachingUtil implements Runnable { pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false)); } catch (Exception e1) { logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR); - e1.printStackTrace(); } ResultSet rs = MusicCore.get(pQuery); Iterator<Row> it = rs.iterator(); @@ -158,7 +153,6 @@ public class CachingUtil implements Runnable { } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR); logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. "); - e.printStackTrace(); } } @@ -317,7 +311,6 @@ public class CachingUtil implements Runnable { appNameCache.put(namespace, isAAF); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR); - e.printStackTrace(); } } return isAAF; @@ -334,8 +327,7 @@ public class CachingUtil implements Runnable { try { uuid = rs.getUUID("uuid").toString(); } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage()); - e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger,"Exception occurred during uuid retrieval from DB."+e.getMessage()); } } return uuid; @@ -352,7 +344,6 @@ public class CachingUtil implements Runnable { appName = rs.getString("application_name"); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR); - e.printStackTrace(); } return appName; } @@ -398,9 +389,9 @@ public class CachingUtil implements Runnable { try { rs = MusicCore.get(queryObject).one(); } catch (MusicServiceException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage()); + String errorMsg = "Unable to process operation. Error is "+e.getMessage(); + logger.error(EELFLoggerDelegate.errorLogger, errorMsg); + resultMap.put("Exception", errorMsg); return resultMap; } catch (InvalidQueryException e) { logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage()); @@ -443,14 +434,15 @@ public class CachingUtil implements Runnable { try { queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace)); } catch (Exception e) { - e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger,"Adding value to query object failed: " + e.getMessage()); } Row rs = null; try { rs = MusicCore.get(queryObject).one(); } catch (MusicServiceException e) { - e.printStackTrace(); - resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage()); + String errMsg = "Unable to process operation. Error is "+e.getMessage(); + logger.error(EELFLoggerDelegate.errorLogger, errMsg); + resultMap.put("Exception", errMsg); return resultMap; } if(rs == null) { @@ -486,7 +478,8 @@ public class CachingUtil implements Runnable { try { MusicCore.nonKeyRelatedPut(pQuery, "eventual"); } catch (Exception e) { - e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), "Deleting keys from " + + "DB failed."); } } } diff --git a/src/main/java/org/onap/music/main/CronJobManager.java b/src/main/java/org/onap/music/main/CronJobManager.java index 9cd9f33f..ea2fa685 100644 --- a/src/main/java/org/onap/music/main/CronJobManager.java +++ b/src/main/java/org/onap/music/main/CronJobManager.java @@ -4,6 +4,8 @@ * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== * 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 @@ -25,12 +27,6 @@ package org.onap.music.main; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Iterator; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.annotation.WebListener; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.eelf.logging.EELFLoggerDelegate; @@ -52,13 +48,13 @@ public class CronJobManager { private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - + @Scheduled(cron = "0 0 0 * * ?") public void scheduleTaskWithFixedRate() { logger.info("Executing cronjob to cleanup locks..", dateTimeFormatter.format(LocalDateTime.now()) ); deleteLocksFromDB(); } - + public void deleteLocksFromDB() { PreparedQueryObject pQuery = new PreparedQueryObject(); String consistency = MusicUtil.EVENTUAL; @@ -69,10 +65,9 @@ public class CronJobManager { logger.error(EELFLoggerDelegate.errorLogger,"Error creating Admin.locks table.",AppMessages.QUERYERROR,ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR); } } catch (MusicServiceException e1) { - logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(),AppMessages.QUERYERROR,ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR); - e1.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger,e1,AppMessages.QUERYERROR,ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR); } - + pQuery = new PreparedQueryObject(); pQuery.appendQueryString( "select * from admin.locks"); @@ -82,7 +77,7 @@ public class CronJobManager { StringBuilder deleteKeys = new StringBuilder(); Boolean expiredKeys = false; while (it.hasNext()) { - Row row = (Row) it.next(); + Row row = it.next(); String id = row.getString("lock_id"); long ctime = Long.parseLong(row.getString("ctime")); if(System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) { @@ -102,8 +97,7 @@ public class CronJobManager { CachingUtil.deleteKeysFromDB(deleteKeys.toString()); } } catch (MusicServiceException e) { - logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(),AppMessages.CACHEERROR,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR); - e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger,e,AppMessages.CACHEERROR,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR); } } } diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java index 507bcd40..0010ed1a 100755 --- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java @@ -4,6 +4,8 @@ * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== * 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 @@ -404,9 +406,10 @@ public class RestMusicDataAPI { @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception { try { ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion); - if((keyspace == null || keyspace == null) || (tablename.isEmpty() || tablename.isEmpty())){ + if(keyspace == null || keyspace.isEmpty() || tablename == null || tablename.isEmpty()){ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) - .setError("one or more path parameters are not set, please check and try again") + .setError("One or more path parameters are not set, please check and try again." + + "Parameter values: keyspace='" + keyspace + "' tablename='" + tablename + "'") .toMap()).build(); } EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) "); diff --git a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java index f351789e..21b4874b 100644 --- a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java +++ b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java @@ -3,6 +3,7 @@ * org.onap.music * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property + * Modifications Copyright (c) 2018 IBM. * =================================================================== * Modifications Copyright (c) 2019 Samsung * =================================================================== @@ -163,7 +164,7 @@ public class MusicCassaCore implements MusicCoreService { String keyspace = splitString[0].substring(1);//remove '$' String table = splitString[1]; String primaryKeyValue = splitString[2].substring(0, splitString[2].lastIndexOf("$")); - fullyQualifiedKey = lockId.substring(1, lockId.lastIndexOf("$")); + String localFullyQualifiedKey = lockId.substring(1, lockId.lastIndexOf("$")); String lockRef = lockId.substring(lockId.lastIndexOf("$")+1); //lockRef is "$" to end ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue, lockRef); @@ -173,7 +174,7 @@ public class MusicCassaCore implements MusicCoreService { //check to see if the value of the key has to be synced in case there was a forceful release String syncTable = keyspace+".unsyncedKeys_"+table; - String query = "select * from "+syncTable+" where key='"+fullyQualifiedKey+"';"; + String query = "select * from "+syncTable+" where key='"+localFullyQualifiedKey+"';"; PreparedQueryObject readQueryObject = new PreparedQueryObject(); readQueryObject.appendQueryString(query); ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(readQueryObject); @@ -187,7 +188,7 @@ public class MusicCassaCore implements MusicCoreService { String exceptionAsString = sw.toString(); return new ReturnType(ResultType.FAILURE, "Exception thrown while syncing key:\n" + exceptionAsString); } - String cleanQuery = "delete from music_internal.unsynced_keys where key='"+fullyQualifiedKey+"';"; + String cleanQuery = "delete from music_internal.unsynced_keys where key='"+localFullyQualifiedKey+"';"; PreparedQueryObject deleteQueryObject = new PreparedQueryObject(); deleteQueryObject.appendQueryString(cleanQuery); MusicDataStoreHandle.getDSHandle().executePut(deleteQueryObject, "critical"); diff --git a/src/test/java/org/onap/music/unittests/TestRestAdminData.java b/src/test/java/org/onap/music/unittests/TestRestAdminData.java index 0471d6f0..2708b64b 100644 --- a/src/test/java/org/onap/music/unittests/TestRestAdminData.java +++ b/src/test/java/org/onap/music/unittests/TestRestAdminData.java @@ -2568,4 +2568,12 @@ public class TestRestAdminData { appName, authorization, keyspaceName, tableNameConditional, json); assertEquals(401, response.getStatus()); } + @Test + public void Test8_HealthCheck_cassandra_musicHealthCheck() { + RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); + Response response = healthCheck.musicHealthCheck(); + assertEquals(200, response.getStatus()); + } + + }
\ No newline at end of file |