diff options
author | Thomas Nelson Jr <tn1381@att.com> | 2018-08-08 00:17:33 +0000 |
---|---|---|
committer | Thomas Nelson Jr <tn1381@att.com> | 2018-08-08 00:17:33 +0000 |
commit | 64b04604921670862993fb2a72a895a6209947d5 (patch) | |
tree | 9e98c091e30c7c7fd2708588d40af56e7d38733e /src/main/java/org/onap/music/datastore | |
parent | 9b6efbd93a12c858a0d2643013217ec3d6c3a46d (diff) |
Updates to Callback Api and Connection
Change-Id: I6a3f0537a616ae4d54b47fa2c70ba5128e39f123
Issue-ID: MUSIC-92
Signed-off-by: Thomas Nelson Jr <tn1381@att.com>
Diffstat (limited to 'src/main/java/org/onap/music/datastore')
-rw-r--r-- | src/main/java/org/onap/music/datastore/MusicDataStore.java | 53 | ||||
-rw-r--r-- | src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java | 115 |
2 files changed, 161 insertions, 7 deletions
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java index 563e07f5..7557247d 100644 --- a/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -42,8 +42,10 @@ import com.datastax.driver.core.ColumnDefinitions; import com.datastax.driver.core.ColumnDefinitions.Definition; import com.datastax.driver.core.ConsistencyLevel; import com.datastax.driver.core.DataType; +import com.datastax.driver.core.HostDistance; import com.datastax.driver.core.KeyspaceMetadata; import com.datastax.driver.core.Metadata; +import com.datastax.driver.core.PoolingOptions; import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; @@ -149,16 +151,35 @@ public class MusicDataStore { * clusters. */ private void connectToCassaCluster() { - Iterator<String> it = getAllPossibleLocalIps().iterator(); + Iterator<String> it = getAllPossibleLocalIps().iterator(); String address = "localhost"; + String[] addresses = null; + address = MusicUtil.getMyCassaHost(); + addresses = address.split(","); + logger.info(EELFLoggerDelegate.applicationLogger, "Connecting to cassa cluster: Iterating through possible ips:" + getAllPossibleLocalIps()); + PoolingOptions poolingOptions = new PoolingOptions(); + poolingOptions + .setConnectionsPerHost(HostDistance.LOCAL, 4, 10) + .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); while (it.hasNext()) { try { - cluster = Cluster.builder().withPort(9042) - .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) - .addContactPoint(address).build(); + if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { + logger.info(EELFLoggerDelegate.applicationLogger, + "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd()); + cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) + .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); + } + else + cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .addContactPoints(addresses).build(); + Metadata metadata = cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " + metadata.getClusterName() + " at " + address); @@ -185,9 +206,27 @@ public class MusicDataStore { * @param address */ private void connectToCassaCluster(String address) throws MusicServiceException { - cluster = Cluster.builder().withPort(9042) - .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) - .addContactPoint(address).build(); + String[] addresses = null; + addresses = address.split(","); + PoolingOptions poolingOptions = new PoolingOptions(); + poolingOptions + .setConnectionsPerHost(HostDistance.LOCAL, 4, 10) + .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); + if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { + logger.info(EELFLoggerDelegate.applicationLogger, + "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd()); + cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) + .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); + } + else { + cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort()) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); + } Metadata metadata = cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " + metadata.getClusterName() + " at " + address); diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java new file mode 100644 index 00000000..42b12f10 --- /dev/null +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java @@ -0,0 +1,115 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * 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.music.datastore.jsonobjects; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "JsonCallback", description = "Json model for callback") +@JsonIgnoreProperties(ignoreUnknown = true) +public class JsonCallback implements Serializable { + private String applicationName; + private String applicationUsername; + private String applicationPassword; + private String applicationNotificationEndpoint; + private String notifyOn; + private String notifyWhenChangeIn; + private String notifyWhenInsertsIn; + private String notifyWhenDeletesIn; + + @ApiModelProperty(value = "application name") + public String getApplicationName() { + return applicationName; + } + + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } + + @ApiModelProperty(value = "notify On") + public String getNotifyOn() { + return notifyOn; + } + + public void setNotifyOn(String notifyOn) { + this.notifyOn = notifyOn; + } + + @ApiModelProperty(value = "application User name") + public String getApplicationUsername() { + return applicationUsername; + } + + public void setApplicationUsername(String applicationUsername) { + this.applicationUsername = applicationUsername; + } + + @ApiModelProperty(value = "application password") + public String getApplicationPassword() { + return applicationPassword; + } + + public void setApplicationPassword(String applicationPassword) { + this.applicationPassword = applicationPassword; + } + + @ApiModelProperty(value = "application notification endpoint") + public String getApplicationNotificationEndpoint() { + return applicationNotificationEndpoint; + } + + public void setApplicationNotificationEndpoint(String applicationNotificationEndpoint) { + this.applicationNotificationEndpoint = applicationNotificationEndpoint; + } + + @ApiModelProperty(value = "notify when updates") + public String getNotifyWhenChangeIn() { + return notifyWhenChangeIn; + } + + public void setNotifyWhenChangeIn(String notifyWhenChangeIn) { + this.notifyWhenChangeIn = notifyWhenChangeIn; + } + + @ApiModelProperty(value = "notify when inserts") + public String getNotifyWhenInsertsIn() { + return notifyWhenInsertsIn; + } + + public void setNotifyWhenInsertsIn(String notifyWhenInsertsIn) { + this.notifyWhenInsertsIn = notifyWhenInsertsIn; + } + + @ApiModelProperty(value = "notify when deletes") + public String getNotifyWhenDeletesIn() { + return notifyWhenDeletesIn; + } + + public void setNotifyWhenDeletesIn(String notifyWhenDeletesIn) { + this.notifyWhenDeletesIn = notifyWhenDeletesIn; + } + +} |