├── .gitignore ├── .travis.force.build ├── .travis.install.maven.sh ├── .travis.maven.settings.xml ├── .travis.yml ├── .travis └── wait_for_services.rb ├── LICENSE ├── README.md ├── docker-compose.yml ├── docker ├── Dockerfile ├── docker_start.sh └── hawkular_wait.sh ├── pom.xml └── src ├── main └── java │ └── org │ └── hawkular │ └── client │ ├── alert │ ├── AlertsClient.java │ ├── AlertsClientImpl.java │ ├── clients │ │ ├── ActionsClient.java │ │ ├── AlertClient.java │ │ ├── DefaultActionsClient.java │ │ ├── DefaultAlertClient.java │ │ ├── DefaultEventsClient.java │ │ ├── DefaultExportClient.java │ │ ├── DefaultImportClient.java │ │ ├── DefaultPluginsClient.java │ │ ├── DefaultStatusClient.java │ │ ├── DefaultTriggersClient.java │ │ ├── EventsClient.java │ │ ├── ExportClient.java │ │ ├── ImportClient.java │ │ ├── PluginsClient.java │ │ ├── StatusClient.java │ │ └── TriggersClient.java │ ├── jaxrs │ │ └── handlers │ │ │ ├── ActionsHandler.java │ │ │ ├── AlertHandler.java │ │ │ ├── EventsHandler.java │ │ │ ├── ExportHandler.java │ │ │ ├── ImportHandler.java │ │ │ ├── PluginsHandler.java │ │ │ ├── StatusHandler.java │ │ │ └── TriggersHandler.java │ └── model │ │ └── AlertsParams.java │ ├── core │ ├── BaseClient.java │ ├── ClientInfo.java │ ├── ClientResponse.java │ ├── DefaultClientResponse.java │ ├── HawkularClient.java │ ├── HawkularClientBuilder.java │ ├── jaxrs │ │ ├── Empty.java │ │ ├── RequestHeadersFilter.java │ │ ├── RequestLoggingFilter.java │ │ ├── ResponseCodes.java │ │ ├── ResponseLoggingFilter.java │ │ ├── RestFactory.java │ │ ├── fasterxml │ │ │ └── jackson │ │ │ │ ├── ClientObjectMapper.java │ │ │ │ ├── HCJacksonJson2Provider.java │ │ │ │ └── JacksonObjectMapperProvider.java │ │ └── param │ │ │ ├── ConvertersProvider.java │ │ │ ├── DurationConverter.java │ │ │ ├── OrderConverter.java │ │ │ ├── PercentilesConverter.java │ │ │ └── TagsConverter.java │ └── typeresolvers │ │ ├── CollectionJavaTypeResolver.java │ │ ├── MapJavaTypeResolver.java │ │ └── SimpleJavaTypeResolver.java │ ├── inventory │ ├── InventoryClient.java │ ├── InventoryClientImpl.java │ ├── clients │ │ ├── APIInfoClient.java │ │ ├── BulkCreateClient.java │ │ ├── DefaultAPIInfoClient.java │ │ ├── DefaultBulkCreateClient.java │ │ ├── DefaultEventsClient.java │ │ ├── DefaultGraphClient.java │ │ ├── DefaultSingleEntityClient.java │ │ ├── DefaultSyncClient.java │ │ ├── DefaultTenantClient.java │ │ ├── DefaultTraversalClient.java │ │ ├── EventsClient.java │ │ ├── GraphClient.java │ │ ├── SingleEntityClient.java │ │ ├── SyncClient.java │ │ ├── TenantClient.java │ │ └── TraversalClient.java │ ├── jaxrs │ │ └── handlers │ │ │ ├── APIInfoHandler.java │ │ │ ├── BulkCreateHandler.java │ │ │ ├── EventsHandler.java │ │ │ ├── GraphHandler.java │ │ │ ├── SingleEntityHandler.java │ │ │ ├── SyncHandler.java │ │ │ ├── TenantHandler.java │ │ │ └── TraversalHandler.java │ ├── json │ │ ├── Endpoint.java │ │ ├── Endpoints.java │ │ ├── IdJSON.java │ │ └── StringValue.java │ └── model │ │ ├── ElementType.java │ │ ├── InventoryJaxRsInfo.java │ │ └── JaxRsResource.java │ └── metrics │ ├── MetricsClient.java │ ├── MetricsClientImpl.java │ ├── clients │ ├── AvailabilityClient.java │ ├── CounterClient.java │ ├── DefaultAvailabilityClient.java │ ├── DefaultCounterClient.java │ ├── DefaultGaugeClient.java │ ├── DefaultMetricClient.java │ ├── DefaultPingClient.java │ ├── DefaultStatusClient.java │ ├── DefaultStringClient.java │ ├── DefaultTenantClient.java │ ├── GaugeClient.java │ ├── MetricClient.java │ ├── PingClient.java │ ├── StatusClient.java │ ├── StringClient.java │ └── TenantClient.java │ ├── fasterxml │ └── jackson │ │ ├── AvailabilityBucketPointDeserializer.java │ │ ├── AvailabilityBucketPointMixin.java │ │ ├── AvailabilityTypeMixin.java │ │ ├── MetricTypeMixin.java │ │ ├── NumericBucketPointDeserializer.java │ │ ├── NumericBucketPointMixin.java │ │ ├── TaggedBucketPointDeserializer.java │ │ ├── TaggedBucketPointMixin.java │ │ ├── TenantDeserializer.java │ │ ├── TenantMixin.java │ │ └── TenantSerializer.java │ ├── jaxrs │ └── handlers │ │ ├── AvailabilityHandler.java │ │ ├── CounterHandler.java │ │ ├── GaugeHandler.java │ │ ├── MetricHandler.java │ │ ├── PingHandler.java │ │ ├── StatusHandler.java │ │ ├── StringHandler.java │ │ └── TenantHandler.java │ └── model │ └── Order.java └── test └── java └── org └── hawkular └── client └── test ├── BTG.java ├── BTGTest.java ├── BaseTest.java ├── NoopTest.java ├── alerts ├── ActionsTest.java ├── AlertTest.java ├── AlertsEventsTest.java ├── AlertsStatusTest.java ├── EventsTest.java ├── ExportTest.java ├── ImportTest.java ├── PluginsTest.java ├── StatusTest.java ├── TriggersConditionsTest.java ├── TriggersTest.java └── trigger │ └── utils │ └── SetConitionMethod.java ├── inventory ├── APIInfoTest.java ├── BulkCreateBaseTest.java ├── BulkCreateTest.java ├── GraphTest.java ├── InventoryEventsTest.java ├── InventoryTenantTest.java ├── SingleEntityTest.java ├── SyncTest.java └── TraversalTest.java ├── metrics ├── AvailabilityTest.java ├── CounterTest.java ├── GaugeTest.java ├── MetricTest.java ├── MetricsStatusTest.java ├── MetricsTenantTest.java ├── PingTest.java └── StringTest.java └── utils ├── DataPointGenerator.java ├── MetricGenerator.java ├── RandomStringGenerator.java └── TagGenerator.java /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ IDEA # 2 | .idea/ 3 | *.iml 4 | 5 | # Eclipse Files # 6 | .metadata 7 | .settings 8 | .project 9 | .classpath 10 | 11 | # General Java Folders/Files # 12 | bin/ 13 | target/ 14 | *.jar 15 | *.class 16 | -------------------------------------------------------------------------------- /.travis.force.build: -------------------------------------------------------------------------------- 1 | # Change this file to force Travis to perform a rebuild 2 | # 3 | 4 | -------------------------------------------------------------------------------- /.travis.install.maven.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | 20 | set -xe 21 | 22 | MVN_VERSION="$1" 23 | MVN_INSTALL_DIR="$2" 24 | 25 | if [ ! -f "${MVN_INSTALL_DIR}/lib/maven-artifact-${MVN_VERSION}.jar" ]; then 26 | # remove the older version that can eventually be there 27 | rm -Rf "${MVN_INSTALL_DIR}" 28 | mkdir -p "${MVN_INSTALL_DIR}" 29 | 30 | # Find the closest Apache mirror 31 | APACHE_MIRROR="$(curl -sL https://www.apache.org/dyn/closer.cgi?asjson=1 | python -c 'import sys, json; print json.load(sys.stdin)["preferred"]')" 32 | curl -o "${HOME}/apache-maven-$MVN_VERSION-bin.tar.gz" "$APACHE_MIRROR/maven/maven-3/$MVN_VERSION/binaries/apache-maven-$MVN_VERSION-bin.tar.gz" 33 | cd "${MVN_INSTALL_DIR}" 34 | tar -xzf "${HOME}/apache-maven-$MVN_VERSION-bin.tar.gz" --strip 1 35 | chmod +x "${MVN_INSTALL_DIR}/bin/mvn" 36 | else 37 | echo "Using cached Maven ${MVN_VERSION}" 38 | fi 39 | ${MVN_INSTALL_DIR}/bin/mvn -version 40 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | notifications: 5 | irc: 6 | channels: 7 | - chat.freenode.net#hawkular 8 | on_success: change 9 | # whitelist 10 | branches: 11 | only: 12 | - master 13 | env: 14 | global: 15 | - HAWKULAR_ENDPOINT=http://localhost:8080 16 | - secure: P1sgq46dmYBOb/pvHGO2ACO/Zum5wbXebLJ6kLV+Ss97y0B+KWKGCrc9Hh9TG28mdzPMCHbJOFynfneet8irpEIL97PbSb2HFeKhiHJTeB4d0y60uaa6Y6Lmo+YCniubvw+FaeoXBYjImg2nDXslvKDTu6I0JKQ1pk8Fkqx45Sw= 17 | - secure: BTZcYkskQR5SleCK8enISTeSK/xR8rzvht/jEsYG5Ar7T/xa2USY2jaiIWzmd1t4hWkrSoubRCHuKt4oGi/fll75r9kPDLql9R1zaMmhEiKDsaEHZhuL6Ds8SVIgwdcpXN4IwiFfVOOxSTdpWcsNNbiQvCgtEIh0oqSk+jJArzI= 18 | services: 19 | - docker 20 | before_install: 21 | - docker-compose up -d && ./.travis/wait_for_services.rb 22 | install: 23 | - bash .travis.install.maven.sh "3.3.9" "${HOME}/mvn-home" 24 | - export M2_HOME=${HOME}/mvn-home 25 | - export PATH=${HOME}/mvn-home/bin:${PATH} 26 | - mvn -version -B 27 | script: 28 | - mvn -s .travis.maven.settings.xml verify -Dwildfly.logging.console.level=DEBUG -B -Pci 29 | | grep -vF "[INFO] Downloading:" | grep -vF "[INFO] Downloaded:"; test ${PIPESTATUS[0]} -eq 0 30 | after_success: 31 | - PROJECT_VERSION=`mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version | grep -v '\['` 32 | - if [[ "$PROJECT_VERSION" =~ .*SNAPSHOT ]] && [[ "${TRAVIS_BRANCH}" = "master" ]] && [[ "${TRAVIS_PULL_REQUEST}" = "false" ]]; 33 | then 34 | mvn -s .travis.maven.settings.xml deploy -DskipTests ; 35 | fi 36 | -------------------------------------------------------------------------------- /.travis/wait_for_services.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | require 'net/http' 20 | 21 | uris = [ 22 | 'http://localhost:8080/hawkular/status', 23 | 'http://localhost:8080/hawkular/metrics/status', 24 | 'http://localhost:8080/hawkular/alerts/status', 25 | 'http://localhost:8080/hawkular/inventory/status' 26 | ] 27 | 28 | uris.each do |uri_string| 29 | loop do 30 | uri = URI(uri_string) 31 | begin 32 | response = Net::HTTP.get_response(uri) 33 | break if response.code == '200' 34 | puts "Waiting for: #{uri_string}" 35 | rescue 36 | puts 'Waiting for Hawkular-Services to accept connections' 37 | end 38 | sleep 5 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/hawkular/hawkular-client-java.svg?branch=master)](https://travis-ci.org/hawkular/hawkular-client-java) 2 | [![Release Version](https://img.shields.io/maven-central/v/org.hawkular.client/hawkular-java-client.svg?maxAge=2592000)](https://mvnrepository.com/artifact/org.hawkular.client/hawkular-java-client) 3 | [![License](https://img.shields.io/hexpm/l/plug.svg?maxAge=2592000)]() 4 | 5 | # Java client for [Hawkular](https://github.com/hawkular) 6 | Example, 7 | ```java 8 | HawkularClient client = HawkularClient.builder("my-tenant") 9 | .uri("http://localhost:8080") 10 | .basicAuthentication("jdoe", "password") 11 | .build(); 12 | 13 | System.out.println(client.metrics().tenant().getTenants()); // show all tenants 14 | System.out.println(client.alerts().plugins().findActionPlugins()) // show all plugins 15 | System.out.println(client.inventory().tenant.getTenant()); // get current tenant 16 | ``` 17 | See [unit tests](src/test/java/org/hawkular/client/test) for more examples. 18 | 19 | ### How to run unit tests? 20 | You have set your hawkular server url in to `HAWKULAR_ENDPOINT` environment variable.(example: `export HAWKULAR_ENDPOINT=http://:8080`) 21 | 22 | To run `mvn test` 23 | 24 | Run with debug log: `mvn test -Dorg.slf4j.simpleLogger.defaultLogLevel=debug -Dorg.slf4j.simpleLogger.logFile=target/test.log` 25 | - http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html 26 | 27 | # Help Wanted 28 | This project is under active development. Pull requests are welcome. 29 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | hawkular: 19 | image: "pilhuhn/hawkular-services:latest" 20 | ports: 21 | - "8080:8080" 22 | - "8443:8443" 23 | - "9990:9990" 24 | links: 25 | - myCassandra 26 | environment: 27 | - CASSANDRA_NODES=myCassandra 28 | - ADMIN_TOKEN=awesome_secret_sauce 29 | myCassandra: 30 | image: cassandra:3.7 31 | environment: 32 | - CASSANDRA_START_RPC=true 33 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | # and other contributors as indicated by the @author tags. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | FROM hawkular/docker-maven 19 | 20 | MAINTAINER Viet Nguyen 21 | 22 | USER root 23 | 24 | ENV WORKING_DIR=/opt/hawkular-java-client 25 | 26 | RUN yum install -y git wget &&\ 27 | git clone https://github.com/Hawkular-QE/hawkular-java-client.git ${WORKING_DIR} &&\ 28 | cd ${WORKING_DIR} &&\ 29 | mvn dependency:go-offline test -Dtest=NoopTest &&\ 30 | ln -s ${WORKING_DIR}/target/surefire-reports /reports &&\ 31 | rm -rf /reports/* 32 | 33 | ADD hawkular_wait.sh /usr/bin/hawkular_wait.sh 34 | ADD docker_start.sh /usr/bin/docker_start.sh 35 | 36 | CMD ["sh", "-c", "/usr/bin/docker_start.sh"] 37 | -------------------------------------------------------------------------------- /docker/docker_start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | hawkular_wait.sh && mvn -f ${WORKING_DIR} -o test -Pci 20 | 21 | echo 1> /reports/.completed 22 | chmod +x -R /reports 23 | 24 | echo "## Test completed ##" 25 | while true; do sleep 5; done 26 | -------------------------------------------------------------------------------- /docker/hawkular_wait.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | wget --retry-connrefused --timeout=10 -t ${WAIT_TRIES:-1} -w 5 --spider ${HAWKULAR_ENDPOINT:-http://localhost:8080} 20 | exit $? 21 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/AlertsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert; 18 | 19 | import org.hawkular.client.alert.clients.ActionsClient; 20 | import org.hawkular.client.alert.clients.AlertClient; 21 | import org.hawkular.client.alert.clients.EventsClient; 22 | import org.hawkular.client.alert.clients.ExportClient; 23 | import org.hawkular.client.alert.clients.ImportClient; 24 | import org.hawkular.client.alert.clients.PluginsClient; 25 | import org.hawkular.client.alert.clients.StatusClient; 26 | import org.hawkular.client.alert.clients.TriggersClient; 27 | 28 | public interface AlertsClient { 29 | 30 | AlertClient alert(); 31 | 32 | ActionsClient actions(); 33 | 34 | EventsClient events(); 35 | 36 | ExportClient export(); 37 | 38 | ImportClient imports(); 39 | 40 | PluginsClient plugins(); 41 | 42 | StatusClient status(); 43 | 44 | TriggersClient triggers(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/DefaultExportClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import javax.ws.rs.core.Response; 20 | 21 | import org.hawkular.alerts.api.model.export.Definitions; 22 | import org.hawkular.client.alert.jaxrs.handlers.ExportHandler; 23 | import org.hawkular.client.core.BaseClient; 24 | import org.hawkular.client.core.ClientInfo; 25 | import org.hawkular.client.core.ClientResponse; 26 | import org.hawkular.client.core.DefaultClientResponse; 27 | import org.hawkular.client.core.jaxrs.ResponseCodes; 28 | import org.hawkular.client.core.jaxrs.RestFactory; 29 | 30 | import com.fasterxml.jackson.databind.JavaType; 31 | 32 | public class DefaultExportClient extends BaseClient implements ExportClient { 33 | 34 | public DefaultExportClient(ClientInfo clientInfo) { 35 | super(clientInfo, new RestFactory<>(ExportHandler.class)); 36 | } 37 | 38 | public ClientResponse export() { 39 | Response serverResponse = null; 40 | 41 | try { 42 | serverResponse = restApi().export(); 43 | JavaType javaType = simpleResolver().get(Definitions.class); 44 | 45 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 46 | } finally { 47 | if (serverResponse != null) { 48 | serverResponse.close(); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/DefaultImportClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import javax.ws.rs.core.Response; 20 | 21 | import org.hawkular.alerts.api.model.export.Definitions; 22 | import org.hawkular.client.alert.jaxrs.handlers.ImportHandler; 23 | import org.hawkular.client.core.BaseClient; 24 | import org.hawkular.client.core.ClientInfo; 25 | import org.hawkular.client.core.ClientResponse; 26 | import org.hawkular.client.core.DefaultClientResponse; 27 | import org.hawkular.client.core.jaxrs.ResponseCodes; 28 | import org.hawkular.client.core.jaxrs.RestFactory; 29 | 30 | import com.fasterxml.jackson.databind.JavaType; 31 | 32 | public class DefaultImportClient extends BaseClient implements ImportClient { 33 | 34 | public DefaultImportClient(ClientInfo clientInfo) { 35 | super(clientInfo, new RestFactory<>(ImportHandler.class)); 36 | } 37 | 38 | public ClientResponse importDefinitions(final String strategy, final Definitions definitions) { 39 | Response serverResponse = null; 40 | 41 | try { 42 | serverResponse = restApi().importDefinitions(strategy, definitions); 43 | JavaType javaType = simpleResolver().get(Definitions.class); 44 | 45 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 46 | } finally { 47 | if (serverResponse != null) { 48 | serverResponse.close(); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/DefaultPluginsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import java.util.List; 20 | 21 | import javax.ws.rs.core.Response; 22 | 23 | import org.hawkular.client.alert.jaxrs.handlers.PluginsHandler; 24 | import org.hawkular.client.core.BaseClient; 25 | import org.hawkular.client.core.ClientInfo; 26 | import org.hawkular.client.core.ClientResponse; 27 | import org.hawkular.client.core.DefaultClientResponse; 28 | import org.hawkular.client.core.jaxrs.ResponseCodes; 29 | import org.hawkular.client.core.jaxrs.RestFactory; 30 | 31 | import com.fasterxml.jackson.databind.JavaType; 32 | 33 | public class DefaultPluginsClient extends BaseClient implements PluginsClient { 34 | 35 | public DefaultPluginsClient(ClientInfo clientInfo) { 36 | super(clientInfo, new RestFactory<>(PluginsHandler.class)); 37 | } 38 | 39 | @Override 40 | public ClientResponse> findActionPlugins() { 41 | Response serverResponse = null; 42 | 43 | try { 44 | serverResponse = restApi().findActionPlugins(); 45 | JavaType javaType = collectionResolver().get(List.class, String.class); 46 | 47 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 48 | } finally { 49 | if (serverResponse != null) { 50 | serverResponse.close(); 51 | } 52 | } 53 | } 54 | 55 | @Override 56 | public ClientResponse> getActionPlugin(String actionPlugin) { 57 | Response serverResponse = null; 58 | 59 | try { 60 | serverResponse = restApi().getActionPlugin(actionPlugin); 61 | JavaType javaType = collectionResolver().get(List.class, String.class); 62 | 63 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 64 | } finally { 65 | if (serverResponse != null) { 66 | serverResponse.close(); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/DefaultStatusClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import java.util.Map; 20 | 21 | import javax.ws.rs.core.Response; 22 | 23 | import org.hawkular.client.alert.jaxrs.handlers.StatusHandler; 24 | import org.hawkular.client.core.BaseClient; 25 | import org.hawkular.client.core.ClientInfo; 26 | import org.hawkular.client.core.ClientResponse; 27 | import org.hawkular.client.core.DefaultClientResponse; 28 | import org.hawkular.client.core.jaxrs.ResponseCodes; 29 | import org.hawkular.client.core.jaxrs.RestFactory; 30 | 31 | import com.fasterxml.jackson.databind.JavaType; 32 | 33 | public class DefaultStatusClient extends BaseClient implements StatusClient { 34 | 35 | public DefaultStatusClient(ClientInfo clientInfo) { 36 | super(clientInfo, new RestFactory<>(StatusHandler.class)); 37 | } 38 | 39 | @Override 40 | public ClientResponse> status() { 41 | Response serverResponse = null; 42 | 43 | try { 44 | serverResponse = restApi().status(); 45 | JavaType javaType = mapResolver().get(Map.class, String.class, String.class); 46 | 47 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 48 | } finally { 49 | if (serverResponse != null) { 50 | serverResponse.close(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/EventsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import java.util.List; 20 | 21 | import org.hawkular.alerts.api.model.event.Event; 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.client.core.jaxrs.Empty; 24 | 25 | public interface EventsClient { 26 | 27 | /** 28 | * Get events with optional filtering. 29 | * @param startTime 30 | * @param endTime 31 | * @param eventIds 32 | * @param triggerIds 33 | * @param categories 34 | * @param tags 35 | * @param thin 36 | * @return 37 | */ 38 | ClientResponse> findEvents( 39 | final Long startTime, 40 | final Long endTime, 41 | final String eventIds, 42 | final String triggerIds, 43 | final String categories, 44 | final String tags, 45 | final Boolean thin); 46 | 47 | /** 48 | * Create a new Event. 49 | * @param event 50 | * @return 51 | */ 52 | ClientResponse createEvent(Event event); 53 | 54 | /** 55 | * Delete events with optional filtering. 56 | * @param startTime 57 | * @param endTime 58 | * @param eventIds 59 | * @param triggerIds 60 | * @param categories 61 | * @param tags 62 | * @return 63 | */ 64 | ClientResponse deleteEvents( 65 | final Long startTime, 66 | final Long endTime, 67 | final String eventIds, 68 | final String triggerIds, 69 | final String categories, 70 | final String tags); 71 | 72 | /** 73 | * Get an existing Event. 74 | * @param eventId 75 | * @param thin 76 | * @return 77 | */ 78 | ClientResponse getEvent(final String eventId, final Boolean thin); 79 | 80 | /** 81 | * Remove tags from existing Events. 82 | * @param eventIds 83 | * @param tagNames 84 | * @return 85 | */ 86 | ClientResponse deleteTags(final String eventIds, final String tagNames); 87 | 88 | /** 89 | * Add tags to existing Events. 90 | * @param eventIds 91 | * @param tagNames 92 | * @return 93 | */ 94 | ClientResponse createTags(final String eventIds, final String tagNames); 95 | 96 | /** 97 | * Delete an existing Event. 98 | * @param eventId 99 | * @return 100 | */ 101 | ClientResponse deleteEvent(final String eventId); 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/ExportClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import org.hawkular.alerts.api.model.export.Definitions; 20 | import org.hawkular.client.core.ClientResponse; 21 | 22 | public interface ExportClient { 23 | 24 | /** 25 | * Export a list of full triggers and action definitions. 26 | * @return 27 | */ 28 | ClientResponse export(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/ImportClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import org.hawkular.alerts.api.model.export.Definitions; 20 | import org.hawkular.client.core.ClientResponse; 21 | 22 | public interface ImportClient { 23 | 24 | /** 25 | * Import a list of full triggers and action definitions. 26 | * @param strategy 27 | * @param definitions 28 | * @return 29 | */ 30 | ClientResponse importDefinitions(final String strategy, final Definitions definitions); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/PluginsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import java.util.List; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | 23 | public interface PluginsClient { 24 | 25 | /** 26 | * Find all action plugins. 27 | * @return 28 | */ 29 | ClientResponse> findActionPlugins(); 30 | 31 | /** 32 | * Find list of properties to fill for a specific action plugin. 33 | * @param actionPlugin 34 | * @return 35 | */ 36 | ClientResponse> getActionPlugin(String actionPlugin); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/clients/StatusClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.clients; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | 23 | public interface StatusClient { 24 | 25 | ClientResponse> status(); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/jaxrs/handlers/ActionsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.DELETE; 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.POST; 23 | import javax.ws.rs.PUT; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.PathParam; 26 | import javax.ws.rs.Produces; 27 | import javax.ws.rs.QueryParam; 28 | import javax.ws.rs.core.MediaType; 29 | import javax.ws.rs.core.Response; 30 | 31 | import org.hawkular.alerts.api.model.action.ActionDefinition; 32 | 33 | /** 34 | * Actions API 35 | * http://www.hawkular.org/docs/rest/rest-alerts.html#_actions 36 | */ 37 | @Path("/hawkular/alerts/actions") 38 | @Produces(MediaType.APPLICATION_JSON) 39 | @Consumes(MediaType.APPLICATION_JSON) 40 | public interface ActionsHandler { 41 | 42 | @GET 43 | @Path("/") 44 | Response findActions(); 45 | 46 | @POST 47 | @Path("/") 48 | Response createAction(final ActionDefinition definition); 49 | 50 | @PUT 51 | @Path("/") 52 | Response updateAction(final ActionDefinition definition); 53 | 54 | @GET 55 | @Path("/history") 56 | Response getActionHistory(@QueryParam("startTime") final Long startTime, 57 | @QueryParam("endTime") final Long endTime, 58 | @QueryParam("actionPlugins") final String actionPlugins, 59 | @QueryParam("actionIds") final String actionIds, 60 | @QueryParam("alertIds") final String alertIds, 61 | @QueryParam("results") final String results, 62 | @QueryParam("thin") final Boolean thin); 63 | 64 | @PUT 65 | @Path("/history/delete") 66 | Response deleteActionHistory(@QueryParam("startTime") final Long startTime, 67 | @QueryParam("endTime") final Long endTime, 68 | @QueryParam("actionPlugins") final String actionPlugins, 69 | @QueryParam("actionIds") final String actionIds, 70 | @QueryParam("alertIds") final String alertIds, 71 | @QueryParam("results") final String results); 72 | 73 | @GET 74 | @Path("/plugin/{actionPlugin}") 75 | Response findActionsByPlugin(@PathParam("actionPlugin") final String actionPlugin); 76 | 77 | @DELETE 78 | @Path("/{actionPlugin}/{actionId}") 79 | Response deleteAction(@PathParam("actionPlugin") final String actionPlugin, @PathParam("actionId") final String actionId); 80 | 81 | @GET 82 | @Path("/{actionPlugin}/{actionId}") 83 | Response getAction(@PathParam("actionPlugin") final String actionPlugin, @PathParam("actionId") final String actionId); 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/jaxrs/handlers/EventsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.DELETE; 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.POST; 23 | import javax.ws.rs.PUT; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.PathParam; 26 | import javax.ws.rs.Produces; 27 | import javax.ws.rs.QueryParam; 28 | import javax.ws.rs.core.MediaType; 29 | import javax.ws.rs.core.Response; 30 | 31 | import org.hawkular.alerts.api.model.event.Event; 32 | 33 | /** 34 | * Events API 35 | * http://www.hawkular.org/docs/rest/rest-alerts.html#_events 36 | */ 37 | @Path("/hawkular/alerts/events") 38 | @Produces(MediaType.APPLICATION_JSON) 39 | @Consumes(MediaType.APPLICATION_JSON) 40 | public interface EventsHandler { 41 | 42 | @GET 43 | @Path("/") 44 | Response findEvents( 45 | @QueryParam("startTime") final Long startTime, 46 | @QueryParam("endTime") final Long endTime, 47 | @QueryParam("eventIds") final String eventIds, 48 | @QueryParam("triggerIds") final String triggerIds, 49 | @QueryParam("categories") final String categories, 50 | @QueryParam("tags") final String tags, 51 | @QueryParam("thin") final Boolean thin); 52 | 53 | @POST 54 | @Path("/") 55 | Response createEvent(Event event); 56 | 57 | @PUT 58 | @Path("/delete") 59 | Response deleteEvents( 60 | @QueryParam("startTime") final Long startTime, 61 | @QueryParam("endTime") final Long endTime, 62 | @QueryParam("eventIds") final String eventIds, 63 | @QueryParam("triggerIds") final String triggerIds, 64 | @QueryParam("categories") final String categories, 65 | @QueryParam("tags") final String tags); 66 | 67 | @GET 68 | @Path("/event/{eventId}") 69 | Response getEvent(@PathParam("eventId") final String eventId, @QueryParam("thin") final Boolean thin); 70 | 71 | @DELETE 72 | @Path("/tags") 73 | Response deleteTags(@QueryParam("eventIds") final String eventIds, 74 | @QueryParam("tagNames") final String tagNames); 75 | 76 | @PUT 77 | @Path("/tags") 78 | Response createTags(@QueryParam("eventIds") final String eventIds, 79 | @QueryParam("tags") final String tagNames); 80 | 81 | @DELETE 82 | @Path("/{eventId}") 83 | Response deleteEvent(@PathParam("eventId") final String eventId); 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/jaxrs/handlers/ExportHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.core.MediaType; 24 | import javax.ws.rs.core.Response; 25 | 26 | /** 27 | * Export API 28 | * http://www.hawkular.org/docs/rest/rest-alerts.html#_export 29 | */ 30 | @Path("/hawkular/alerts/export") 31 | @Produces(MediaType.APPLICATION_JSON) 32 | @Consumes(MediaType.APPLICATION_JSON) 33 | public interface ExportHandler { 34 | 35 | @GET 36 | @Path("/") 37 | Response export(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/jaxrs/handlers/ImportHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.POST; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.PathParam; 23 | import javax.ws.rs.Produces; 24 | import javax.ws.rs.core.MediaType; 25 | import javax.ws.rs.core.Response; 26 | 27 | import org.hawkular.alerts.api.model.export.Definitions; 28 | 29 | /** 30 | * Import API 31 | * http://www.hawkular.org/docs/rest/rest-alerts.html#_import 32 | */ 33 | @Path("/hawkular/alerts/import") 34 | @Produces(MediaType.APPLICATION_JSON) 35 | @Consumes(MediaType.APPLICATION_JSON) 36 | public interface ImportHandler { 37 | 38 | @POST 39 | @Path("/{strategy}") 40 | Response importDefinitions(@PathParam("strategy") final String strategy, final Definitions definitions); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/jaxrs/handlers/PluginsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.PathParam; 23 | import javax.ws.rs.Produces; 24 | import javax.ws.rs.core.MediaType; 25 | import javax.ws.rs.core.Response; 26 | 27 | /** 28 | * Plugins API 29 | * http://www.hawkular.org/docs/rest/rest-alerts.html#_plugins 30 | */ 31 | @Path("/hawkular/alerts/plugins") 32 | @Produces(MediaType.APPLICATION_JSON) 33 | @Consumes(MediaType.APPLICATION_JSON) 34 | public interface PluginsHandler { 35 | 36 | @GET 37 | @Path("/") 38 | Response findActionPlugins(); 39 | 40 | @GET 41 | @Path("/{actionPlugin}") 42 | Response getActionPlugin(@PathParam("actionPlugin") String actionPlugin); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/alert/jaxrs/handlers/StatusHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.alert.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.core.MediaType; 24 | import javax.ws.rs.core.Response; 25 | 26 | @Path("/hawkular/alerts/status") 27 | @Produces(MediaType.APPLICATION_JSON) 28 | @Consumes(MediaType.APPLICATION_JSON) 29 | public interface StatusHandler { 30 | 31 | @GET 32 | @Path("/") 33 | Response status(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/BaseClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core; 18 | 19 | import static com.google.common.base.Preconditions.checkNotNull; 20 | 21 | import org.hawkular.client.core.jaxrs.RestFactory; 22 | import org.hawkular.client.core.typeresolvers.CollectionJavaTypeResolver; 23 | import org.hawkular.client.core.typeresolvers.MapJavaTypeResolver; 24 | import org.hawkular.client.core.typeresolvers.SimpleJavaTypeResolver; 25 | 26 | public abstract class BaseClient { 27 | 28 | private T restAPI; 29 | private SimpleJavaTypeResolver simpleJavaTypeResolver = new SimpleJavaTypeResolver(); 30 | private CollectionJavaTypeResolver collectionJavaTypeResolver = new CollectionJavaTypeResolver(); 31 | private MapJavaTypeResolver mapJavaTypeResolver = new MapJavaTypeResolver(); 32 | 33 | public BaseClient(ClientInfo clientInfo, RestFactory restFactory) { 34 | checkNotNull(clientInfo); 35 | restAPI = restFactory.createAPI(clientInfo); 36 | } 37 | 38 | public T restApi() { 39 | return this.restAPI; 40 | } 41 | 42 | public SimpleJavaTypeResolver simpleResolver() { 43 | return simpleJavaTypeResolver; 44 | } 45 | 46 | public CollectionJavaTypeResolver collectionResolver() { 47 | return collectionJavaTypeResolver; 48 | } 49 | 50 | public MapJavaTypeResolver mapResolver() { 51 | return mapJavaTypeResolver; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/ClientInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core; 18 | 19 | import static com.google.common.base.Preconditions.checkNotNull; 20 | 21 | import java.net.URI; 22 | import java.util.Map; 23 | import java.util.Optional; 24 | 25 | import com.google.common.collect.ImmutableMap; 26 | 27 | public final class ClientInfo { 28 | 29 | private final URI endpointUri; 30 | private final Optional username; 31 | private final Optional password; 32 | private final Map headers; 33 | 34 | public ClientInfo(URI endpointUri, Optional username, Optional password, Map 35 | headers) { 36 | this.endpointUri = checkNotNull(endpointUri); 37 | this.username = checkNotNull(username); 38 | this.password = checkNotNull(password); 39 | this.headers = ImmutableMap.copyOf(checkNotNull(headers)); 40 | } 41 | 42 | public URI getEndpointUri() { 43 | return endpointUri; 44 | } 45 | 46 | public Optional getUsername() { 47 | return username; 48 | } 49 | 50 | public Optional getPassword() { 51 | return password; 52 | } 53 | 54 | public Map getHeaders() { 55 | return headers; 56 | } 57 | 58 | @Override public boolean equals(Object o) { 59 | if (this == o) return true; 60 | if (o == null || getClass() != o.getClass()) return false; 61 | 62 | ClientInfo that = (ClientInfo) o; 63 | 64 | if (endpointUri != null ? !endpointUri.equals(that.endpointUri) : that.endpointUri != null) return false; 65 | if (username != null ? !username.equals(that.username) : that.username != null) return false; 66 | if (password != null ? !password.equals(that.password) : that.password != null) return false; 67 | return headers != null ? headers.equals(that.headers) : that.headers == null; 68 | 69 | } 70 | 71 | @Override public int hashCode() { 72 | int result = endpointUri != null ? endpointUri.hashCode() : 0; 73 | result = 31 * result + (username != null ? username.hashCode() : 0); 74 | result = 31 * result + (password != null ? password.hashCode() : 0); 75 | result = 31 * result + (headers != null ? headers.hashCode() : 0); 76 | return result; 77 | } 78 | 79 | @Override public String toString() { 80 | return "ClientInfo{" + 81 | "endpointUri=" + endpointUri + 82 | ", username=" + username + 83 | ", password=" + password + 84 | ", headers=" + headers + 85 | '}'; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/ClientResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core; 18 | 19 | public interface ClientResponse { 20 | 21 | int getStatusCode(); 22 | 23 | void setStatusCode(int statusCode); 24 | 25 | boolean isSuccess(); 26 | 27 | void setSuccess(boolean success); 28 | 29 | T getEntity(); 30 | 31 | void setEntity(T entity); 32 | 33 | String getErrorMsg(); 34 | 35 | void setErrorMsg(String errorMsg); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/HawkularClientBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core; 18 | 19 | 20 | import java.net.URI; 21 | import java.net.URISyntaxException; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | import java.util.Optional; 25 | 26 | import com.google.common.base.Throwables; 27 | 28 | public class HawkularClientBuilder { 29 | 30 | private URI uri; 31 | private Optional username = Optional.empty(); 32 | private Optional password = Optional.empty(); 33 | private Map headers = new HashMap<>(); 34 | 35 | public HawkularClientBuilder(String tenant) { 36 | try { 37 | uri = new URI("http://127.0.0.1:8080"); 38 | } catch (URISyntaxException e) { 39 | Throwables.propagate(e); 40 | } 41 | headers.put(HawkularClient.KEY_HEADER_TENANT, tenant); 42 | } 43 | 44 | public HawkularClientBuilder uri(String uri) throws URISyntaxException { 45 | return uri(new URI(uri)); 46 | } 47 | 48 | public HawkularClientBuilder uri(URI uri) { 49 | this.uri = uri; 50 | return this; 51 | } 52 | 53 | public HawkularClientBuilder basicAuthentication(String username, String password) { 54 | this.username = Optional.ofNullable(username); 55 | this.password = Optional.ofNullable(password); 56 | return this; 57 | } 58 | 59 | public HawkularClientBuilder basicAuthentication(Optional username, Optional password) { 60 | this.username = username; 61 | this.password = password; 62 | return this; 63 | } 64 | 65 | public HawkularClientBuilder tokenAuthentication(String token) { 66 | headers.put(HawkularClient.KEY_HEADER_AUTHORIZATION, "Bearer " + token); 67 | return this; 68 | } 69 | 70 | public HawkularClientBuilder adminTokenAuthentication(String token) { 71 | headers.put(HawkularClient.KEY_HEADER_ADMIN_TOKEN, token); 72 | return this; 73 | } 74 | 75 | public HawkularClientBuilder addHeader(String key, Object value) { 76 | headers.put(key, value); 77 | return this; 78 | } 79 | 80 | public HawkularClient build() { 81 | ClientInfo clientInfo = new ClientInfo(uri, username, password, headers); 82 | return new HawkularClient(clientInfo); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs; 18 | 19 | /** 20 | * Used when the REST response is empty 21 | */ 22 | public interface Empty { 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/RequestHeadersFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs; 18 | 19 | import java.io.IOException; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.client.ClientRequestContext; 23 | import javax.ws.rs.client.ClientRequestFilter; 24 | import javax.ws.rs.core.MultivaluedHashMap; 25 | import javax.ws.rs.core.MultivaluedMap; 26 | 27 | public class RequestHeadersFilter implements ClientRequestFilter { 28 | 29 | private final MultivaluedMap headers; 30 | 31 | public RequestHeadersFilter(Map headers) { 32 | this.headers = new MultivaluedHashMap<>(headers); 33 | } 34 | 35 | @Override 36 | public void filter(ClientRequestContext requestContext) throws IOException { 37 | requestContext.getHeaders().putAll(headers); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/RequestLoggingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs; 18 | 19 | import java.io.IOException; 20 | 21 | import javax.ws.rs.client.ClientRequestContext; 22 | import javax.ws.rs.client.ClientRequestFilter; 23 | import javax.ws.rs.ext.Provider; 24 | 25 | import org.hawkular.client.core.jaxrs.fasterxml.jackson.ClientObjectMapper; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import com.fasterxml.jackson.databind.ObjectMapper; 30 | 31 | @Provider 32 | public class RequestLoggingFilter implements ClientRequestFilter { 33 | 34 | private static final Logger LOG = LoggerFactory.getLogger(RequestLoggingFilter.class); 35 | private static final ObjectMapper OBJECT_MAPPER = new ClientObjectMapper(); 36 | 37 | @Override 38 | public void filter(ClientRequestContext requestContext) throws IOException { 39 | if (LOG.isDebugEnabled()) { 40 | LOG.debug(">> HTTP: {}", requestContext.getMethod()); 41 | LOG.debug(">> URI: {}", requestContext.getUri()); 42 | LOG.debug(">> Headers: {}", requestContext.getHeaders()); 43 | LOG.debug(">> Data: {}", OBJECT_MAPPER.writerWithDefaultPrettyPrinter() 44 | .writeValueAsString(requestContext.getEntity())); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/ResponseCodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs; 18 | 19 | public enum ResponseCodes { 20 | 21 | GET_SUCCESS_200(200), 22 | CREATE_SUCCESS_200(200), 23 | CREATE_SUCCESS_201(201), 24 | UPDATE_SUCCESS_204(204), 25 | UPDATE_SUCCESS_200(200), 26 | DELETE_SUCCESS_200(200), 27 | DELETE_SUCCESS_204(204), 28 | NO_CONTENT_204(204); 29 | 30 | private int code; 31 | 32 | ResponseCodes(int code) { 33 | this.code = code; 34 | } 35 | 36 | public int value() { 37 | return this.code; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return String.valueOf(this.code); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/ResponseLoggingFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs; 18 | 19 | import java.io.IOException; 20 | 21 | import javax.ws.rs.client.ClientRequestContext; 22 | import javax.ws.rs.client.ClientResponseContext; 23 | import javax.ws.rs.client.ClientResponseFilter; 24 | import javax.ws.rs.ext.Provider; 25 | 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | @Provider 30 | public class ResponseLoggingFilter implements ClientResponseFilter { 31 | 32 | private static final Logger LOG = LoggerFactory.getLogger(ResponseLoggingFilter.class); 33 | 34 | @Override 35 | public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { 36 | if (LOG.isDebugEnabled()) { 37 | LOG.debug("<< Response headers:{}", responseContext.getHeaders()); 38 | LOG.debug("<< Status -> code:{}, message:{}", 39 | responseContext.getStatusInfo().getStatusCode(), 40 | responseContext.getStatusInfo().getReasonPhrase()); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/fasterxml/jackson/ClientObjectMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.fasterxml.jackson; 18 | 19 | import org.hawkular.client.metrics.fasterxml.jackson.AvailabilityBucketPointMixin; 20 | import org.hawkular.client.metrics.fasterxml.jackson.AvailabilityTypeMixin; 21 | import org.hawkular.client.metrics.fasterxml.jackson.MetricTypeMixin; 22 | import org.hawkular.client.metrics.fasterxml.jackson.NumericBucketPointMixin; 23 | import org.hawkular.client.metrics.fasterxml.jackson.TaggedBucketPointMixin; 24 | import org.hawkular.client.metrics.fasterxml.jackson.TenantMixin; 25 | import org.hawkular.inventory.json.InventoryJacksonConfig; 26 | import org.hawkular.metrics.model.AvailabilityBucketPoint; 27 | import org.hawkular.metrics.model.AvailabilityType; 28 | import org.hawkular.metrics.model.MetricType; 29 | import org.hawkular.metrics.model.NumericBucketPoint; 30 | import org.hawkular.metrics.model.TaggedBucketPoint; 31 | import org.hawkular.metrics.model.Tenant; 32 | 33 | import com.fasterxml.jackson.annotation.JsonInclude; 34 | import com.fasterxml.jackson.databind.DeserializationFeature; 35 | import com.fasterxml.jackson.databind.ObjectMapper; 36 | import com.fasterxml.jackson.databind.SerializationFeature; 37 | 38 | public class ClientObjectMapper extends ObjectMapper { 39 | 40 | private static final long serialVersionUID = 1L; 41 | 42 | public ClientObjectMapper() { 43 | config(this); 44 | } 45 | 46 | public static ObjectMapper config(ObjectMapper mapper) { 47 | mapper.configure(SerializationFeature.INDENT_OUTPUT, true) 48 | .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) 49 | .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) 50 | .setSerializationInclusion(JsonInclude.Include.NON_NULL); 51 | 52 | addMetricMixins(mapper); 53 | addInventoryMixins(mapper); 54 | 55 | return mapper; 56 | } 57 | 58 | private static void addMetricMixins(ObjectMapper mapper) { 59 | mapper.addMixIn(Tenant.class, TenantMixin.class) 60 | .addMixIn(MetricType.class, MetricTypeMixin.class) 61 | .addMixIn(AvailabilityType.class, AvailabilityTypeMixin.class) 62 | .addMixIn(TaggedBucketPoint.class, TaggedBucketPointMixin.class) 63 | .addMixIn(NumericBucketPoint.class, NumericBucketPointMixin.class) 64 | .addMixIn(AvailabilityBucketPoint.class, AvailabilityBucketPointMixin.class); 65 | } 66 | 67 | private static void addInventoryMixins(ObjectMapper mapper) { 68 | InventoryJacksonConfig.configure(mapper); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/fasterxml/jackson/HCJacksonJson2Provider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.fasterxml.jackson; 18 | 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | import java.lang.annotation.Annotation; 22 | import java.lang.reflect.Type; 23 | 24 | import javax.ws.rs.Consumes; 25 | import javax.ws.rs.Produces; 26 | import javax.ws.rs.core.MediaType; 27 | import javax.ws.rs.core.MultivaluedMap; 28 | import javax.ws.rs.ext.Provider; 29 | 30 | import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider; 31 | 32 | /** 33 | * @author jkandasa@redhat.com (Jeeva Kandasamy) 34 | */ 35 | @Provider 36 | @Produces(MediaType.APPLICATION_JSON) 37 | @Consumes(MediaType.APPLICATION_JSON) 38 | public class HCJacksonJson2Provider extends ResteasyJackson2Provider { 39 | 40 | @Override 41 | public void writeTo(Object value, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, 42 | MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { 43 | ClientObjectMapper.config(locateMapper(type, mediaType)); 44 | 45 | super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/fasterxml/jackson/JacksonObjectMapperProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.fasterxml.jackson; 18 | 19 | import javax.ws.rs.ext.ContextResolver; 20 | import javax.ws.rs.ext.Provider; 21 | 22 | import com.fasterxml.jackson.databind.ObjectMapper; 23 | 24 | @Provider 25 | public class JacksonObjectMapperProvider implements ContextResolver { 26 | private final ObjectMapper objectMapper; 27 | 28 | public JacksonObjectMapperProvider() throws Exception { 29 | objectMapper = new ClientObjectMapper(); 30 | } 31 | 32 | @Override 33 | public ObjectMapper getContext(Class type) { 34 | return objectMapper; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/param/ConvertersProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.param; 18 | 19 | import java.lang.annotation.Annotation; 20 | import java.lang.reflect.Type; 21 | 22 | import javax.ws.rs.ext.ParamConverter; 23 | import javax.ws.rs.ext.ParamConverterProvider; 24 | import javax.ws.rs.ext.Provider; 25 | 26 | import org.hawkular.client.metrics.model.Order; 27 | import org.hawkular.metrics.model.param.Duration; 28 | import org.hawkular.metrics.model.param.Percentiles; 29 | import org.hawkular.metrics.model.param.Tags; 30 | 31 | import com.google.common.collect.ImmutableMap; 32 | 33 | /** 34 | * https://github.com/hawkular/hawkular-metrics/blob/master/api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/param/ConvertersProvider.java 35 | * 36 | * Provides Metrics {@link javax.ws.rs.ext.ParamConverterProvider} instances. 37 | * 38 | * @author Thomas Segismont 39 | */ 40 | @Provider 41 | public class ConvertersProvider implements ParamConverterProvider { 42 | private final ImmutableMap, ParamConverter> paramConverters; 43 | 44 | public ConvertersProvider() { 45 | ImmutableMap.Builder, ParamConverter> paramConvertersBuilder = ImmutableMap.builder(); 46 | paramConverters = paramConvertersBuilder 47 | .put(Duration.class, new DurationConverter()) 48 | .put(Tags.class, new TagsConverter()) 49 | .put(Order.class, new OrderConverter()) 50 | .put(Percentiles.class, new PercentilesConverter()) 51 | .build(); 52 | } 53 | 54 | @Override 55 | @SuppressWarnings("unchecked") 56 | public ParamConverter getConverter(Class rawType, Type genericType, Annotation[] annotations) { 57 | return (ParamConverter) paramConverters.get(rawType); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/param/DurationConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.param; 18 | 19 | import javax.ws.rs.ext.ParamConverter; 20 | 21 | import org.hawkular.metrics.model.param.Duration; 22 | 23 | /** 24 | * https://github.com/hawkular/hawkular-metrics/blob/master/api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/param/DurationConverter.java 25 | *

26 | * A JAX-RS {@link ParamConverter} for {@link Duration} parameters. 27 | * 28 | * @author Thomas Segismont 29 | */ 30 | public class DurationConverter implements ParamConverter { 31 | 32 | @Override 33 | public Duration fromString(String value) { 34 | return new Duration(value); 35 | } 36 | 37 | @Override 38 | public String toString(Duration duration) { 39 | return duration.getValue() + Duration.UNITS.get(duration.getTimeUnit()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/param/OrderConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.param; 18 | 19 | import org.hawkular.client.metrics.model.Order; 20 | 21 | /** 22 | * https://github.com/hawkular/hawkular-metrics/blob/master/api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/param/OrderConverter.java 23 | * 24 | * @author Thomas Segismont 25 | */ 26 | public class OrderConverter implements javax.ws.rs.ext.ParamConverter { 27 | @Override 28 | public Order fromString(String value) { 29 | return Order.fromText(value); 30 | } 31 | 32 | @Override 33 | public String toString(Order value) { 34 | return value.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/jaxrs/param/PercentilesConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.jaxrs.param; 18 | 19 | import java.util.Arrays; 20 | import java.util.stream.Collectors; 21 | 22 | import javax.ws.rs.ext.ParamConverter; 23 | 24 | import org.hawkular.metrics.model.Percentile; 25 | import org.hawkular.metrics.model.param.Percentiles; 26 | 27 | /** 28 | * https://github.com/hawkular/hawkular-metrics/blob/master/api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/jaxrs/param/PercentilesConverter.java 29 | * 30 | * A JAX-RS ParamConverter from number,number,number input string to a Percentiles or vice-versa. 31 | * 32 | * @author Michael Burman 33 | */ 34 | public class PercentilesConverter implements ParamConverter { 35 | @Override 36 | public Percentiles fromString(String param) { 37 | return new Percentiles(Arrays.stream(param.split(",")).map(Percentile::new).collect(Collectors.toList())); 38 | } 39 | 40 | @Override 41 | public String toString(Percentiles percentiles) { 42 | return percentiles.getPercentiles().stream().map(Percentile::getOriginalQuantile) 43 | .collect(Collectors.joining(",")); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/typeresolvers/CollectionJavaTypeResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.typeresolvers; 18 | 19 | import java.util.List; 20 | 21 | import org.hawkular.client.core.jaxrs.fasterxml.jackson.ClientObjectMapper; 22 | 23 | import com.fasterxml.jackson.databind.JavaType; 24 | import com.fasterxml.jackson.databind.ObjectMapper; 25 | 26 | public class CollectionJavaTypeResolver { 27 | 28 | private final ObjectMapper objectMapper; 29 | 30 | public CollectionJavaTypeResolver() { 31 | this.objectMapper = new ClientObjectMapper(); 32 | } 33 | 34 | /** 35 | * List with Generic, i.e.: List 36 | */ 37 | public JavaType get(Class collectionClazz, Class clazz) { 38 | JavaType clazzType = objectMapper.getTypeFactory().constructType(clazz); 39 | return objectMapper.getTypeFactory().constructCollectionType(collectionClazz, clazzType); 40 | } 41 | 42 | /** 43 | * List with Generic, Generic, i.e.: List> 44 | */ 45 | public JavaType get(Class collectionClazz, Class clazz, Class parametrizedClazz) { 46 | JavaType parametrizedClazzType = objectMapper.getTypeFactory().constructType(parametrizedClazz); 47 | JavaType clazzType = objectMapper.getTypeFactory().constructParametrizedType(clazz, clazz, parametrizedClazzType); 48 | 49 | return objectMapper.getTypeFactory().constructCollectionType(collectionClazz, clazzType); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/typeresolvers/MapJavaTypeResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.typeresolvers; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.jaxrs.fasterxml.jackson.ClientObjectMapper; 22 | 23 | import com.fasterxml.jackson.databind.JavaType; 24 | import com.fasterxml.jackson.databind.ObjectMapper; 25 | 26 | public class MapJavaTypeResolver { 27 | 28 | private final ObjectMapper objectMapper; 29 | 30 | public MapJavaTypeResolver() { 31 | this.objectMapper = new ClientObjectMapper(); 32 | } 33 | 34 | /** 35 | * Map with Generic Key and Value, i.e.: Map 36 | */ 37 | public JavaType get(Class mapClazz, Class mapClazzKey, Class mapClazzValue) { 38 | JavaType mapClazzKeyType = objectMapper.getTypeFactory().constructType(mapClazzKey); 39 | JavaType mapClazzValueType = objectMapper.getTypeFactory().constructType(mapClazzValue); 40 | 41 | return objectMapper.getTypeFactory().constructMapType(mapClazz, mapClazzKeyType, mapClazzValueType); 42 | } 43 | 44 | /** 45 | * Map with Generic Key and Genric Value, i.e.: Map> 46 | */ 47 | public JavaType get( 48 | Class mapClazz, Class mapClazzKey, Class mapClazzValue, Class mapClazzParametrizedValue) { 49 | JavaType mapClazzKeyType = objectMapper.getTypeFactory().constructType(mapClazzKey); 50 | JavaType parametrizedClazzType = objectMapper.getTypeFactory().constructParametrizedType(mapClazzValue, mapClazzValue, mapClazzParametrizedValue); 51 | 52 | return objectMapper.getTypeFactory().constructMapType(mapClazz, mapClazzKeyType, parametrizedClazzType); 53 | } 54 | 55 | /** 56 | * Map of a Map with Generic Key and Value, i.e.: Map> 57 | */ 58 | public JavaType get( 59 | Class mapClazz, Class mapClazzKey, Class mapClazzValue, Class mapClazzParametrizedKey, Class mapClazzParametrizedValue) { 60 | JavaType mapClazzKeyType = objectMapper.getTypeFactory().constructType(mapClazzKey); 61 | 62 | JavaType mapClazzParametrizedKeyType = objectMapper.getTypeFactory().constructType(mapClazzParametrizedKey); 63 | JavaType mapClazzParametrizedValueType = objectMapper.getTypeFactory().constructType(mapClazzParametrizedValue); 64 | JavaType innerMap = objectMapper.getTypeFactory().constructMapType(mapClazzValue, mapClazzParametrizedKeyType, mapClazzParametrizedValueType); 65 | 66 | return objectMapper.getTypeFactory().constructMapType(mapClazz, mapClazzKeyType, innerMap); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/core/typeresolvers/SimpleJavaTypeResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.core.typeresolvers; 18 | 19 | import org.hawkular.client.core.jaxrs.fasterxml.jackson.ClientObjectMapper; 20 | 21 | import com.fasterxml.jackson.databind.JavaType; 22 | import com.fasterxml.jackson.databind.ObjectMapper; 23 | 24 | public class SimpleJavaTypeResolver { 25 | 26 | private final ObjectMapper objectMapper; 27 | 28 | public SimpleJavaTypeResolver() { 29 | this.objectMapper = new ClientObjectMapper(); 30 | } 31 | 32 | /** 33 | * Simple Class, i.e.: Double 34 | */ 35 | public JavaType get(Class clazz) { 36 | return objectMapper.getTypeFactory().constructType(clazz); 37 | } 38 | 39 | /** 40 | * Simple Class with Generic, i.e.: Metric 41 | */ 42 | public JavaType get(Class clazz, Class parametrizedClazz) { 43 | JavaType parametrizedClazzType = objectMapper.getTypeFactory().constructType(parametrizedClazz); 44 | 45 | return objectMapper.getTypeFactory().constructParametrizedType(clazz, clazz, parametrizedClazzType); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/InventoryClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory; 18 | 19 | import org.hawkular.client.inventory.clients.APIInfoClient; 20 | import org.hawkular.client.inventory.clients.BulkCreateClient; 21 | import org.hawkular.client.inventory.clients.EventsClient; 22 | import org.hawkular.client.inventory.clients.GraphClient; 23 | import org.hawkular.client.inventory.clients.SingleEntityClient; 24 | import org.hawkular.client.inventory.clients.SyncClient; 25 | import org.hawkular.client.inventory.clients.TenantClient; 26 | import org.hawkular.client.inventory.clients.TraversalClient; 27 | 28 | public interface InventoryClient { 29 | 30 | APIInfoClient apiInfo(); 31 | 32 | BulkCreateClient bulkCreate(); 33 | 34 | TraversalClient traversal(); 35 | 36 | EventsClient events(); 37 | 38 | GraphClient graph(); 39 | 40 | SingleEntityClient singleEntity(); 41 | 42 | SyncClient sync(); 43 | 44 | TenantClient tenant(); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/APIInfoClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import org.hawkular.client.core.ClientResponse; 20 | import org.hawkular.client.inventory.model.InventoryJaxRsInfo; 21 | 22 | public interface APIInfoClient { 23 | 24 | /** 25 | * List Endpoints 26 | * 27 | * @return 28 | */ 29 | ClientResponse getEndpoints(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/BulkCreateClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.client.inventory.model.ElementType; 24 | import org.hawkular.inventory.paths.CanonicalPath; 25 | 26 | public interface BulkCreateClient { 27 | 28 | /** 29 | * Bulk creation of new entities. 30 | * 31 | * @param entities 32 | * @param at 33 | * @return 34 | */ 35 | ClientResponse>> create(Map>> entities, String at); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/DefaultAPIInfoClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import javax.ws.rs.core.Response; 20 | 21 | import org.hawkular.client.core.BaseClient; 22 | import org.hawkular.client.core.ClientInfo; 23 | import org.hawkular.client.core.ClientResponse; 24 | import org.hawkular.client.core.DefaultClientResponse; 25 | import org.hawkular.client.core.jaxrs.ResponseCodes; 26 | import org.hawkular.client.core.jaxrs.RestFactory; 27 | import org.hawkular.client.inventory.jaxrs.handlers.APIInfoHandler; 28 | import org.hawkular.client.inventory.model.InventoryJaxRsInfo; 29 | 30 | import com.fasterxml.jackson.databind.JavaType; 31 | 32 | public class DefaultAPIInfoClient extends BaseClient implements APIInfoClient { 33 | 34 | public DefaultAPIInfoClient(ClientInfo clientInfo) { 35 | super(clientInfo, new RestFactory(APIInfoHandler.class)); 36 | } 37 | 38 | @Override 39 | public ClientResponse getEndpoints() { 40 | Response serverResponse = null; 41 | 42 | try { 43 | serverResponse = restApi().getEndpoints(); 44 | JavaType javaType = simpleResolver().get(InventoryJaxRsInfo.class); 45 | 46 | return new DefaultClientResponse(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 47 | } finally { 48 | if (serverResponse != null) { 49 | serverResponse.close(); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/DefaultBulkCreateClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.core.Response; 23 | 24 | import org.hawkular.client.core.BaseClient; 25 | import org.hawkular.client.core.ClientInfo; 26 | import org.hawkular.client.core.ClientResponse; 27 | import org.hawkular.client.core.DefaultClientResponse; 28 | import org.hawkular.client.core.jaxrs.ResponseCodes; 29 | import org.hawkular.client.core.jaxrs.RestFactory; 30 | import org.hawkular.client.inventory.jaxrs.handlers.BulkCreateHandler; 31 | import org.hawkular.client.inventory.model.ElementType; 32 | import org.hawkular.inventory.paths.CanonicalPath; 33 | 34 | import com.fasterxml.jackson.databind.JavaType; 35 | 36 | public class DefaultBulkCreateClient extends BaseClient implements BulkCreateClient { 37 | 38 | public DefaultBulkCreateClient(ClientInfo clientInfo) { 39 | super(clientInfo, new RestFactory(BulkCreateHandler.class)); 40 | } 41 | 42 | @Override 43 | public ClientResponse>> create(Map>> entities, String at) { 44 | Response serverResponse = null; 45 | 46 | try { 47 | serverResponse = restApi().create(entities, at); 48 | JavaType javaType = mapResolver().get(Map.class, ElementType.class, Map.class, CanonicalPath.class, Integer.class); 49 | 50 | return new DefaultClientResponse>>(javaType, serverResponse, ResponseCodes.CREATE_SUCCESS_201); 51 | } finally { 52 | if (serverResponse != null) { 53 | serverResponse.close(); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/DefaultEventsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.core.Response; 23 | 24 | import org.hawkular.client.core.BaseClient; 25 | import org.hawkular.client.core.ClientInfo; 26 | import org.hawkular.client.core.ClientResponse; 27 | import org.hawkular.client.core.DefaultClientResponse; 28 | import org.hawkular.client.core.jaxrs.ResponseCodes; 29 | import org.hawkular.client.core.jaxrs.RestFactory; 30 | import org.hawkular.client.inventory.jaxrs.handlers.EventsHandler; 31 | import org.hawkular.inventory.api.Action; 32 | import org.hawkular.inventory.paths.SegmentType; 33 | 34 | import com.fasterxml.jackson.databind.JavaType; 35 | 36 | public class DefaultEventsClient extends BaseClient implements EventsClient { 37 | 38 | public DefaultEventsClient(ClientInfo clientInfo) { 39 | super(clientInfo, new RestFactory(EventsHandler.class)); 40 | } 41 | 42 | @Override 43 | public ClientResponse> getEvents(SegmentType type, Action.Enumerated action) { 44 | Response serverResponse = null; 45 | 46 | try { 47 | serverResponse = restApi().getEvents(type.getSimpleName(), action.name()); 48 | JavaType javaType = collectionResolver().get(List.class, Map.class); 49 | 50 | return new DefaultClientResponse>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 51 | } finally { 52 | if (serverResponse != null) { 53 | serverResponse.close(); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/DefaultGraphClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import javax.ws.rs.core.Response; 20 | 21 | import org.hawkular.client.core.BaseClient; 22 | import org.hawkular.client.core.ClientInfo; 23 | import org.hawkular.client.core.ClientResponse; 24 | import org.hawkular.client.core.DefaultClientResponse; 25 | import org.hawkular.client.core.jaxrs.ResponseCodes; 26 | import org.hawkular.client.core.jaxrs.RestFactory; 27 | import org.hawkular.client.inventory.jaxrs.handlers.GraphHandler; 28 | 29 | import com.fasterxml.jackson.databind.JavaType; 30 | 31 | public class DefaultGraphClient extends BaseClient implements GraphClient { 32 | 33 | public DefaultGraphClient(ClientInfo clientInfo) { 34 | super(clientInfo, new RestFactory(GraphHandler.class)); 35 | } 36 | 37 | @Override 38 | public ClientResponse getGraph() { 39 | Response serverResponse = null; 40 | 41 | try { 42 | serverResponse = restApi().getGraph(); 43 | JavaType javaType = simpleResolver().get(String.class); 44 | 45 | return new DefaultClientResponse(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 46 | } finally { 47 | if (serverResponse != null) { 48 | serverResponse.close(); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/DefaultSyncClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import javax.ws.rs.core.Response; 20 | 21 | import org.hawkular.client.core.BaseClient; 22 | import org.hawkular.client.core.ClientInfo; 23 | import org.hawkular.client.core.ClientResponse; 24 | import org.hawkular.client.core.DefaultClientResponse; 25 | import org.hawkular.client.core.jaxrs.Empty; 26 | import org.hawkular.client.core.jaxrs.ResponseCodes; 27 | import org.hawkular.client.core.jaxrs.RestFactory; 28 | import org.hawkular.client.inventory.jaxrs.handlers.SyncHandler; 29 | import org.hawkular.inventory.api.model.SyncRequest; 30 | import org.hawkular.inventory.paths.CanonicalPath; 31 | 32 | import com.fasterxml.jackson.databind.JavaType; 33 | 34 | public class DefaultSyncClient extends BaseClient implements SyncClient { 35 | 36 | public DefaultSyncClient(ClientInfo clientInfo) { 37 | super(clientInfo, new RestFactory(SyncHandler.class)); 38 | } 39 | 40 | @Override 41 | public ClientResponse synchronize(CanonicalPath path, String at, SyncRequest request) { 42 | Response serverResponse = null; 43 | 44 | try { 45 | serverResponse = restApi().synchronize(path.toRelativePath().toString(), at, request); 46 | JavaType javaType = simpleResolver().get(Empty.class); 47 | 48 | return new DefaultClientResponse(javaType, serverResponse, ResponseCodes.UPDATE_SUCCESS_204); 49 | } finally { 50 | if (serverResponse != null) { 51 | serverResponse.close(); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/EventsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.inventory.api.Action; 24 | import org.hawkular.inventory.paths.SegmentType; 25 | 26 | public interface EventsClient { 27 | 28 | /** 29 | * Listen on stream of the events 30 | * 31 | * @param type 32 | * @param action 33 | * @return 34 | */ 35 | ClientResponse> getEvents(SegmentType type, Action.Enumerated action); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/GraphClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import org.hawkular.client.core.ClientResponse; 20 | 21 | public interface GraphClient { 22 | 23 | /** 24 | * Gets the graph. 25 | * 26 | * @return 27 | */ 28 | ClientResponse getGraph(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/SingleEntityClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.client.core.jaxrs.Empty; 24 | import org.hawkular.inventory.api.model.AbstractElement; 25 | import org.hawkular.inventory.api.model.Change; 26 | import org.hawkular.inventory.api.model.IdentityHash; 27 | import org.hawkular.inventory.paths.CanonicalPath; 28 | import org.hawkular.inventory.paths.SegmentType; 29 | 30 | public interface SingleEntityClient { 31 | 32 | /** 33 | * Deletes an inventory entity on the given location. 34 | * 35 | * @param path 36 | * @param at 37 | * @return 38 | */ 39 | ClientResponse deleteEntity(CanonicalPath path, String at); 40 | 41 | /** 42 | * Reads an inventory entity on the given location. 43 | * TODO: Response should be a: http://www.hawkular.org/docs/rest/rest-inventory.html#AbstractElement 44 | * 45 | * @param path 46 | * @param at 47 | * @return 48 | */ 49 | ClientResponse getEntity(CanonicalPath path, String at); 50 | 51 | /** 52 | * Updates an entity. The path is actually a canonical path. 53 | * The format of the accepted JSON object is governed by the type of the entity being updated. If you’re updating an environment, 54 | * look for EnvironmentUpdate type, etc. 55 | * 56 | * @param path 57 | * @param at 58 | * @param update 59 | * @return 60 | */ 61 | ClientResponse updateEntity(CanonicalPath path, String at, AbstractElement.Update update); 62 | 63 | /** 64 | * Obtains the history of the entity. 65 | * 66 | * @param path 67 | * @param from 68 | * @param to 69 | * @return 70 | */ 71 | ClientResponse>> getHistory(CanonicalPath path, String from, String to); 72 | 73 | /** 74 | * Obtains the identity tree hash of the entity. 75 | * 76 | * @param path 77 | * @param at 78 | * @return 79 | */ 80 | ClientResponse getEntityHash(CanonicalPath path, String at); 81 | 82 | /** 83 | * Creates a new entity 84 | * TODO: Response should be a: http://www.hawkular.org/docs/rest/rest-inventory.html#AbstractElement 85 | * 86 | * @param path 87 | * @param type 88 | * @param at 89 | * @param entity 90 | * @return 91 | */ 92 | ClientResponse createEntity(CanonicalPath path, SegmentType type, String at, AbstractElement.Blueprint entity); 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/SyncClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import org.hawkular.client.core.ClientResponse; 20 | import org.hawkular.client.core.jaxrs.Empty; 21 | import org.hawkular.inventory.api.model.SyncRequest; 22 | import org.hawkular.inventory.paths.CanonicalPath; 23 | 24 | public interface SyncClient { 25 | 26 | /** 27 | * Make the inventory under given path match the provided inventory structure. 28 | * Note that the relationships specified in the provided entities will be ignored and will not be applied. 29 | * @param path 30 | * @param at 31 | * @param request 32 | * @return 33 | */ 34 | ClientResponse synchronize(CanonicalPath path, String at, SyncRequest request); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/TenantClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | import org.hawkular.client.core.jaxrs.Empty; 23 | import org.hawkular.inventory.api.model.Relationship; 24 | import org.hawkular.inventory.api.model.Tenant; 25 | import org.hawkular.inventory.paths.CanonicalPath; 26 | 27 | public interface TenantClient { 28 | 29 | /** 30 | * Retrieves the details of the current tenant. 31 | * 32 | * @param at 33 | * @return 34 | */ 35 | ClientResponse getTenant(String at); 36 | 37 | /** 38 | * Updates the properties of the tenant 39 | * 40 | * @param at 41 | * @param update 42 | * @return 43 | */ 44 | ClientResponse createTenant(String at, Tenant.Update update); 45 | 46 | /** 47 | * Creates new relationship(s) on a tenant 48 | * 49 | * @param at 50 | * @param blueprints 51 | * @return 52 | */ 53 | ClientResponse> createRelationship(String at, List blueprints); 54 | 55 | /** 56 | * Retrieves tenant’s relationships 57 | * 58 | * @param path 59 | * @param at 60 | * @return 61 | */ 62 | ClientResponse> getRelationships(CanonicalPath path, String at); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/clients/TraversalClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.inventory.api.Relationships; 24 | import org.hawkular.inventory.api.paging.Order; 25 | import org.hawkular.inventory.paths.CanonicalPath; 26 | import org.hawkular.inventory.paths.SegmentType; 27 | 28 | public interface TraversalClient { 29 | 30 | /** 31 | * Retrieves a list of entities 32 | * 33 | * @param traversal 34 | * @param at 35 | * @param page 36 | * @param per_page 37 | * @param sort 38 | * @param order 39 | * @param type 40 | * @param id 41 | * @param name 42 | * @param cp 43 | * @param propertyName 44 | * @param propertyValue 45 | * @param relatedBy 46 | * @param relatedTo 47 | * @param relatedWith 48 | * @param definedBy 49 | * @return 50 | */ 51 | ClientResponse> getTraversal(CanonicalPath traversal, String at, 52 | Integer page, Integer per_page, String sort, Order.Direction order, 53 | SegmentType type, String id, String name, CanonicalPath cp, String propertyName, 54 | String propertyValue, Relationships.WellKnown relatedBy, CanonicalPath relatedTo, 55 | CanonicalPath relatedWith, String definedBy); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/APIInfoHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.core.MediaType; 24 | import javax.ws.rs.core.Response; 25 | 26 | /** 27 | * APIInfo API 28 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_api_info 29 | */ 30 | @Path("/hawkular/inventory") 31 | @Produces(MediaType.APPLICATION_JSON) 32 | @Consumes(MediaType.APPLICATION_JSON) 33 | public interface APIInfoHandler { 34 | 35 | @GET 36 | @Path("/") 37 | Response getEndpoints(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/BulkCreateHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.Consumes; 23 | import javax.ws.rs.POST; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.Produces; 26 | import javax.ws.rs.QueryParam; 27 | import javax.ws.rs.core.MediaType; 28 | import javax.ws.rs.core.Response; 29 | 30 | import org.hawkular.client.inventory.model.ElementType; 31 | 32 | /** 33 | * Bulk Create API 34 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_bulk_create 35 | */ 36 | @Path("/hawkular/inventory/bulk") 37 | @Produces(MediaType.APPLICATION_JSON) 38 | @Consumes(MediaType.APPLICATION_JSON) 39 | public interface BulkCreateHandler { 40 | 41 | @POST 42 | @Path("/") 43 | Response create(Map>> entities, @QueryParam("at") String at); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/EventsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.QueryParam; 24 | import javax.ws.rs.core.MediaType; 25 | import javax.ws.rs.core.Response; 26 | 27 | /** 28 | * Events API 29 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_events 30 | */ 31 | @Path("/hawkular/inventory/events") 32 | @Produces(MediaType.APPLICATION_JSON) 33 | @Consumes(MediaType.APPLICATION_JSON) 34 | public interface EventsHandler { 35 | 36 | @GET 37 | @Path("/") 38 | Response getEvents(@QueryParam("type") String type, @QueryParam("action") String action); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/GraphHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.core.MediaType; 24 | import javax.ws.rs.core.Response; 25 | 26 | /** 27 | * Graph API 28 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_graph 29 | */ 30 | @Path("/hawkular/inventory/graph") 31 | @Produces(MediaType.APPLICATION_JSON) 32 | @Consumes(MediaType.APPLICATION_JSON) 33 | public interface GraphHandler { 34 | 35 | @GET 36 | @Path("/") 37 | Response getGraph(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/SingleEntityHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.DELETE; 21 | import javax.ws.rs.Encoded; 22 | import javax.ws.rs.GET; 23 | import javax.ws.rs.POST; 24 | import javax.ws.rs.PUT; 25 | import javax.ws.rs.Path; 26 | import javax.ws.rs.PathParam; 27 | import javax.ws.rs.Produces; 28 | import javax.ws.rs.QueryParam; 29 | import javax.ws.rs.core.MediaType; 30 | import javax.ws.rs.core.Response; 31 | 32 | import org.hawkular.inventory.api.model.AbstractElement; 33 | 34 | /** 35 | * Single Entity API 36 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_single_entity 37 | */ 38 | @Path("/hawkular/inventory/entity") 39 | @Produces(MediaType.APPLICATION_JSON) 40 | @Consumes(MediaType.APPLICATION_JSON) 41 | public interface SingleEntityHandler { 42 | 43 | @DELETE 44 | @Path("/{path}") 45 | Response deleteEntity(@Encoded @PathParam("path") String path, @QueryParam("at") String at); 46 | 47 | @GET 48 | @Path("/{path}") 49 | Response getEntity(@Encoded @PathParam("path") String path, @QueryParam("at") String at); 50 | 51 | @PUT 52 | @Path("/{path}") 53 | Response updateEntity(@Encoded @PathParam("path") String path, @QueryParam("at") String at, AbstractElement.Update update); 54 | 55 | @GET 56 | @Path("/{path}/history") 57 | Response getHistory(@Encoded @PathParam("path") String path, @QueryParam("from") String from, @QueryParam("to") String to); 58 | 59 | @GET 60 | @Path("/{path}/treeHash") 61 | Response getEntityHash(@Encoded @PathParam("path") String path, @QueryParam("at") String at); 62 | 63 | @POST 64 | @Path("/{path}/{type}") 65 | Response createEntity(@Encoded @PathParam("path") String path, @PathParam("type") String type, @QueryParam("at") String at, 66 | AbstractElement.Blueprint entity); 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/SyncHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.Encoded; 21 | import javax.ws.rs.POST; 22 | import javax.ws.rs.Path; 23 | import javax.ws.rs.PathParam; 24 | import javax.ws.rs.Produces; 25 | import javax.ws.rs.QueryParam; 26 | import javax.ws.rs.core.MediaType; 27 | import javax.ws.rs.core.Response; 28 | 29 | import org.hawkular.inventory.api.model.SyncRequest; 30 | 31 | /** 32 | * Sync API 33 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_sync 34 | */ 35 | @Path("/hawkular/inventory/sync") 36 | @Produces(MediaType.APPLICATION_JSON) 37 | @Consumes(MediaType.APPLICATION_JSON) 38 | public interface SyncHandler { 39 | 40 | @POST 41 | @Path("/{path}") 42 | Response synchronize(@Encoded @PathParam("path") String path, @QueryParam("at") String at, SyncRequest request); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/TenantHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import java.util.List; 20 | 21 | import javax.ws.rs.Consumes; 22 | import javax.ws.rs.Encoded; 23 | import javax.ws.rs.GET; 24 | import javax.ws.rs.POST; 25 | import javax.ws.rs.PUT; 26 | import javax.ws.rs.Path; 27 | import javax.ws.rs.PathParam; 28 | import javax.ws.rs.Produces; 29 | import javax.ws.rs.QueryParam; 30 | import javax.ws.rs.core.MediaType; 31 | import javax.ws.rs.core.Response; 32 | 33 | import org.hawkular.inventory.api.model.Relationship; 34 | import org.hawkular.inventory.api.model.Tenant; 35 | 36 | /** 37 | * Tenant Information API 38 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_tenant_information 39 | */ 40 | @Path("/hawkular/inventory/tenant") 41 | @Produces(MediaType.APPLICATION_JSON) 42 | @Consumes(MediaType.APPLICATION_JSON) 43 | public interface TenantHandler { 44 | 45 | @GET 46 | @Path("/") 47 | Response getTenant(@QueryParam("at") String at); 48 | 49 | @PUT 50 | @Path("/") 51 | Response createTenant(@QueryParam("at") String at, Tenant.Update update); 52 | 53 | @POST 54 | @Path("/relationship") 55 | Response createRelationship(@QueryParam("at") String at, List blueprints); 56 | 57 | @GET 58 | @Path("/relationships/{path}") 59 | Response getRelationships(@Encoded @PathParam("path") String path, @QueryParam("at") String at); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/jaxrs/handlers/TraversalHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.Encoded; 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.Path; 23 | import javax.ws.rs.PathParam; 24 | import javax.ws.rs.Produces; 25 | import javax.ws.rs.QueryParam; 26 | import javax.ws.rs.core.MediaType; 27 | import javax.ws.rs.core.Response; 28 | 29 | /** 30 | * Traversal API 31 | * http://www.hawkular.org/docs/rest/rest-inventory.html#_entity_graph_traversal 32 | */ 33 | @Path("/hawkular/inventory/traversal") 34 | @Produces(MediaType.APPLICATION_JSON) 35 | @Consumes(MediaType.APPLICATION_JSON) 36 | public interface TraversalHandler { 37 | 38 | @GET 39 | @Path("/{traversal}/{filter}") 40 | Response getTraversal(@Encoded @PathParam("traversal") String traversal, @QueryParam("at") String at, 41 | @QueryParam("page") Integer page, @QueryParam("per_page") Integer per_page, 42 | @QueryParam("sort") String sort, @QueryParam("order") String order, 43 | @PathParam("filter") String filter); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/json/Endpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.json; 18 | 19 | import java.util.ArrayList; 20 | 21 | public class Endpoint { 22 | private ArrayList methods; 23 | private String uri; 24 | 25 | public Endpoint(ArrayList methods, String uri) { 26 | this.methods = methods; 27 | this.uri = uri; 28 | } 29 | 30 | public Endpoint() { 31 | 32 | } 33 | 34 | public ArrayList getMethods() { 35 | return methods; 36 | } 37 | 38 | public void setMethods(ArrayList methods) { 39 | this.methods = methods; 40 | } 41 | 42 | public String getUri() { 43 | return uri; 44 | } 45 | 46 | public void setUri(String uri) { 47 | this.uri = uri; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/json/Endpoints.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.json; 18 | 19 | import java.util.ArrayList; 20 | 21 | public class Endpoints { 22 | private ArrayList endpoints; 23 | private String documentation; 24 | 25 | public Endpoints(ArrayList endpoints, String documentation) { 26 | 27 | } 28 | 29 | public Endpoints() { 30 | 31 | } 32 | 33 | public ArrayList getEndpoints() { 34 | return endpoints; 35 | } 36 | 37 | public void setEndpoints(ArrayList endpoints) { 38 | this.endpoints = endpoints; 39 | } 40 | 41 | public String getDocumentation() { 42 | return documentation; 43 | } 44 | 45 | public void setDocumentation(String documentation) { 46 | this.documentation = documentation; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/json/IdJSON.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.json; 18 | 19 | /** 20 | * Simple wrapper for Ids 21 | * @author Heiko Rupp 22 | */ 23 | public class IdJSON { 24 | 25 | String id; 26 | 27 | public IdJSON() { 28 | } 29 | 30 | public IdJSON(String id) { 31 | this.id = id; 32 | } 33 | 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | public void setId(String id) { 39 | this.id = id; 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/json/StringValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.json; 18 | /** 19 | * Encapsulate a simple string value 20 | * @author Heiko W. Rupp 21 | */ 22 | public class StringValue { 23 | 24 | String value; 25 | 26 | public StringValue() { 27 | } 28 | 29 | public StringValue(String value) { 30 | this.value = value; 31 | } 32 | 33 | public String getValue() { 34 | return value; 35 | } 36 | 37 | public void setValue(String value) { 38 | this.value = value; 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/model/InventoryJaxRsInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.model; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * https://github.com/hawkular/hawkular-inventory/blob/master/hawkular-inventory-rest-api/src/main/java/org/hawkular/inventory/rest/RestPing.java 24 | */ 25 | public class InventoryJaxRsInfo { 26 | private static final String DOC_URL = "http://www.hawkular.org/"; 27 | 28 | private List endpoints = new ArrayList<>(); 29 | 30 | public InventoryJaxRsInfo() { 31 | 32 | } 33 | 34 | public String getDocumentation() { 35 | return DOC_URL; 36 | } 37 | 38 | public List getEndpoints() { 39 | return endpoints; 40 | } 41 | 42 | public boolean addJaxRsResources(JaxRsResource jaxRsResources) { 43 | return this.endpoints.add(jaxRsResources); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/inventory/model/JaxRsResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.inventory.model; 18 | 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | import java.util.regex.Matcher; 22 | import java.util.regex.Pattern; 23 | 24 | /** 25 | * https://github.com/hawkular/hawkular-inventory/blob/master/hawkular-inventory-rest-api/src/main/java/org/hawkular/inventory/rest/RestPing.java 26 | */ 27 | public class JaxRsResource implements Comparable { 28 | 29 | private static final Pattern NAME_PATTERN = Pattern.compile("(/[a-zA-Z]+)"); 30 | 31 | private Set methods = new HashSet<>(); 32 | private String uri; 33 | 34 | public JaxRsResource() { 35 | 36 | } 37 | 38 | public JaxRsResource(String uri) { 39 | this.uri = uri; 40 | } 41 | 42 | public boolean addMethod(String method) { 43 | return methods.add(method); 44 | } 45 | 46 | public Set getMethods() { 47 | return methods; 48 | } 49 | 50 | public String getUri() { 51 | return uri; 52 | } 53 | 54 | public void setUri(String uri) { 55 | this.uri = uri; 56 | } 57 | 58 | private String getUriPattern(String uri) { 59 | Matcher matcher = NAME_PATTERN.matcher(uri); 60 | if (matcher.find()) { 61 | return matcher.group(); 62 | } 63 | 64 | return uri; 65 | } 66 | 67 | @Override 68 | public int compareTo(JaxRsResource that) { 69 | if (this == that) { 70 | return 0; 71 | } 72 | 73 | String other = getUriPattern(that.getUri()); 74 | String current = getUriPattern(this.uri); 75 | 76 | return current.compareTo(other); 77 | } 78 | 79 | @Override 80 | public boolean equals(Object o) { 81 | if (this == o) 82 | return true; 83 | if (!(o instanceof JaxRsResource)) 84 | return false; 85 | 86 | JaxRsResource that = (JaxRsResource)o; 87 | 88 | return !(uri != null ? !uri.equals(that.uri) : that.uri != null); 89 | 90 | } 91 | 92 | @Override 93 | public int hashCode() { 94 | return uri != null ? uri.hashCode() : 0; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/MetricsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics; 18 | 19 | import org.hawkular.client.metrics.clients.AvailabilityClient; 20 | import org.hawkular.client.metrics.clients.CounterClient; 21 | import org.hawkular.client.metrics.clients.GaugeClient; 22 | import org.hawkular.client.metrics.clients.MetricClient; 23 | import org.hawkular.client.metrics.clients.PingClient; 24 | import org.hawkular.client.metrics.clients.StatusClient; 25 | import org.hawkular.client.metrics.clients.StringClient; 26 | import org.hawkular.client.metrics.clients.TenantClient; 27 | 28 | /** 29 | * http://www.hawkular.org/docs/rest/rest-metrics.html 30 | */ 31 | public interface MetricsClient { 32 | 33 | AvailabilityClient availability(); 34 | 35 | CounterClient counter(); 36 | 37 | GaugeClient gauge(); 38 | 39 | MetricClient metric(); 40 | 41 | StringClient string(); 42 | 43 | TenantClient tenant(); 44 | 45 | PingClient ping(); 46 | 47 | StatusClient status(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/DefaultPingClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.Map; 20 | 21 | import javax.ws.rs.core.Response; 22 | 23 | import org.hawkular.client.core.BaseClient; 24 | import org.hawkular.client.core.ClientInfo; 25 | import org.hawkular.client.core.ClientResponse; 26 | import org.hawkular.client.core.DefaultClientResponse; 27 | import org.hawkular.client.core.jaxrs.ResponseCodes; 28 | import org.hawkular.client.core.jaxrs.RestFactory; 29 | import org.hawkular.client.metrics.jaxrs.handlers.PingHandler; 30 | 31 | import com.fasterxml.jackson.databind.JavaType; 32 | 33 | public class DefaultPingClient extends BaseClient implements PingClient { 34 | 35 | public DefaultPingClient(ClientInfo clientInfo) { 36 | super(clientInfo, new RestFactory<>(PingHandler.class)); 37 | } 38 | 39 | @Override 40 | public ClientResponse> ping() { 41 | Response serverResponse = null; 42 | 43 | try { 44 | serverResponse = restApi().ping(); 45 | JavaType javaType = mapResolver().get(Map.class, String.class, String.class); 46 | 47 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 48 | } finally { 49 | if (serverResponse != null) { 50 | serverResponse.close(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/DefaultStatusClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.Map; 20 | 21 | import javax.ws.rs.core.Response; 22 | 23 | import org.hawkular.client.core.BaseClient; 24 | import org.hawkular.client.core.ClientInfo; 25 | import org.hawkular.client.core.ClientResponse; 26 | import org.hawkular.client.core.DefaultClientResponse; 27 | import org.hawkular.client.core.jaxrs.ResponseCodes; 28 | import org.hawkular.client.core.jaxrs.RestFactory; 29 | import org.hawkular.client.metrics.jaxrs.handlers.StatusHandler; 30 | 31 | import com.fasterxml.jackson.databind.JavaType; 32 | 33 | public class DefaultStatusClient extends BaseClient implements StatusClient { 34 | 35 | public DefaultStatusClient(ClientInfo clientInfo) { 36 | super(clientInfo, new RestFactory<>(StatusHandler.class)); 37 | } 38 | 39 | @Override 40 | public ClientResponse> status() { 41 | Response serverResponse = null; 42 | 43 | try { 44 | serverResponse = restApi().status(); 45 | JavaType javaType = mapResolver().get(Map.class, String.class, String.class); 46 | 47 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 48 | } finally { 49 | if (serverResponse != null) { 50 | serverResponse.close(); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/DefaultTenantClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.core.Response; 23 | 24 | import org.hawkular.client.core.BaseClient; 25 | import org.hawkular.client.core.ClientInfo; 26 | import org.hawkular.client.core.ClientResponse; 27 | import org.hawkular.client.core.DefaultClientResponse; 28 | import org.hawkular.client.core.jaxrs.Empty; 29 | import org.hawkular.client.core.jaxrs.ResponseCodes; 30 | import org.hawkular.client.core.jaxrs.RestFactory; 31 | import org.hawkular.client.metrics.jaxrs.handlers.TenantHandler; 32 | import org.hawkular.metrics.model.Tenant; 33 | 34 | import com.fasterxml.jackson.databind.JavaType; 35 | 36 | public class DefaultTenantClient extends BaseClient implements TenantClient { 37 | 38 | public DefaultTenantClient(ClientInfo clientInfo) { 39 | super(clientInfo, new RestFactory<>(TenantHandler.class)); 40 | } 41 | 42 | @Override 43 | public ClientResponse> getTenants() { 44 | Response serverResponse = null; 45 | 46 | try { 47 | serverResponse = restApi().getTenants(); 48 | JavaType javaType = collectionResolver().get(List.class, Tenant.class); 49 | 50 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.GET_SUCCESS_200); 51 | } finally { 52 | if (serverResponse != null) { 53 | serverResponse.close(); 54 | } 55 | } 56 | } 57 | 58 | @Override 59 | public ClientResponse createTenant(Boolean overwrite, Tenant tenant) { 60 | Response serverResponse = null; 61 | 62 | try { 63 | serverResponse = restApi().createTenant(overwrite, tenant); 64 | JavaType javaType = simpleResolver().get(Empty.class); 65 | 66 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.CREATE_SUCCESS_201); 67 | } finally { 68 | if (serverResponse != null) { 69 | serverResponse.close(); 70 | } 71 | } 72 | } 73 | 74 | @Override 75 | public ClientResponse> deleteTenant(String id) { 76 | Response serverResponse = null; 77 | 78 | try { 79 | serverResponse = restApi().deleteTenant(id); 80 | JavaType javaType = mapResolver().get(Map.class, String.class, String.class); 81 | 82 | return new DefaultClientResponse<>(javaType, serverResponse, ResponseCodes.DELETE_SUCCESS_200); 83 | } finally { 84 | if (serverResponse != null) { 85 | serverResponse.close(); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/MetricClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.client.core.jaxrs.Empty; 24 | import org.hawkular.metrics.model.Metric; 25 | import org.hawkular.metrics.model.MetricType; 26 | import org.hawkular.metrics.model.MixedMetricsRequest; 27 | import org.hawkular.metrics.model.param.Tags; 28 | 29 | public interface MetricClient { 30 | 31 | /** 32 | * Find tenant’s metric definitions. 33 | * @param metricType 34 | * @param tags 35 | * @param id 36 | * @return 37 | */ 38 | ClientResponse>> findMetrics(MetricType metricType, Tags tags, String id); 39 | 40 | /** 41 | * Create metric. 42 | * @param overwrite 43 | * @param metric 44 | * @return 45 | */ 46 | ClientResponse createMetric(Boolean overwrite, Metric metric); 47 | 48 | /** 49 | * Add data points for multiple metrics in a single call. 50 | * @param metricsRequest 51 | * @return 52 | */ 53 | ClientResponse addMetricsData(MixedMetricsRequest metricsRequest); 54 | 55 | /** 56 | * Retrieve metrics' tag values 57 | * @param tags 58 | * @param metricType 59 | * @return 60 | */ 61 | ClientResponse>> findMetricsTags(Tags tags, MetricType metricType); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/PingClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | 23 | public interface PingClient { 24 | 25 | ClientResponse> ping(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/StatusClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | 23 | public interface StatusClient { 24 | 25 | ClientResponse> status(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/clients/TenantClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.clients; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.PathParam; 23 | 24 | import org.hawkular.client.core.ClientResponse; 25 | import org.hawkular.client.core.jaxrs.Empty; 26 | import org.hawkular.metrics.model.Tenant; 27 | 28 | public interface TenantClient { 29 | 30 | /** 31 | * Returns a list of tenants. 32 | * 33 | * @return 34 | */ 35 | ClientResponse> getTenants(); 36 | 37 | /** 38 | * Create a new tenant. 39 | * 40 | * @param overwrite 41 | * @param tenant 42 | * @return 43 | */ 44 | ClientResponse createTenant(Boolean overwrite, Tenant tenant); 45 | 46 | /** 47 | * Delete a tenant. 48 | * 49 | * @param id 50 | * @return 51 | */ 52 | ClientResponse> deleteTenant(@PathParam("id") String id); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/AvailabilityBucketPointDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import java.io.IOException; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import org.hawkular.metrics.model.AvailabilityBucketPoint; 24 | import org.hawkular.metrics.model.AvailabilityType; 25 | 26 | import com.fasterxml.jackson.core.JsonParser; 27 | import com.fasterxml.jackson.core.ObjectCodec; 28 | import com.fasterxml.jackson.databind.DeserializationContext; 29 | import com.fasterxml.jackson.databind.JsonDeserializer; 30 | import com.fasterxml.jackson.databind.JsonNode; 31 | 32 | public class AvailabilityBucketPointDeserializer extends JsonDeserializer { 33 | 34 | @SuppressWarnings("unchecked") 35 | @Override 36 | public AvailabilityBucketPoint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { 37 | ObjectCodec objectCodec = jp.getCodec(); 38 | JsonNode node = objectCodec.readTree(jp); 39 | 40 | long start = 0L; 41 | JsonNode startJsonNode = node.get("start"); 42 | if (startJsonNode != null) { 43 | start = startJsonNode.asLong(); 44 | } 45 | 46 | long end = 0L; 47 | JsonNode endJsonNode = node.get("end"); 48 | if (endJsonNode != null) { 49 | end = endJsonNode.asLong(); 50 | } 51 | 52 | JsonNode durationMapJsonNode = node.get("durationMap"); 53 | JsonNode lastNotUptimeJsonNode = node.get("lastNotUptime"); 54 | JsonNode uptimeRatioJsonNode = node.get("uptimeRatio"); 55 | JsonNode notUpCountJsonNode = node.get("notUpCount"); 56 | JsonNode adminDurationJsonNode = node.get("adminDuration"); 57 | JsonNode downDurationJsonNode = node.get("downDuration"); 58 | 59 | return new AvailabilityBucketPoint.Builder(start, end) 60 | .setDurationMap(durationMapJsonNode == null ? new HashMap() : objectCodec.treeToValue(durationMapJsonNode, Map.class)) 61 | .setAdminDuration(adminDurationJsonNode == null ? 0L : adminDurationJsonNode.asLong()) 62 | .setLastNotUptime(lastNotUptimeJsonNode == null ? 0L : lastNotUptimeJsonNode.asLong()) 63 | .setDownDuration(downDurationJsonNode == null ? 0L : downDurationJsonNode.asLong()) 64 | .setUptimeRatio(uptimeRatioJsonNode == null ? 0L : uptimeRatioJsonNode.asLong()) 65 | .setNotUptimeCount(notUpCountJsonNode == null ? 0L : notUpCountJsonNode.asLong()) 66 | .build(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/AvailabilityBucketPointMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 20 | 21 | @JsonDeserialize(using = AvailabilityBucketPointDeserializer.class) 22 | public abstract class AvailabilityBucketPointMixin { 23 | } 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/AvailabilityTypeMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import org.hawkular.metrics.model.fasterxml.jackson.AvailabilityTypeDeserializer; 20 | import org.hawkular.metrics.model.fasterxml.jackson.AvailabilityTypeSerializer; 21 | 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 24 | 25 | @JsonDeserialize(using = AvailabilityTypeDeserializer.class) 26 | @JsonSerialize(using = AvailabilityTypeSerializer.class) 27 | public abstract class AvailabilityTypeMixin { 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/MetricTypeMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import org.hawkular.metrics.model.fasterxml.jackson.MetricTypeDeserializer; 20 | import org.hawkular.metrics.model.fasterxml.jackson.MetricTypeSerializer; 21 | 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 24 | 25 | /** 26 | * @author jkandasa@redhat.com (Jeeva Kandasamy) 27 | */ 28 | @JsonDeserialize(using = MetricTypeDeserializer.class) 29 | @JsonSerialize(using = MetricTypeSerializer.class) 30 | public abstract class MetricTypeMixin { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/NumericBucketPointDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import java.io.IOException; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import org.hawkular.metrics.model.NumericBucketPoint; 24 | import org.hawkular.metrics.model.Percentile; 25 | 26 | import com.fasterxml.jackson.core.JsonParser; 27 | import com.fasterxml.jackson.core.ObjectCodec; 28 | import com.fasterxml.jackson.databind.DeserializationContext; 29 | import com.fasterxml.jackson.databind.JsonDeserializer; 30 | import com.fasterxml.jackson.databind.JsonNode; 31 | 32 | /** 33 | * Response causes Constructor Miss-match, due to "empty" field 34 | * TODO: get metrics to exclude "empty" from model 35 | */ 36 | public class NumericBucketPointDeserializer extends JsonDeserializer { 37 | 38 | @SuppressWarnings("unchecked") 39 | @Override 40 | public NumericBucketPoint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { 41 | ObjectCodec objectCodec = jp.getCodec(); 42 | JsonNode node = objectCodec.readTree(jp); 43 | 44 | long start = 0L; 45 | JsonNode startJsonNode = node.get("start"); 46 | if (startJsonNode != null) { 47 | start = startJsonNode.asLong(); 48 | } 49 | 50 | long end = 0L; 51 | JsonNode endJsonNode = node.get("end"); 52 | if (endJsonNode != null) { 53 | end = endJsonNode.asLong(); 54 | } 55 | 56 | JsonNode minJsonNode = node.get("min"); 57 | JsonNode avgJsonNode = node.get("avg"); 58 | JsonNode medianJsonNode = node.get("median"); 59 | JsonNode maxJsonNode = node.get("max"); 60 | JsonNode sumJsonNode = node.get("sum"); 61 | JsonNode samplesJsonNode = node.get("samples"); 62 | 63 | JsonNode percentilesJsonNode = node.get("percentiles"); 64 | List percentiles = new ArrayList(); 65 | if (percentilesJsonNode != null) { 66 | percentiles = objectCodec.treeToValue(percentilesJsonNode, List.class); 67 | } 68 | 69 | return new NumericBucketPoint.Builder(start, end) 70 | .setMin(minJsonNode == null ? 0 : minJsonNode.asDouble()) 71 | .setAvg(avgJsonNode == null ? 0 : avgJsonNode.asDouble()) 72 | .setMedian(medianJsonNode == null ? 0 : medianJsonNode.asDouble()) 73 | .setMax(maxJsonNode == null ? 0 : maxJsonNode.asDouble()) 74 | .setSum(sumJsonNode == null ? 0 : sumJsonNode.asDouble()) 75 | .setSamples(samplesJsonNode == null ? 0 : samplesJsonNode.asInt()) 76 | .setPercentiles(percentiles) 77 | .build(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/NumericBucketPointMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 20 | 21 | @JsonDeserialize(using = NumericBucketPointDeserializer.class) 22 | public abstract class NumericBucketPointMixin { 23 | } 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/TaggedBucketPointDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import java.io.IOException; 20 | import java.util.ArrayList; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import org.hawkular.metrics.model.Percentile; 26 | import org.hawkular.metrics.model.TaggedBucketPoint; 27 | 28 | import com.fasterxml.jackson.core.JsonParser; 29 | import com.fasterxml.jackson.core.ObjectCodec; 30 | import com.fasterxml.jackson.databind.DeserializationContext; 31 | import com.fasterxml.jackson.databind.JsonDeserializer; 32 | import com.fasterxml.jackson.databind.JsonNode; 33 | 34 | public class TaggedBucketPointDeserializer extends JsonDeserializer { 35 | 36 | @SuppressWarnings("unchecked") 37 | @Override 38 | public TaggedBucketPoint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { 39 | ObjectCodec objectCodec = jp.getCodec(); 40 | JsonNode node = objectCodec.readTree(jp); 41 | 42 | JsonNode tagsJsonNode = node.get("tags"); 43 | JsonNode minJsonNode = node.get("min"); 44 | JsonNode avgJsonNode = node.get("avg"); 45 | JsonNode medianJsonNode = node.get("median"); 46 | JsonNode maxJsonNode = node.get("max"); 47 | JsonNode sumJsonNode = node.get("sum"); 48 | JsonNode samplesJsonNode = node.get("samples"); 49 | 50 | JsonNode percentilesJsonNode = node.get("percentiles"); 51 | List percentiles = new ArrayList(); 52 | if (percentilesJsonNode != null) { 53 | percentiles = objectCodec.treeToValue(percentilesJsonNode, List.class); 54 | } 55 | 56 | return new TaggedBucketPoint(tagsJsonNode == null ? new HashMap() : objectCodec.treeToValue(tagsJsonNode, Map.class), 57 | minJsonNode == null ? 0 : minJsonNode.asDouble(), 58 | avgJsonNode == null ? 0 : avgJsonNode.asDouble(), 59 | medianJsonNode == null ? 0 : medianJsonNode.asDouble(), 60 | maxJsonNode == null ? 0 : maxJsonNode.asDouble(), 61 | sumJsonNode == null ? 0 : sumJsonNode.asDouble(), 62 | samplesJsonNode == null ? 0 : samplesJsonNode.asInt(), 63 | percentiles); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/TaggedBucketPointMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 20 | 21 | @JsonDeserialize(using = TaggedBucketPointDeserializer.class) 22 | public abstract class TaggedBucketPointMixin { 23 | } 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/TenantDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import java.io.IOException; 20 | 21 | import org.hawkular.metrics.model.Tenant; 22 | import org.hawkular.metrics.model.TenantDefinition; 23 | 24 | import com.fasterxml.jackson.core.JsonParser; 25 | import com.fasterxml.jackson.databind.DeserializationContext; 26 | import com.fasterxml.jackson.databind.JsonDeserializer; 27 | 28 | public class TenantDeserializer extends JsonDeserializer { 29 | 30 | @Override 31 | public Tenant deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { 32 | TenantDefinition tenantDefinition = jp.getCodec().readValue(jp, TenantDefinition.class); 33 | if (tenantDefinition != null) { 34 | return tenantDefinition.toTenant(); 35 | } 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/TenantMixin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 20 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 21 | 22 | /** 23 | * @author jkandasa@redhat.com (Jeeva Kandasamy) 24 | */ 25 | @JsonSerialize(using = TenantSerializer.class) 26 | @JsonDeserialize(using = TenantDeserializer.class) 27 | public abstract class TenantMixin { 28 | } 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/fasterxml/jackson/TenantSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.fasterxml.jackson; 18 | 19 | import java.io.IOException; 20 | 21 | import org.hawkular.client.core.jaxrs.fasterxml.jackson.ClientObjectMapper; 22 | import org.hawkular.metrics.model.Tenant; 23 | import org.hawkular.metrics.model.TenantDefinition; 24 | 25 | import com.fasterxml.jackson.core.JsonGenerator; 26 | import com.fasterxml.jackson.databind.JsonSerializer; 27 | import com.fasterxml.jackson.databind.ObjectMapper; 28 | import com.fasterxml.jackson.databind.SerializerProvider; 29 | 30 | public class TenantSerializer extends JsonSerializer { 31 | 32 | @Override 33 | public void serialize(Tenant tenant, JsonGenerator jgen, SerializerProvider sp) throws IOException { 34 | if (tenant != null) { 35 | ObjectMapper objectMapper = new ClientObjectMapper(); 36 | objectMapper.writeValue(jgen, new TenantDefinition(tenant)); 37 | } else { 38 | jgen.writeNull(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/jaxrs/handlers/MetricHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.POST; 22 | import javax.ws.rs.Path; 23 | import javax.ws.rs.PathParam; 24 | import javax.ws.rs.Produces; 25 | import javax.ws.rs.QueryParam; 26 | import javax.ws.rs.core.MediaType; 27 | import javax.ws.rs.core.Response; 28 | 29 | import org.hawkular.metrics.model.Metric; 30 | import org.hawkular.metrics.model.MetricType; 31 | import org.hawkular.metrics.model.MixedMetricsRequest; 32 | import org.hawkular.metrics.model.param.Tags; 33 | 34 | /** 35 | * Metrics API 36 | * http://www.hawkular.org/docs/rest/rest-metrics.html#_metric 37 | */ 38 | @Path("/hawkular/metrics/metrics") 39 | @Produces(MediaType.APPLICATION_JSON) 40 | @Consumes(MediaType.APPLICATION_JSON) 41 | public interface MetricHandler { 42 | 43 | @GET 44 | @Path("/") 45 | Response findMetrics( 46 | @QueryParam("type") MetricType metricType, 47 | @QueryParam("tags") Tags tags, 48 | @QueryParam("id") String id); 49 | 50 | @POST 51 | @Path("/") 52 | Response createMetric(@QueryParam("overwrite") Boolean overwrite, Metric metric); 53 | 54 | @POST 55 | @Path("/raw") 56 | Response addMetricsData(MixedMetricsRequest metricsRequest); 57 | 58 | @GET 59 | @Path("/tags/{tags}") 60 | Response findMetricsTags(@PathParam("tags") Tags tags, @QueryParam("type") MetricType metricType); 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/jaxrs/handlers/PingHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.core.MediaType; 24 | import javax.ws.rs.core.Response; 25 | 26 | @Path("/hawkular/metrics/ping") 27 | @Produces(MediaType.APPLICATION_JSON) 28 | @Consumes(MediaType.APPLICATION_JSON) 29 | public interface PingHandler { 30 | 31 | @GET 32 | @Path("/") 33 | Response ping(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/jaxrs/handlers/StatusHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.GET; 21 | import javax.ws.rs.Path; 22 | import javax.ws.rs.Produces; 23 | import javax.ws.rs.core.MediaType; 24 | import javax.ws.rs.core.Response; 25 | 26 | @Path("/hawkular/metrics/status") 27 | @Produces(MediaType.APPLICATION_JSON) 28 | @Consumes(MediaType.APPLICATION_JSON) 29 | public interface StatusHandler { 30 | 31 | @GET 32 | @Path("/") 33 | Response status(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/jaxrs/handlers/StringHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.jaxrs.handlers; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.ws.rs.Consumes; 23 | import javax.ws.rs.DELETE; 24 | import javax.ws.rs.GET; 25 | import javax.ws.rs.POST; 26 | import javax.ws.rs.PUT; 27 | import javax.ws.rs.Path; 28 | import javax.ws.rs.PathParam; 29 | import javax.ws.rs.Produces; 30 | import javax.ws.rs.QueryParam; 31 | import javax.ws.rs.core.MediaType; 32 | import javax.ws.rs.core.Response; 33 | 34 | import org.hawkular.client.metrics.model.Order; 35 | import org.hawkular.metrics.model.DataPoint; 36 | import org.hawkular.metrics.model.Metric; 37 | import org.hawkular.metrics.model.param.Tags; 38 | 39 | /** 40 | * String API 41 | * http://www.hawkular.org/docs/rest/rest-metrics.html#_string 42 | */ 43 | @Path("/hawkular/metrics/strings") 44 | @Produces(MediaType.APPLICATION_JSON) 45 | @Consumes(MediaType.APPLICATION_JSON) 46 | public interface StringHandler { 47 | 48 | @GET 49 | @Path("/") 50 | Response findMetricsDefinitions(@QueryParam("tags") Tags tags); 51 | 52 | @POST 53 | @Path("/") 54 | Response createStringMetric(@QueryParam("overwrite") Boolean overwrite, Metric metric); 55 | 56 | @POST 57 | @Path("/raw") 58 | Response createStringMetric(List> metrics); 59 | 60 | @GET 61 | @Path("/tags/{tags}") 62 | Response findMetricTags(@PathParam("tags") Tags tags); 63 | 64 | @GET 65 | @Path("/{id}") 66 | Response getMetricDefinitions(@PathParam("id") String id); 67 | 68 | @GET 69 | @Path("/{id}/raw") 70 | Response getMetricDefinitionsData( 71 | @PathParam("id") String id, 72 | @QueryParam("start") String start, 73 | @QueryParam("end") String end, 74 | @QueryParam("distinct") Boolean distinct, 75 | @QueryParam("limit") Integer limit, 76 | @QueryParam("order") Order order); 77 | 78 | @POST 79 | @Path("/{id}/raw") 80 | Response createMetricDefinitionsData(@PathParam("id") String id, List> dataPoints); 81 | 82 | @GET 83 | @Path("/{id}/tags") 84 | Response findMetricDefinitionsTags(@PathParam("id") String id); 85 | 86 | @PUT 87 | @Path("/{id}/tags") 88 | Response updateMetricDefinitionsTags(@PathParam("id") String id, Map tags); 89 | 90 | @DELETE 91 | @Path("/{id}/tags/{tags}") 92 | Response deleteMetricDefinitionsTags(@PathParam("id") String id, @PathParam("tags") Tags tags); 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/jaxrs/handlers/TenantHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.jaxrs.handlers; 18 | 19 | import javax.ws.rs.Consumes; 20 | import javax.ws.rs.DELETE; 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.POST; 23 | import javax.ws.rs.Path; 24 | import javax.ws.rs.PathParam; 25 | import javax.ws.rs.Produces; 26 | import javax.ws.rs.QueryParam; 27 | import javax.ws.rs.core.MediaType; 28 | import javax.ws.rs.core.Response; 29 | 30 | import org.hawkular.metrics.model.Tenant; 31 | 32 | /** 33 | * Tenants API 34 | * http://www.hawkular.org/docs/rest/rest-metrics.html#_tenant 35 | */ 36 | @Path("/hawkular/metrics/tenants") 37 | @Produces(MediaType.APPLICATION_JSON) 38 | @Consumes(MediaType.APPLICATION_JSON) 39 | public interface TenantHandler { 40 | 41 | @GET 42 | @Path("/") 43 | Response getTenants(); 44 | 45 | @POST 46 | @Path("/") 47 | Response createTenant(@QueryParam("overwrite") Boolean overwrite, Tenant tenant); 48 | 49 | @DELETE 50 | @Path("/{id}") 51 | Response deleteTenant(@PathParam("id") String id); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/hawkular/client/metrics/model/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.metrics.model; 18 | 19 | /* 20 | * Copyright 2014-2016 Red Hat, Inc. and/or its affiliates 21 | * and other contributors as indicated by the @author tags. 22 | * 23 | * Licensed under the Apache License, Version 2.0 (the "License"); 24 | * you may not use this file except in compliance with the License. 25 | * You may obtain a copy of the License at 26 | * 27 | * http://www.apache.org/licenses/LICENSE-2.0 28 | * 29 | * Unless required by applicable law or agreed to in writing, software 30 | * distributed under the License is distributed on an "AS IS" BASIS, 31 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 32 | * See the License for the specific language governing permissions and 33 | * limitations under the License. 34 | */ 35 | import static com.google.common.base.Preconditions.checkArgument; 36 | 37 | import java.util.Map; 38 | 39 | import com.google.common.collect.ImmutableSortedMap; 40 | import com.google.common.collect.ImmutableSortedMap.Builder; 41 | 42 | /** 43 | * https://github.com/hawkular/hawkular-metrics/blob/master/core/metrics-core-service/src/main/java/org/hawkular/metrics/core/service/Order.java 44 | * 45 | * @author John Sanda 46 | */ 47 | public enum Order { 48 | ASC("asc"), 49 | DESC("desc"); 50 | 51 | private static final Map texts; 52 | 53 | static { 54 | Builder builder = ImmutableSortedMap.orderedBy(String.CASE_INSENSITIVE_ORDER); 55 | for (Order order : values()) { 56 | builder.put(order.text, order); 57 | } 58 | texts = builder.build(); 59 | } 60 | 61 | private String text; 62 | 63 | Order(String text) { 64 | this.text = text; 65 | } 66 | 67 | public static Order fromText(String text) { 68 | checkArgument(text != null, "text is null"); 69 | Order order = texts.get(text); 70 | if (order == null) { 71 | throw new IllegalArgumentException(text + " is not a recognized order"); 72 | } 73 | return order; 74 | } 75 | 76 | /** 77 | * Determines a default value based on API parameters. 78 | * 79 | * @param limit maximum of rows returned 80 | * @param start time range start 81 | * @param end time range end 82 | * @return {@link #ASC} if limit is positive, start is not null and end is null; {@link #DESC} otherwise 83 | */ 84 | public static Order defaultValue(int limit, Object start, Object end) { 85 | return limit > 0 && start != null && end == null ? ASC : DESC; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return text; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/BTG.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test; 18 | 19 | import java.time.Duration; 20 | import java.time.Instant; 21 | 22 | import org.apache.http.annotation.NotThreadSafe; 23 | 24 | /** 25 | * A Better-Timestamp-Generator helper class generates new timestamp value starting 26 | * from (current time - window) in 30 seconds increment to avoid getting almost 27 | * identical values when calling System.currentTimeMillis() in 28 | * rapid succession 29 | * 30 | * @author vnguyen 31 | */ 32 | @NotThreadSafe 33 | public class BTG { 34 | private Instant nextVal; 35 | private Duration window; 36 | private Duration increment = Duration.ofSeconds(30); 37 | 38 | public BTG() { 39 | this(Instant.now()); 40 | } 41 | 42 | public BTG(Instant current) { 43 | window = Duration.ofHours(4); 44 | nextVal = current.minus(window); 45 | } 46 | 47 | public BTG withIncrement(Duration inc) { 48 | increment = inc; 49 | return this; 50 | } 51 | 52 | public long nextMilli() { 53 | return this.next().toEpochMilli(); 54 | } 55 | 56 | public Instant next() { 57 | Instant ret = nextVal; 58 | nextVal = nextVal.plus(increment); 59 | //TODO: test when we use up all values within window 60 | return ret; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/BTGTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test; 18 | 19 | import java.time.Duration; 20 | import java.time.Instant; 21 | 22 | import org.testng.Assert; 23 | import org.testng.Reporter; 24 | import org.testng.annotations.Test; 25 | 26 | public class BTGTest { 27 | 28 | @Test 29 | public void simple() { 30 | Instant now = Instant.now(); 31 | Duration window = Duration.ofHours(4); 32 | Duration defaultInc = Duration.ofSeconds(30); 33 | Reporter.log("Current: " + now.toString()); 34 | 35 | BTG ts = new BTG(now); 36 | for (int i = 0; i < 4; i++) { 37 | Instant next = ts.next(); 38 | Reporter.log(next.toString()); 39 | Assert.assertEquals(next, now.minus(window).plus(defaultInc.multipliedBy(i))); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/BaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test; 18 | 19 | import java.net.URI; 20 | import java.net.URISyntaxException; 21 | 22 | import org.apache.commons.lang3.StringUtils; 23 | import org.hawkular.client.core.HawkularClient; 24 | import org.testng.Reporter; 25 | import org.testng.annotations.BeforeClass; 26 | 27 | public class BaseTest { 28 | 29 | protected static final long MINUTE = 1000 * 60; 30 | public static final String HEADER_TENANT = "unit-testing"; 31 | 32 | static final String HEADER_ADMIN_TOKEN = "awesome_secret_sauce"; 33 | 34 | private HawkularClient client; 35 | 36 | @BeforeClass 37 | public void init() throws Exception { 38 | URI endpoint = getEndpointFromEnv(); 39 | Reporter.log(endpoint.toString()); 40 | 41 | client = HawkularClient.builder(HEADER_TENANT) 42 | .uri(endpoint) 43 | .basicAuthentication(getUsername(), getPassword()) 44 | .adminTokenAuthentication(HEADER_ADMIN_TOKEN) 45 | .build(); 46 | } 47 | 48 | private URI getEndpointFromEnv() throws URISyntaxException { 49 | String endpoint = System.getenv("HAWKULAR_ENDPOINT"); 50 | if (StringUtils.trimToNull(endpoint) == null) { 51 | Reporter.log("HAWKULAR_ENDPOINT env not defined. Defaulting to 'localhost'"); 52 | endpoint = "http://localhost:8080"; 53 | } 54 | 55 | return new URI(endpoint); 56 | } 57 | 58 | private String getUsername() { 59 | String username = System.getenv("HAWKULAR_USER"); 60 | if (StringUtils.trimToNull(username) == null) { 61 | Reporter.log("HAWKULAR_USER env not defined. Defaulting to 'jdoe'"); 62 | username = "jdoe"; 63 | } 64 | 65 | return username; 66 | } 67 | 68 | private String getPassword() { 69 | String password = System.getenv("HAWKULAR_PASSWORD"); 70 | if (StringUtils.trimToNull(password) == null) { 71 | Reporter.log("HAWKULAR_PASSWORD env not defined. Defaulting to 'password'"); 72 | password = "password"; 73 | } 74 | 75 | return password; 76 | } 77 | 78 | /** 79 | * Return the main Hawkular client 80 | * 81 | * @return HawkularClient 82 | */ 83 | public HawkularClient client() { 84 | return client; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/NoopTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test; 18 | 19 | import org.testng.Reporter; 20 | import org.testng.annotations.Test; 21 | 22 | @Test 23 | public class NoopTest { 24 | 25 | @Test 26 | public void noop() { 27 | Reporter.log("Hello world"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/alerts/AlertsStatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.alerts; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | import org.hawkular.client.test.BaseTest; 23 | import org.testng.Assert; 24 | import org.testng.annotations.Test; 25 | 26 | @Test(groups = { "alerts" }) 27 | public class AlertsStatusTest extends BaseTest { 28 | 29 | @Test 30 | public void status() { 31 | ClientResponse> response = client() 32 | .alerts() 33 | .status() 34 | .status(); 35 | 36 | Assert.assertTrue(response.isSuccess()); 37 | Assert.assertNotNull(response.getEntity()); 38 | Assert.assertTrue(response.getEntity().size() > 0); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/alerts/ExportTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.alerts; 18 | 19 | import org.hawkular.alerts.api.model.export.Definitions; 20 | import org.hawkular.client.core.ClientResponse; 21 | import org.hawkular.client.test.BaseTest; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.testng.Assert; 25 | import org.testng.annotations.Test; 26 | 27 | @Test(groups = { "alerts" }) 28 | public class ExportTest extends BaseTest { 29 | 30 | private static final Logger LOG = LoggerFactory.getLogger(ExportTest.class); 31 | 32 | @Test(dependsOnGroups = "alerts-import") 33 | public void export() { 34 | LOG.info("Exporting"); 35 | 36 | ClientResponse response = client() 37 | .alerts() 38 | .export() 39 | .export(); 40 | 41 | Assert.assertTrue(response.isSuccess()); 42 | Assert.assertNotNull(response.getEntity()); 43 | Assert.assertNotNull(response.getEntity().getActions()); 44 | Assert.assertNotNull(response.getEntity().getTriggers()); 45 | Assert.assertTrue(response.getEntity().getActions().size() > 0); 46 | Assert.assertTrue(response.getEntity().getTriggers().size() > 0); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/alerts/PluginsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.alerts; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import org.hawkular.client.core.ClientResponse; 23 | import org.hawkular.client.test.BaseTest; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | import org.testng.Assert; 27 | import org.testng.annotations.Test; 28 | 29 | @Test(groups = {"alerts", "alerts-plugins"}) 30 | public class PluginsTest extends BaseTest { 31 | 32 | private static final Logger LOG = LoggerFactory.getLogger(PluginsTest.class); 33 | 34 | public static final String EMAIL_PLUGIN_NAME = "email"; 35 | public static final String EMAIL_PLUGIN_PROPERTY_TO = "to"; 36 | public static final String EMAIL_PLUGIN_PROPERTY_FROM = "from"; 37 | private static final List emailProperties = 38 | Arrays.asList("cc", "from", "from-name", "template.hawkular.url", "template.html", "template.plain", "to"); 39 | 40 | @Test 41 | public void findActionPlugins() { 42 | LOG.info("Testing with Plugin == {}", EMAIL_PLUGIN_NAME); 43 | 44 | ClientResponse> response = client() 45 | .alerts() 46 | .plugins() 47 | .findActionPlugins(); 48 | 49 | Assert.assertTrue(response.isSuccess()); 50 | Assert.assertTrue(response.getEntity().size() > 0); 51 | Assert.assertTrue(response.getEntity().contains(EMAIL_PLUGIN_NAME)); 52 | } 53 | 54 | @Test(dependsOnMethods = "findActionPlugins") 55 | public void getActionPlugin() { 56 | ClientResponse> response = client() 57 | .alerts() 58 | .plugins() 59 | .getActionPlugin(EMAIL_PLUGIN_NAME); 60 | 61 | Assert.assertTrue(response.isSuccess()); 62 | Assert.assertTrue(response.getEntity().size() > 0); 63 | Assert.assertEquals(response.getEntity(), emailProperties); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/alerts/StatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.alerts; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | import org.hawkular.client.test.BaseTest; 23 | import org.testng.Assert; 24 | import org.testng.annotations.Test; 25 | 26 | @Test(groups = { "alerts" }) 27 | public class StatusTest extends BaseTest { 28 | 29 | @Test 30 | public void status() { 31 | ClientResponse> response = client() 32 | .alerts() 33 | .status() 34 | .status(); 35 | 36 | Assert.assertTrue(response.isSuccess()); 37 | Assert.assertNotNull(response.getEntity()); 38 | Assert.assertTrue(response.getEntity().size() > 0); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/alerts/trigger/utils/SetConitionMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.alerts.trigger.utils; 18 | 19 | import java.util.List; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | 23 | public interface SetConitionMethod { 24 | 25 | ClientResponse> setConditions(String triggerId, String triggerMode, List conditions); 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/inventory/APIInfoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.inventory; 18 | 19 | import org.hawkular.client.core.ClientResponse; 20 | import org.hawkular.client.inventory.model.InventoryJaxRsInfo; 21 | import org.hawkular.client.test.BaseTest; 22 | import org.testng.Assert; 23 | import org.testng.annotations.Test; 24 | 25 | @Test(groups = {"inventory"}) 26 | public class APIInfoTest extends BaseTest { 27 | 28 | @Test 29 | public void getEndpoints() { 30 | ClientResponse response = client() 31 | .inventory() 32 | .apiInfo() 33 | .getEndpoints(); 34 | 35 | Assert.assertTrue(response.isSuccess()); 36 | Assert.assertNotNull(response.getEntity()); 37 | Assert.assertNotNull(response.getEntity().getDocumentation()); 38 | Assert.assertNotNull(response.getEntity().getEndpoints()); 39 | Assert.assertTrue(response.getEntity().getEndpoints().size() > 0); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/inventory/BulkCreateBaseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.inventory; 18 | 19 | import org.hawkular.client.test.BaseTest; 20 | import org.hawkular.client.test.utils.RandomStringGenerator; 21 | 22 | public abstract class BulkCreateBaseTest extends BaseTest { 23 | 24 | protected static String environmentId = "environment-id-" + RandomStringGenerator.getRandomId(); 25 | protected static String feedId = "feed-id-" + RandomStringGenerator.getRandomId(); 26 | protected static String resourceTypeId = "resource-type-id-" + RandomStringGenerator.getRandomId(); 27 | protected static String resourceId = "resource-id-" + RandomStringGenerator.getRandomId(); 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/inventory/GraphTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.inventory; 18 | 19 | import org.hawkular.client.core.ClientResponse; 20 | import org.hawkular.client.test.BaseTest; 21 | import org.testng.Assert; 22 | import org.testng.annotations.Test; 23 | 24 | @Test(groups = {"inventory"}, dependsOnGroups = "inventory-bulkcreate", enabled = false) 25 | public class GraphTest extends BaseTest { 26 | 27 | @Test(enabled = false) 28 | public void getGraph() { 29 | //TODO: https://gist.github.com/garethahealy/0a7d7403f329d8768ab4cab4dcf2c409 30 | 31 | ClientResponse response = client() 32 | .inventory() 33 | .graph() 34 | .getGraph(); 35 | 36 | Assert.assertTrue(response.isSuccess(), response.getErrorMsg()); 37 | Assert.assertNotNull(response.getEntity()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/inventory/SyncTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.inventory; 18 | 19 | import java.util.EnumSet; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | import org.hawkular.client.core.jaxrs.Empty; 23 | import org.hawkular.client.test.BaseTest; 24 | import org.hawkular.client.test.utils.RandomStringGenerator; 25 | import org.hawkular.inventory.api.model.Feed; 26 | import org.hawkular.inventory.api.model.InventoryStructure; 27 | import org.hawkular.inventory.api.model.Resource; 28 | import org.hawkular.inventory.api.model.ResourceType; 29 | import org.hawkular.inventory.api.model.SyncConfiguration; 30 | import org.hawkular.inventory.api.model.SyncRequest; 31 | import org.hawkular.inventory.paths.CanonicalPath; 32 | import org.hawkular.inventory.paths.SegmentType; 33 | import org.testng.Assert; 34 | import org.testng.annotations.Test; 35 | 36 | @Test(groups = {"inventory"}, dependsOnGroups = "inventory-bulkcreate") 37 | public class SyncTest extends BulkCreateBaseTest { 38 | 39 | @Test 40 | public void synchronize() { 41 | CanonicalPath path = CanonicalPath.of() 42 | .tenant(BaseTest.HEADER_TENANT) 43 | .feed(feedId) 44 | .get(); 45 | 46 | Feed.Blueprint feed = Feed.Blueprint.builder() 47 | .withId(feedId) 48 | .withName("feed-test-synced") 49 | .withProperty("rand", RandomStringGenerator.getRandomId()) 50 | .build(); 51 | 52 | ResourceType.Blueprint resourceType = ResourceType.Blueprint 53 | .builder() 54 | .withId(resourceTypeId) 55 | .withName("resource-type-synced") 56 | .withProperty("rand", RandomStringGenerator.getRandomId()) 57 | .build(); 58 | 59 | Resource.Blueprint resource = Resource.Blueprint 60 | .builder() 61 | .withId(resourceId) 62 | .withName("resource-synced") 63 | .withResourceTypePath(resourceTypeId) 64 | .withProperty("rand", RandomStringGenerator.getRandomId()) 65 | .build(); 66 | 67 | EnumSet enumSet = EnumSet.of(SegmentType.f, SegmentType.r, SegmentType.rt); 68 | SyncConfiguration config = new SyncConfiguration(enumSet, true); 69 | InventoryStructure structure = InventoryStructure.Offline 70 | .of(feed) 71 | .addChild(resourceType) 72 | .addChild(resource) 73 | .build(); 74 | 75 | SyncRequest request = new SyncRequest(config, structure); 76 | 77 | ClientResponse response = client() 78 | .inventory() 79 | .sync() 80 | .synchronize(path, null, request); 81 | 82 | Assert.assertTrue(response.isSuccess()); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/metrics/MetricsStatusTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.metrics; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | import org.hawkular.client.test.BaseTest; 23 | import org.testng.Assert; 24 | import org.testng.annotations.Test; 25 | 26 | @Test(groups = {"metrics"}) 27 | public class MetricsStatusTest extends BaseTest { 28 | 29 | @Test 30 | public void status() { 31 | ClientResponse> response = client() 32 | .metrics() 33 | .status() 34 | .status(); 35 | 36 | Assert.assertTrue(response.isSuccess()); 37 | Assert.assertNotNull(response.getEntity()); 38 | Assert.assertTrue(response.getEntity().size() > 0); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/metrics/PingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2017 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.metrics; 18 | 19 | import java.util.Map; 20 | 21 | import org.hawkular.client.core.ClientResponse; 22 | import org.hawkular.client.test.BaseTest; 23 | import org.testng.Assert; 24 | import org.testng.annotations.Test; 25 | 26 | @Test(groups = {"metrics"}) 27 | public class PingTest extends BaseTest { 28 | 29 | @Test 30 | public void ping() { 31 | ClientResponse> response = client() 32 | .metrics() 33 | .ping() 34 | .ping(); 35 | 36 | Assert.assertTrue(response.isSuccess()); 37 | Assert.assertNotNull(response.getEntity()); 38 | Assert.assertTrue(response.getEntity().size() > 0); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/utils/DataPointGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.utils; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Random; 22 | 23 | import org.hawkular.client.test.BTG; 24 | import org.hawkular.metrics.model.DataPoint; 25 | 26 | import com.google.common.collect.ImmutableList.Builder; 27 | 28 | public class DataPointGenerator { 29 | 30 | public List> generator(int size, Map tags) { 31 | return build(size, tags); 32 | } 33 | 34 | private List> build(int size, Map tags) { 35 | BTG ts = new BTG(); 36 | Random random = new Random(1000); 37 | 38 | Builder> builder = new Builder<>(); 39 | for (int i = 0; i < size; i++) { 40 | DataPoint point = new DataPoint(ts.nextMilli(), getValue(random), tags); 41 | builder.add(point); 42 | } 43 | return builder.build(); 44 | } 45 | 46 | protected T getValue(Random random) { 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/utils/MetricGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.utils; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.hawkular.client.test.BaseTest; 23 | import org.hawkular.metrics.model.DataPoint; 24 | import org.hawkular.metrics.model.Metric; 25 | import org.hawkular.metrics.model.MetricId; 26 | import org.hawkular.metrics.model.MetricType; 27 | 28 | public class MetricGenerator { 29 | 30 | private static final int DATA_RETENTION = 21; 31 | 32 | public static Metric generate(MetricType metricType, Map tags, String name, List> dataPoints) { 33 | MetricId id = new MetricId(BaseTest.HEADER_TENANT, metricType, name); 34 | return new Metric(id, tags, DATA_RETENTION, dataPoints); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/utils/RandomStringGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.utils; 18 | 19 | import org.apache.commons.lang3.RandomStringUtils; 20 | 21 | public class RandomStringGenerator { 22 | 23 | public static String getRandomId() { 24 | return getRandomId(8); 25 | } 26 | 27 | public static String getRandomId(int count) { 28 | return RandomStringUtils.randomAlphanumeric(count).toLowerCase(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/hawkular/client/test/utils/TagGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Red Hat, Inc. and/or its affiliates 3 | * and other contributors as indicated by the @author tags. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.hawkular.client.test.utils; 18 | 19 | import java.util.Arrays; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import org.hawkular.metrics.model.param.Tags; 25 | 26 | public class TagGenerator { 27 | 28 | public static final String POD_NAMESPACE = "pod_namespace"; 29 | public static final String POD_NAME = "container_name"; 30 | 31 | public static Tags generate(String namespace, String podName) { 32 | return new Tags(generateMap(namespace, podName)); 33 | } 34 | 35 | public static Map generateMap(String namespace, String podName) { 36 | Map tagsMap = new HashMap(); 37 | tagsMap.put(POD_NAMESPACE, namespace); 38 | tagsMap.put(POD_NAME, podName); 39 | 40 | return tagsMap; 41 | } 42 | 43 | public static Map> convert(Map tags) { 44 | Map> answer = new HashMap>(); 45 | for (Map.Entry current : tags.entrySet()) { 46 | answer.put(current.getKey(), Arrays.asList(current.getValue())); 47 | } 48 | 49 | return answer; 50 | } 51 | } 52 | --------------------------------------------------------------------------------