Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,18 @@
public class SaveAndRestoreJerseyClient implements org.phoebus.applications.saveandrestore.client.SaveAndRestoreClient {

private static final String CONTENT_TYPE_JSON = "application/json; charset=UTF-8";
private final Logger logger = Logger.getLogger(SaveAndRestoreJerseyClient.class.getName());
private static final Logger logger = Logger.getLogger(SaveAndRestoreJerseyClient.class.getName());

private static final int DEFAULT_READ_TIMEOUT = 5000; // ms
private static final int DEFAULT_CONNECT_TIMEOUT = 5000; // ms

ObjectMapper mapper = new ObjectMapper();
private static final ObjectMapper mapper = new ObjectMapper();

private HTTPBasicAuthFilter httpBasicAuthFilter;
private static final Client client;

public SaveAndRestoreJerseyClient() {

mapper.registerModule(new JavaTimeModule());
mapper.setSerializationInclusion(Include.NON_NULL);
}
private static HTTPBasicAuthFilter httpBasicAuthFilter;

private Client getClient() {
static {
int httpClientReadTimeout = Preferences.httpClientReadTimeout > 0 ? Preferences.httpClientReadTimeout : DEFAULT_READ_TIMEOUT;
logger.log(Level.INFO, "Save&restore client using read timeout " + httpClientReadTimeout + " ms");

Expand All @@ -73,7 +69,7 @@ private Client getClient() {
JacksonJsonProvider jacksonJsonProvider = new JacksonJsonProvider(mapper);
defaultClientConfig.getSingletons().add(jacksonJsonProvider);

Client client = Client.create(defaultClientConfig);
client = Client.create(defaultClientConfig);

try {
SecureStore store = new SecureStore();
Expand All @@ -89,8 +85,11 @@ private Client getClient() {
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to retrieve credentials from secure store", e);
}
}

return client;
public SaveAndRestoreJerseyClient() {
mapper.registerModule(new JavaTimeModule());
mapper.setSerializationInclusion(Include.NON_NULL);
}

@Override
Expand All @@ -110,7 +109,7 @@ public Node getNode(String uniqueNodeId) {

@Override
public List<Node> getCompositeSnapshotReferencedNodes(String uniqueNodeId) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/nodes");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/nodes");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -129,7 +128,7 @@ public List<Node> getCompositeSnapshotReferencedNodes(String uniqueNodeId) {

@Override
public List<SnapshotItem> getCompositeSnapshotItems(String uniqueNodeId) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/items");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot/" + uniqueNodeId + "/items");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand Down Expand Up @@ -160,7 +159,7 @@ public List<Node> getChildNodes(String uniqueNodeId) throws SaveAndRestoreClient

@Override
public Node createNewNode(String parentNodeId, Node node) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/node")
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/node")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(node, CONTENT_TYPE_JSON)
Expand All @@ -184,7 +183,7 @@ public Node updateNode(Node nodeToUpdate) {

@Override
public Node updateNode(Node nodeToUpdate, boolean customTimeForMigration) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/node")
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/node")
.queryParam("customTimeForMigration", customTimeForMigration ? "true" : "false");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -210,7 +209,7 @@ private <T> T getCall(String relativeUrl, Class<T> clazz) {
}

private ClientResponse getCall(String relativeUrl) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + relativeUrl);
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + relativeUrl);

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -228,7 +227,7 @@ private ClientResponse getCall(String relativeUrl) {

@Override
public void deleteNodes(List<String> nodeIds) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/node");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/node");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(nodeIds, CONTENT_TYPE_JSON)
.delete(ClientResponse.class);
Expand All @@ -255,7 +254,7 @@ public List<Node> getAllSnapshots() {
@Override
public Node moveNodes(List<String> sourceNodeIds, String targetNodeId) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/move")
client.resource(Preferences.jmasarServiceUrl + "/move")
.queryParam("to", targetNodeId);

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -277,7 +276,7 @@ public Node moveNodes(List<String> sourceNodeIds, String targetNodeId) {
@Override
public Node copyNodes(List<String> sourceNodeIds, String targetNodeId) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/copy")
client.resource(Preferences.jmasarServiceUrl + "/copy")
.queryParam("to", targetNodeId);

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -299,7 +298,7 @@ public Node copyNodes(List<String> sourceNodeIds, String targetNodeId) {
@Override
public String getFullPath(String uniqueNodeId) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/path/" + uniqueNodeId);
client.resource(Preferences.jmasarServiceUrl + "/path/" + uniqueNodeId);
ClientResponse response = webResource.get(ClientResponse.class);

if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -322,7 +321,7 @@ public ConfigurationData getConfigurationData(String nodeId) {
@Override
public Configuration createConfiguration(String parentNodeId, Configuration configuration) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/config")
client.resource(Preferences.jmasarServiceUrl + "/config")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(configuration, CONTENT_TYPE_JSON)
Expand All @@ -341,7 +340,7 @@ public Configuration createConfiguration(String parentNodeId, Configuration conf

@Override
public Configuration updateConfiguration(Configuration configuration) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/config");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/config");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(configuration, CONTENT_TYPE_JSON)
Expand All @@ -367,7 +366,7 @@ public SnapshotData getSnapshotData(String nodeId) {
@Override
public Snapshot createSnapshot(String parentNodeId, Snapshot snapshot) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/snapshot")
client.resource(Preferences.jmasarServiceUrl + "/snapshot")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response;
try {
Expand All @@ -392,7 +391,7 @@ public Snapshot createSnapshot(String parentNodeId, Snapshot snapshot) {
@Override
public Snapshot updateSnapshot(Snapshot snapshot) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/snapshot");
client.resource(Preferences.jmasarServiceUrl + "/snapshot");
ClientResponse response;
try {
response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -417,7 +416,7 @@ public Snapshot updateSnapshot(Snapshot snapshot) {
@Override
public CompositeSnapshot createCompositeSnapshot(String parentNodeId, CompositeSnapshot compositeSnapshot) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot")
client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot")
.queryParam("parentNodeId", parentNodeId);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(compositeSnapshot, CONTENT_TYPE_JSON)
Expand All @@ -437,7 +436,7 @@ public CompositeSnapshot createCompositeSnapshot(String parentNodeId, CompositeS
@Override
public List<String> checkCompositeSnapshotConsistency(List<String> snapshotNodeIds) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot-consistency-check");
client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot-consistency-check");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(snapshotNodeIds, CONTENT_TYPE_JSON)
.post(ClientResponse.class);
Expand All @@ -456,7 +455,7 @@ public List<String> checkCompositeSnapshotConsistency(List<String> snapshotNodeI

@Override
public CompositeSnapshot updateCompositeSnapshot(CompositeSnapshot compositeSnapshot) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/composite-snapshot");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/composite-snapshot");

ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(compositeSnapshot, CONTENT_TYPE_JSON)
Expand All @@ -475,7 +474,7 @@ public CompositeSnapshot updateCompositeSnapshot(CompositeSnapshot compositeSnap

@Override
public SearchResult search(MultivaluedMap<String, String> searchParams) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/search")
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/search")
.queryParams(searchParams);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.get(ClientResponse.class);
Expand All @@ -493,7 +492,7 @@ public SearchResult search(MultivaluedMap<String, String> searchParams) {

@Override
public Filter saveFilter(Filter filter) {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/filter");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/filter");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.entity(filter, CONTENT_TYPE_JSON)
.put(ClientResponse.class);
Expand All @@ -511,7 +510,7 @@ public Filter saveFilter(Filter filter) {

@Override
public List<Filter> getAllFilters() {
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/filters");
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/filters");
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -531,7 +530,7 @@ public List<Filter> getAllFilters() {
public void deleteFilter(String name) {
// Filter name may contain space chars, need to URL encode these.
String filterName = name.replace(" ", "%20");
WebResource webResource = getClient().resource(Preferences.jmasarServiceUrl + "/filter/" + filterName);
WebResource webResource = client.resource(Preferences.jmasarServiceUrl + "/filter/" + filterName);
ClientResponse response = webResource.accept(CONTENT_TYPE_JSON)
.delete(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode()) {
Expand All @@ -555,7 +554,7 @@ public void deleteFilter(String name) {
public List<Node> addTag(TagData tagData) {

WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/tags");
client.resource(Preferences.jmasarServiceUrl + "/tags");
ClientResponse response;
try {
response = webResource.accept(CONTENT_TYPE_JSON)
Expand Down Expand Up @@ -586,7 +585,7 @@ public List<Node> addTag(TagData tagData) {
*/
public List<Node> deleteTag(TagData tagData) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/tags");
client.resource(Preferences.jmasarServiceUrl + "/tags");
ClientResponse response;
try {
response = webResource.accept(CONTENT_TYPE_JSON)
Expand All @@ -611,7 +610,7 @@ public List<Node> deleteTag(TagData tagData) {
@Override
public UserData authenticate(String userName, String password) {
WebResource webResource =
getClient().resource(Preferences.jmasarServiceUrl + "/login")
client.resource(Preferences.jmasarServiceUrl + "/login")
.queryParam("username", userName)
.queryParam("password", password);
ClientResponse response;
Expand Down