Search in sources :

Example 16 with ConfigurationProviderException

use of org.apache.nifi.minifi.c2.api.ConfigurationProviderException in project nifi-minifi by apache.

the class ConfigService method initContentTypeInfo.

protected ConfigurationProviderInfo initContentTypeInfo(List<ConfigurationProvider> configurationProviders) {
    List<Pair<MediaType, ConfigurationProvider>> mediaTypeList = new ArrayList<>();
    List<String> contentTypes = new ArrayList<>();
    Set<MediaType> seenMediaTypes = new LinkedHashSet<>();
    for (ConfigurationProvider configurationProvider : configurationProviders) {
        try {
            for (String contentTypeString : configurationProvider.getContentTypes()) {
                MediaType mediaType = MediaType.valueOf(contentTypeString);
                if (seenMediaTypes.add(mediaType)) {
                    contentTypes.add(contentTypeString);
                    mediaTypeList.add(new Pair<>(mediaType, configurationProvider));
                }
            }
        } catch (ConfigurationProviderException e) {
            return new ConfigurationProviderInfo(null, null, e);
        }
    }
    return new ConfigurationProviderInfo(mediaTypeList, contentTypes, null);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) ConfigurationProvider(org.apache.nifi.minifi.c2.api.ConfigurationProvider) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) Pair(org.apache.nifi.minifi.c2.api.util.Pair)

Example 17 with ConfigurationProviderException

use of org.apache.nifi.minifi.c2.api.ConfigurationProviderException in project nifi-minifi by apache.

the class ConfigService method initConfigurationProviderValue.

public ConfigurationProviderValue initConfigurationProviderValue(ConfigurationProviderKey key) {
    if (logger.isDebugEnabled()) {
        logger.debug("Attempting to load and cache configuration with key " + key);
    }
    try {
        List<MediaType> acceptValues = key.getAcceptValues();
        Pair<MediaType, ConfigurationProvider> providerPair = getProvider(acceptValues);
        Map<String, List<String>> parameters = key.getParameters();
        Integer version = null;
        List<String> versionList = parameters.get("version");
        if (versionList != null && versionList.size() > 0) {
            try {
                version = Integer.parseInt(versionList.get(0));
            } catch (NumberFormatException e) {
                throw new InvalidParameterException("Unable to parse " + version + " as integer.", e);
            }
        }
        return new ConfigurationProviderValue(providerPair.getSecond().getConfiguration(providerPair.getFirst().toString(), version, parameters), providerPair.getFirst(), null);
    } catch (ConfigurationProviderException e) {
        return new ConfigurationProviderValue(null, null, e);
    }
}
Also used : ConfigurationProvider(org.apache.nifi.minifi.c2.api.ConfigurationProvider) ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) InvalidParameterException(org.apache.nifi.minifi.c2.api.InvalidParameterException) MediaType(javax.ws.rs.core.MediaType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with ConfigurationProviderException

use of org.apache.nifi.minifi.c2.api.ConfigurationProviderException in project nifi-minifi by apache.

the class ConfigService method getContentTypes.

@GET
@Path("/contentTypes")
@Produces(MediaType.APPLICATION_JSON)
public Response getContentTypes(@Context HttpServletRequest request, @Context UriInfo uriInfo) {
    try {
        authorizer.authorize(SecurityContextHolder.getContext().getAuthentication(), uriInfo);
    } catch (AuthorizationException e) {
        logger.warn(HttpRequestUtil.getClientString(request) + " not authorized to access " + uriInfo, e);
        return Response.status(403).build();
    }
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    List<String> contentTypes;
    try {
        contentTypes = configurationProviderInfo.get().getContentTypes();
    } catch (ConfigurationProviderException e) {
        logger.warn("Unable to initialize content type information.", e);
        return Response.status(500).build();
    }
    try {
        objectMapper.writerWithDefaultPrettyPrinter().writeValue(byteArrayOutputStream, contentTypes);
    } catch (IOException e) {
        logger.warn("Unable to write configuration providers to output stream.", e);
        return Response.status(500).build();
    }
    return Response.ok().type(MediaType.APPLICATION_JSON_TYPE).entity(byteArrayOutputStream.toByteArray()).build();
}
Also used : ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) AuthorizationException(org.apache.nifi.minifi.c2.api.security.authorization.AuthorizationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with ConfigurationProviderException

use of org.apache.nifi.minifi.c2.api.ConfigurationProviderException in project nifi-minifi by apache.

the class FileSystemWritableConfiguration method getOutputStream.

@Override
public OutputStream getOutputStream() throws ConfigurationProviderException {
    try {
        Path parent = path.getParent();
        Files.createDirectories(parent);
        Path tmpPath = cache.resolveChildAndVerifyParent(parent, path.getFileName().toString() + "." + UUID.randomUUID().toString());
        return new DelegatingOutputStream(Files.newOutputStream(tmpPath)) {

            @Override
            public void close() throws IOException {
                super.close();
                Files.move(tmpPath, path);
            }
        };
    } catch (IOException e) {
        throw new ConfigurationProviderException("Unable to open " + path + " for writing.", e);
    }
}
Also used : Path(java.nio.file.Path) ConfigurationProviderException(org.apache.nifi.minifi.c2.api.ConfigurationProviderException) IOException(java.io.IOException) DelegatingOutputStream(org.apache.nifi.minifi.c2.api.util.DelegatingOutputStream)

Aggregations

WriteableConfiguration (org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration)11 ConfigurationCacheFileInfo (org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo)10 ConfigurationProviderException (org.apache.nifi.minifi.c2.api.ConfigurationProviderException)9 List (java.util.List)8 Test (org.junit.Test)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)5 HttpURLConnection (java.net.HttpURLConnection)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HashMap (java.util.HashMap)4 InvalidParameterException (org.apache.nifi.minifi.c2.api.InvalidParameterException)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 MediaType (javax.ws.rs.core.MediaType)3 ConfigurationProvider (org.apache.nifi.minifi.c2.api.ConfigurationProvider)3 AuthorizationException (org.apache.nifi.minifi.c2.api.security.authorization.AuthorizationException)3 FileSystemConfigurationCache (org.apache.nifi.minifi.c2.cache.filesystem.FileSystemConfigurationCache)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Closeable (java.io.Closeable)2 OutputStream (java.io.OutputStream)2