Skip to content

Commit

Permalink
KYLO-2966: Fix Nifi service down reporting to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
harschware committed Nov 6, 2018
1 parent df66e7c commit 105140e
Show file tree
Hide file tree
Showing 23 changed files with 549 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.ws.rs.NotAcceptableException;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class JerseyRestClient {
* @see #JerseyRestClient(JerseyClientConfig)
*/
protected String uri;

/**
* The username to use to connect set by configuration of the REST Client
* The constructor will set this value using {@link JerseyClientConfig#username}
Expand Down Expand Up @@ -410,20 +412,18 @@ public <T> T get(WebTarget target, Class<T> clazz) {
* @return the returned object of the specified Class
*/
public <T> T get(Invocation.Builder builder, Class<T> clazz, boolean logError) {
T obj = null;

try {
obj = builder.accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).get(clazz);
return builder.accept(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE).get(clazz);
} catch (Exception e) {
if (e instanceof NotAcceptableException) {
obj = handleNotAcceptableGetRequestJsonException(builder, clazz);
return handleNotAcceptableGetRequestJsonException(builder, clazz);
} else {
if (logError) {
log.error("Failed to process request " + builder, e);
}
throw e; // NOTE: includes ProcessingException that can occur when service is down.
}
}
return obj;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
/**
* Exception thrown when a template is unable to be created
*/
public class TemplateCreationException extends RuntimeException {

public class TemplateCreationException extends TemplateException {

/**
* @param message
Expand All @@ -37,6 +36,6 @@ public TemplateCreationException(String message) {
* @param cause
*/
public TemplateCreationException(String message, Throwable cause) {
super(cause);
super(message,cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.thinkbiganalytics.nifi.feedmgr;

/*-
* #%L
* thinkbig-nifi-rest-client-api
* %%
* Copyright (C) 2017 ThinkBig Analytics
* %%
* 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.
* #L%
*/

/**
* Exception thrown when a template is unable to be created
*/
public class TemplateException extends RuntimeException {

/**
* @param message
*/
public TemplateException(String message) {
super(message);
}

/**
* @param cause
*/
public TemplateException(String message, Throwable cause) {
super(message,cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.thinkbiganalytics.nifi.feedmgr;

/*-
* #%L
* thinkbig-nifi-rest-client-api
* %%
* Copyright (C) 2017 ThinkBig Analytics
* %%
* 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.
* #L%
*/

/**
* Exception thrown when a template is unable to be created
*/
public class TemplateExportException extends TemplateException {

/**
* @param message
*/
public TemplateExportException(String message) {
super(message);
}

/**
* @param cause
*/
public TemplateExportException(String message, Throwable cause) {
super(message,cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.thinkbiganalytics.nifi.feedmgr;

/*-
* #%L
* thinkbig-nifi-rest-client-api
* %%
* Copyright (C) 2017 ThinkBig Analytics
* %%
* 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.
* #L%
*/

/**
* Exception thrown when a template is unable to be created
*/
public class TemplateImportException extends TemplateException {

/**
* @param message
*/
public TemplateImportException(String message) {
super(message);
}

/**
* @param cause
*/
public TemplateImportException(String message, Throwable cause) {
super(message,cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* 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.
Expand All @@ -23,7 +23,6 @@
import com.thinkbiganalytics.nifi.rest.client.NiFiRestClient;
import com.thinkbiganalytics.nifi.rest.client.NifiRestClientConfig;
import com.thinkbiganalytics.nifi.rest.model.NiFiPropertyDescriptorTransform;
import com.thinkbiganalytics.nifi.v1.rest.client.NiFiRestClientV1;
import com.thinkbiganalytics.nifi.v1.rest.client.NiFiRestClientV1_2;
import com.thinkbiganalytics.nifi.v1.rest.model.NiFiPropertyDescriptorTransformV1;

Expand All @@ -37,7 +36,7 @@
* Configures a {@link NiFiRestClient} for NiFi v1.2+.
*/
@Configuration
@Profile({"nifi-v1.2","nifi-v1.3","nifi-v1.4","nifi-v1.5"})
@Profile({"nifi-v1.2", "nifi-v1.3", "nifi-v1.4", "nifi-v1.5"})
public class SpringNiFiRestConfigurationV1_2 {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package com.thinkbiganalytics.nifi.v1.rest.client;

/*-
* #%L
* kylo-nifi-rest-client-v1
* %%
* Copyright (C) 2017 - 2018 ThinkBig Analytics, a Teradata Company
* %%
* 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.
* #L%
*/

import com.thinkbiganalytics.rest.JerseyClientConfig;
import com.thinkbiganalytics.rest.JerseyRestClient;

import org.glassfish.jersey.media.multipart.MultiPart;

import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.Future;

import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import static com.thinkbiganalytics.nifi.v1.rest.util.CatchNifiConnectionExceptionsUtil.catchConnectionExceptions;

public class NiFiJerseyRestClient extends JerseyRestClient {

public NiFiJerseyRestClient(JerseyClientConfig config) {
super(config);
}

@Override
public <T> Future<T> getAsync(String path, Map<String, Object> params, Class<T> clazz) {
return catchConnectionExceptions(super::getAsync, path, params, clazz);
}

@Override
public <T> Future<T> getAsync(String path, Map<String, Object> params, GenericType<T> type) {
return catchConnectionExceptions(super::getAsync, path, params, type);
}

@Override
public <T> T get(Invocation.Builder builder, Class<T> clazz) {
return catchConnectionExceptions(super::get, builder, clazz);
}

@Override
public <T> T get(WebTarget target, Class<T> clazz) {
return catchConnectionExceptions(super::get, target, clazz);
}

@Override
public <T> T get(Invocation.Builder builder, Class<T> clazz, boolean logError) {
return catchConnectionExceptions(super::get, builder, clazz, logError);
}

@Override
public <T> T get(WebTarget target, Class<T> clazz, boolean logError) {
return catchConnectionExceptions(super::get, target, clazz, logError);
}

@Override
public <T> T get(String path, Map<String, Object> params, Class<T> clazz) {
return catchConnectionExceptions(super::get, path, params, clazz);
}

@Override
public <T> T get(String path, Map<String, Object> params, Class<T> clazz, boolean logError) {
return catchConnectionExceptions(super::get, path, params, clazz, logError);
}

@Override
public <T> T getWithHeaders(String path, MultivaluedMap<String, Object> headers, Map<String, Object> params, Class<T> clazz) {
return catchConnectionExceptions(super::getWithHeaders, path, headers, params, clazz);
}

@Override
public <T> T getWithoutErrorLogging(String path, Map<String, Object> params, Class<T> clazz) {
return catchConnectionExceptions(super::getWithoutErrorLogging, path, params, clazz);
}

@Override
public <T> T getFromPathString(String path, Class<T> clazz) {
return catchConnectionExceptions(super::getFromPathString, path, clazz);
}

@Override
public <T> T get(String path, Class<T> clazz) {
return catchConnectionExceptions(super::get, path, clazz);
}

@Override
public <T> T get(String path, Map<String, Object> params, GenericType<T> type) {
return catchConnectionExceptions(super::get, path, params, type);
}

@Override
public Response post(String path, Object o) {
return catchConnectionExceptions(super::post, path, o);
}

@Override
public <T> T postMultiPart(String path, MultiPart object, Class<T> returnType) {
return catchConnectionExceptions(super::postMultiPart, path, object, returnType);
}

@Override
public <T> T postMultiPartStream(String path, String name, String fileName, InputStream stream, Class<T> returnType) {
return catchConnectionExceptions(super::postMultiPartStream, path, name, fileName, stream, returnType);
}

@Override
public <T> T post(String path, Object object, Class<T> returnType) {
return catchConnectionExceptions(super::post, path, object, returnType);
}

@Override
public <T> T put(String path, Object object, Class<T> returnType) {
return catchConnectionExceptions(super::put, path, object, returnType);
}

@Override
public <T> T delete(String path, Map<String, Object> params, Class<T> returnType) {
return catchConnectionExceptions(super::delete, path, params, returnType);
}

@Override
public <T> T deleteWithHeaders(String path, MultivaluedMap<String, Object> headers, Map<String, Object> params, Class<T> clazz) {
return catchConnectionExceptions(super::deleteWithHeaders, path, headers, params, clazz);
}

@Override
public <T> T postForm(String path, Form form, Class<T> returnType) {
return catchConnectionExceptions(super::postForm, path, form, returnType);
}

@Override
public <T> Future<T> postAsync(String path, Object object, Class<T> returnType) {
return catchConnectionExceptions(super::postAsync, path, object, returnType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import javax.ws.rs.client.Client;
import javax.ws.rs.client.WebTarget;

public class NiFiRestClientV1 extends JerseyRestClient implements NiFiRestClient {
public class NiFiRestClientV1 extends NiFiJerseyRestClient implements NiFiRestClient {

/**
* NiFi Connections REST client
Expand Down
Loading

0 comments on commit 105140e

Please sign in to comment.