Search in sources :

Example 11 with ApplicationRecord

use of io.cdap.cdap.proto.ApplicationRecord in project cdap by caskdata.

the class AppLifecycleHttpHandler method decodeAndValidateBatchApplicationRecord.

/**
 * Decodes request coming from the {@link #upgradeApplications(FullHttpRequest, HttpResponder, String, Set, boolean)}
 * call.
 */
private List<ApplicationId> decodeAndValidateBatchApplicationRecord(NamespaceId namespaceId, FullHttpRequest request) throws BadRequestException {
    try {
        List<ApplicationId> appIds = new ArrayList<>();
        List<ApplicationRecord> records = DECODE_GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), new TypeToken<List<ApplicationRecord>>() {
        }.getType());
        if (records == null) {
            throw new BadRequestException("Request body is invalid json, please check that it is a json array.");
        }
        for (ApplicationRecord element : records) {
            if (element.getName() != null && element.getName().isEmpty()) {
                throw new BadRequestException("Missing 'name' in the request element for app-id.");
            }
            if (element.getAppVersion() == null) {
                appIds.add(validateApplicationId(namespaceId, element.getName()));
            } else {
                appIds.add(validateApplicationVersionId(namespaceId, element.getName(), element.getAppVersion()));
            }
        }
        return appIds;
    } catch (JsonSyntaxException e) {
        throw new BadRequestException("Request body is invalid json: " + e.getMessage());
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) TypeToken(com.google.common.reflect.TypeToken) ArrayList(java.util.ArrayList) BadRequestException(io.cdap.cdap.common.BadRequestException) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord)

Aggregations

ApplicationRecord (io.cdap.cdap.proto.ApplicationRecord)11 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)6 ApplicationClient (io.cdap.cdap.client.ApplicationClient)4 TypeToken (com.google.common.reflect.TypeToken)3 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)3 BadRequestException (io.cdap.cdap.common.BadRequestException)3 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 NamespaceClient (io.cdap.cdap.client.NamespaceClient)2 ProgramClient (io.cdap.cdap.client.ProgramClient)2 ScheduleClient (io.cdap.cdap.client.ScheduleClient)2 NotFoundException (io.cdap.cdap.common.NotFoundException)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 IOException (java.io.IOException)2 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 Iterables (com.google.common.collect.Iterables)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1