hawkular-client 2.2.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.rdoc +12 -0
- data/README.rdoc +5 -3
- data/Rakefile +8 -0
- data/hawkularclient.gemspec +1 -1
- data/lib/hawkular/base_client.rb +19 -1
- data/lib/hawkular/hawkular_client.rb +1 -1
- data/lib/hawkular/hawkular_client_utils.rb +1 -0
- data/lib/hawkular/inventory/entities.rb +234 -0
- data/lib/hawkular/inventory/inventory_api.rb +92 -311
- data/lib/hawkular/metrics/metric_api.rb +23 -10
- data/lib/hawkular/metrics/metrics_client.rb +14 -0
- data/lib/hawkular/operations/operations_api.rb +8 -2
- data/lib/hawkular/version.rb +1 -1
- data/spec/README.rdoc +62 -0
- data/spec/integration/alerts_spec.rb +18 -14
- data/spec/integration/hawkular_client_spec.rb +53 -14
- data/spec/integration/inventory_spec.rb +91 -44
- data/spec/integration/metric_spec.rb +574 -420
- data/spec/integration/operations_spec.rb +78 -5
- data/spec/integration/tokens_spec.rb +8 -4
- data/spec/spec_helper.rb +73 -13
- data/spec/unit/base_spec.rb +30 -1
- data/spec/unit/client_spec.rb +21 -9
- data/spec/vcr_cassettes/HawkularClient/Should_err_on_bad_credentials.yml +42 -0
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_both_create_and_delete_feed.yml +64 -34
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_both_list_WildFlys.yml +27 -43
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_both_list_types_with_bad_feed.yml +12 -8
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_same_types_when_param_is_given.yml +144 -64
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_the_same_feeds.yml +26 -14
- data/spec/vcr_cassettes/HawkularClient/and_Inventory_client/Should_list_the_same_resource_types.yml +20 -158
- data/spec/vcr_cassettes/HawkularClient/and_Operations_client/Should_both_work_the_same_way.yml +40 -30
- data/spec/vcr_cassettes/{Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml → HawkularClient/and_Operations_client/Should_work_initializing_with_URI.yml} +18 -20
- data/spec/vcr_cassettes/HawkularClient/and_Operations_client_Should_both_work_the_same_way.json +8 -8
- data/spec/vcr_cassettes/HawkularClient/and_Operations_client_Should_work_initializing_with_URI.json +9 -0
- data/spec/vcr_cassettes/HawkularClient/and_URIs_as_input/Should_work_with_URI.yml +77 -20
- data/spec/vcr_cassettes/HawkularClient/and_URIs_as_input/Should_work_with_URI_on_metrics_client.yml +3 -3
- data/spec/vcr_cassettes/Inventory/Connection/Should_err_on_bad_credentials.yml +42 -0
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Explicit_Credentials.yml +59 -12
- data/spec/vcr_cassettes/Inventory/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml +59 -12
- data/spec/vcr_cassettes/Inventory/{Helpers → inventory_0_17/Helpers}/create_url.yml +9 -7
- data/spec/vcr_cassettes/Inventory/{Templates/Should_list_feeds_when_using_SSL_without_certificate.yml → inventory_0_17/Helpers/get_feeds.yml} +23 -21
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Client_should_listen_on_various_inventory_events.json +47 -0
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Client_should_listen_on_various_inventory_events.yml +48 -40
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Helpers/generate_some_events_for_websocket.yml +397 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_List_datasources_with_no_props.yml +129 -0
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_create_a_feed.yml +13 -10
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_create_a_feed_again.yml +40 -29
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_create_a_nested_resource_and_metric_on_it.yml +193 -237
- data/spec/vcr_cassettes/Inventory/{Templates/Should_create_and_get_a_resource.yml → inventory_0_17/Templates/Should_create_a_resource.yml} +86 -172
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_create_a_resource_with_metric.yml +296 -158
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_create_a_resourcetype.yml +38 -29
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_create_and_delete_feed.yml +42 -27
- data/spec/vcr_cassettes/Inventory/{Templates/Should_create_a_resource.yml → inventory_0_17/Templates/Should_create_and_get_a_resource.yml} +109 -89
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_list_URLs.yml +20 -17
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_list_WildFlys.yml +19 -12
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_WildFlys_with_props.yml +131 -0
- data/spec/vcr_cassettes/Inventory/{Helpers/get_feeds.yml → inventory_0_17/Templates/Should_list_all_the_resource_types.yml} +14 -11
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_children_of_WildFly.yml +315 -0
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_list_children_of_nested_resource.yml +45 -30
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_list_feeds.yml +16 -10
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_feeds_when_using_SSL_without_certificate.yml +60 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_heap_metrics_for_WildFlys.yml +935 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_metrics_for_WildFlys.yml +357 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_metrics_of_given_metric_type.yml +122 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_metrics_of_given_resource_type.yml +292 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_operation_definitions_of_given_resource.yml +235 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_operation_definitions_of_given_resource_type.yml +121 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_recursive_children_of_WildFly.yml +1099 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_relationships_of_WildFly.yml +377 -0
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_list_resources_for_feed.yml +19 -9
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_list_types_with_bad_feed.yml +10 -8
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_list_types_with_feed.yml +164 -0
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_not_find_an_unknown_resource.yml +12 -10
- data/spec/vcr_cassettes/Inventory/{Templates → inventory_0_17/Templates}/Should_return_config_data_of_given_nested_resource.yml +17 -11
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_return_config_data_of_given_resource.yml +66 -0
- data/spec/vcr_cassettes/Inventory/inventory_0_17/Templates/Should_return_the_version.yml +48 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Get_metric_definition_by_id.yml +49 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Retrieve_metric_rate_points.yml +88 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Should_create_Availability_definition.yml +97 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Should_create_Counter_definition.yml +97 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Should_create_gauge_definition.yml +97 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Should_push_metric_data_to_existing_gauge.yml +48 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Should_update_tags_for_Availability_definition.yml +140 -0
- data/spec/vcr_cassettes/Metric_ID_with_special_characters/Should_update_tags_for_gauge_definition.yml +140 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Availability_metrics/Should_create_Availability_definition_using_MetricDefinition_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Availability_metrics/Should_create_and_return_Availability_using_Hash_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Availability_metrics/Should_group_contiguous_values.yml +93 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Availability_metrics/Should_push_metric_data_to_non-existing_Availability.yml +138 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Availability_metrics/Should_update_tags_for_Availability_definition.yml +230 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Counter_metrics/Should_create_and_return_counter_using_Hash_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Counter_metrics/Should_create_counter_definition_using_MetricDefinition_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Counter_metrics/Should_get_metrics_as_bucketed_results.yml +230 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Counter_metrics/Should_get_metrics_with_limit_and_order.yml +314 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Counter_metrics/Should_push_metric_data_to_existing_counter.yml +269 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Counter_metrics/Should_push_metric_data_to_non-existing_counter.yml +138 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Gauge_metrics/Should_create_gauge_definition_using_Hash.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Gauge_metrics/Should_create_gauge_definition_using_MetricDefinition.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Gauge_metrics/Should_push_metric_data_to_existing_gauge.yml +269 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Gauge_metrics/Should_push_metric_data_to_non-existing_gauge.yml +138 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Gauge_metrics/Should_return_periods.yml +93 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Gauge_metrics/Should_update_tags_for_gauge_definition.yml +230 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Mixed_metrics/Should_requests_raw_data_for_multiple_metrics.yml +330 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Mixed_metrics/Should_send_mixed_metric_request.yml +300 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Mixed_metrics/Should_send_mixed_metric_request_of_a_single_type.yml +273 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/No_Tenant/Should_fail.yml +48 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Simple/Should_be_Cool.yml +48 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Status/Should_return_the_version.yml +42 -0
- data/spec/vcr_cassettes/Metrics/metrics_0_16_0/Templates/Tenants/Should_create_and_return_tenant.yml +95 -0
- data/spec/vcr_cassettes/{Availability_metrics → Metrics/metrics_0_8_0/Templates/Availability_metrics}/Should_create_Availability_definition_using_MetricDefinition_parameter.yml +5 -9
- data/spec/vcr_cassettes/{Availability_metrics → Metrics/metrics_0_8_0/Templates/Availability_metrics}/Should_create_and_return_Availability_using_Hash_parameter.yml +5 -9
- data/spec/vcr_cassettes/{Availability_metrics → Metrics/metrics_0_8_0/Templates/Availability_metrics}/Should_push_metric_data_to_non-existing_Availability.yml +9 -15
- data/spec/vcr_cassettes/{Availability_metrics → Metrics/metrics_0_8_0/Templates/Availability_metrics}/Should_update_tags_for_Availability_definition.yml +11 -21
- data/spec/vcr_cassettes/{Counter_metrics → Metrics/metrics_0_8_0/Templates/Counter_metrics}/Should_create_and_return_counter_using_Hash_parameter.yml +5 -9
- data/spec/vcr_cassettes/{Counter_metrics → Metrics/metrics_0_8_0/Templates/Counter_metrics}/Should_create_counter_definition_using_MetricDefinition_parameter.yml +5 -9
- data/spec/vcr_cassettes/Metrics/metrics_0_8_0/Templates/Counter_metrics/Should_get_metrics_as_bucketed_results.yml +200 -0
- data/spec/vcr_cassettes/{Counter_metrics → Metrics/metrics_0_8_0/Templates/Counter_metrics}/Should_push_metric_data_to_existing_counter.yml +16 -28
- data/spec/vcr_cassettes/{Counter_metrics → Metrics/metrics_0_8_0/Templates/Counter_metrics}/Should_push_metric_data_to_non-existing_counter.yml +9 -15
- data/spec/vcr_cassettes/{Gauge_metrics → Metrics/metrics_0_8_0/Templates/Gauge_metrics}/Should_create_gauge_definition_using_Hash.yml +5 -9
- data/spec/vcr_cassettes/{Gauge_metrics → Metrics/metrics_0_8_0/Templates/Gauge_metrics}/Should_create_gauge_definition_using_MetricDefinition.yml +6 -10
- data/spec/vcr_cassettes/{Gauge_metrics → Metrics/metrics_0_8_0/Templates/Gauge_metrics}/Should_push_metric_data_to_existing_gauge.yml +18 -30
- data/spec/vcr_cassettes/{Gauge_metrics → Metrics/metrics_0_8_0/Templates/Gauge_metrics}/Should_push_metric_data_to_non-existing_gauge.yml +9 -15
- data/spec/vcr_cassettes/{Gauge_metrics → Metrics/metrics_0_8_0/Templates/Gauge_metrics}/Should_return_periods.yml +6 -10
- data/spec/vcr_cassettes/{Gauge_metrics → Metrics/metrics_0_8_0/Templates/Gauge_metrics}/Should_update_tags_for_gauge_definition.yml +11 -21
- data/spec/vcr_cassettes/{Mixed_metrics → Metrics/metrics_0_8_0/Templates/Mixed_metrics}/Should_send_mixed_metric_request.yml +19 -33
- data/spec/vcr_cassettes/{Mixed_metrics → Metrics/metrics_0_8_0/Templates/Mixed_metrics}/Should_send_mixed_metric_request_of_a_single_type.yml +19 -31
- data/spec/vcr_cassettes/Metrics/metrics_0_8_0/Templates/Simple/Should_be_Cool.yml +82 -0
- data/spec/vcr_cassettes/Metrics/{Status.yml → metrics_0_8_0/Templates/Status/Should_return_the_version.yml} +6 -8
- data/spec/vcr_cassettes/{Tenants → Metrics/metrics_0_8_0/Templates/Tenants}/Should_create_and_return_tenant.yml +12 -8
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Availability_metrics/Should_create_Availability_definition_using_MetricDefinition_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Availability_metrics/Should_create_and_return_Availability_using_Hash_parameter.yml +95 -0
- data/spec/vcr_cassettes/{Availability_metrics → Metrics/metrics_services/Templates/Availability_metrics}/Should_group_contiguous_values.yml +7 -7
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Availability_metrics/Should_push_metric_data_to_non-existing_Availability.yml +138 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Availability_metrics/Should_update_tags_for_Availability_definition.yml +230 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Counter_metrics/Should_create_and_return_counter_using_Hash_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Counter_metrics/Should_create_counter_definition_using_MetricDefinition_parameter.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Counter_metrics/Should_get_metrics_as_bucketed_results.yml +230 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Counter_metrics/Should_get_metrics_with_limit_and_order.yml +314 -0
- data/spec/vcr_cassettes/{Counter_metrics/Should_get_metrics_with_limit_and_order.yml → Metrics/metrics_services/Templates/Counter_metrics/Should_push_metric_data_to_existing_counter.yml} +72 -61
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Counter_metrics/Should_push_metric_data_to_non-existing_counter.yml +138 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_create_gauge_definition_using_Hash.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_create_gauge_definition_using_MetricDefinition.yml +95 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_push_metric_data_to_existing_gauge.yml +269 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_push_metric_data_to_non-existing_gauge.yml +138 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_return_periods.yml +93 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_return_platform_memory.yml +48 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_return_platform_memory_def.yml +49 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Gauge_metrics/Should_update_tags_for_gauge_definition.yml +230 -0
- data/spec/vcr_cassettes/{Mixed_metrics → Metrics/metrics_services/Templates/Mixed_metrics}/Should_requests_raw_data_for_multiple_metrics.yml +25 -25
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Mixed_metrics/Should_send_mixed_metric_request.yml +300 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Mixed_metrics/Should_send_mixed_metric_request_of_a_single_type.yml +273 -0
- data/spec/vcr_cassettes/{No_Tenant → Metrics/metrics_services/Templates/No_Tenant}/Should_fail.yml +16 -10
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Simple/Should_be_Cool.yml +48 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Status/Should_return_the_version.yml +42 -0
- data/spec/vcr_cassettes/Metrics/metrics_services/Templates/Tenants/Should_create_and_return_tenant.yml +95 -0
- data/spec/vcr_cassettes/{Counter_metrics → New_API_Counter_metrics}/Should_get_metrics_as_bucketed_results.yml +73 -33
- data/spec/vcr_cassettes/New_API_Mixed_metrics/Should_send_mixed_metric_request.yml +300 -0
- data/spec/vcr_cassettes/Operation/Helpers/get_feed.yml +17 -11
- data/spec/vcr_cassettes/Operation/Helpers/get_tenant.yml +13 -11
- data/spec/vcr_cassettes/Operation/Operation/Add_JDBC_driver_should_add_the_driver.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Add_datasource_should_be_doable.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Add_deployment_should_be_doable.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_can_be_run_multiple_times_in_parallel.json +4 -4
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_be_performed_and_eventually_respond_with_success.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Redeploy_should_not_be_performed_if_resource_path_is_wrong.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Remove_JDBC_driver_should_be_performed_and_eventually_respond_with_success.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Remove_datasource_should_be_performed_and_eventually_respond_with_success.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Remove_deployment_should_be_performed_and_eventually_respond_with_success.json +2 -2
- data/spec/vcr_cassettes/Operation/Operation/Undeploy_should_be_performed_and_eventually_respond_with_success.json +2 -2
- data/spec/vcr_cassettes/Operation/Websocket_connection/should_bail_with_hash_property_error_because_no_callback_at_all.json +9 -0
- data/spec/vcr_cassettes/Operation/Websocket_connection/should_bail_with_hash_property_error_because_no_error-callback_.json +9 -0
- data/spec/vcr_cassettes/Operation/Websocket_connection/should_run_into_error_callback_because_bad_hash_parameters.json +13 -0
- metadata +259 -139
- data/spec/vcr_cassettes/Gauge_metrics/Platform_mem.yml +0 -44
- data/spec/vcr_cassettes/Gauge_metrics/Platform_mem_def.yml +0 -45
- data/spec/vcr_cassettes/Inventory/Helpers/generate_some_events_for_websocket.yml +0 -4446
- data/spec/vcr_cassettes/Inventory/Templates/Client_should_listen_on_various_inventory_events.json +0 -47
- data/spec/vcr_cassettes/Inventory/Templates/Helpers/generate_some_events_for_websocket.yml +0 -542
- data/spec/vcr_cassettes/Inventory/Templates/Should_List_datasources_with_no_props.yml +0 -174
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_WildFlys_with_props.yml +0 -115
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_all_the_resource_types.yml +0 -126
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_children_of_WildFly.yml +0 -308
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_heap_metrics_for_WildFlys.yml +0 -712
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_for_WildFlys.yml +0 -278
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_of_given_metric_type.yml +0 -530
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_metrics_of_given_resource_type.yml +0 -278
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_operation_definitions_of_given_resource.yml +0 -185
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_operation_definitions_of_given_resource_type.yml +0 -126
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_recursive_children_of_WildFly.yml +0 -2369
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_relationships_of_WildFly.yml +0 -415
- data/spec/vcr_cassettes/Inventory/Templates/Should_list_types_with_feed.yml +0 -124
- data/spec/vcr_cassettes/Inventory/Templates/Should_return_config_data_of_given_resource.yml +0 -57
- data/spec/vcr_cassettes/Simple/Should_be_Cool.yml +0 -208
- data/spec/vcr_cassettes/Tenants/Should_Get_Tenant_For_Implicit_Credentials.yml +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7913796f40acecb8ad5eaeca8bb846dbaae63626
|
4
|
+
data.tar.gz: afdf2f08190d90a4f0a4be6bed389e42826c9e8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b02e20b49ef0fb225d99cc736ee506f7eb5f6b318a2e18b4a6671f19643debdf9be69f31e879a3e7069d7f5b78ef4c42c6bcf2cd895704d39e83871b24daf19
|
7
|
+
data.tar.gz: da752848f50298b6385becb2447969d054e54e0721e281356f58c530e1373a8f249cda2090634a084663fa63494fd7a247f65da2894da4c95950ddd57ad57361
|
data/CHANGES.rdoc
CHANGED
@@ -3,6 +3,18 @@
|
|
3
3
|
This document describes the relevant changes between releases of the
|
4
4
|
_hawkular-client_ project.
|
5
5
|
|
6
|
+
=== V 2.3.0
|
7
|
+
|
8
|
+
* Wrap connection errors in `HawkularConnectionException` (a subclass of `HawkularException`)
|
9
|
+
* Make sure the error callback is called on all kinds of errors (if it exists)
|
10
|
+
* Use the new Rest-API of Hawkular-Inventory.
|
11
|
+
* For authentication errors don't return raw html, but some sensible value
|
12
|
+
* Make it explicit that rest-client v2.0 is used to follow ManageIQ
|
13
|
+
* Provide parameters for operation definitions (depend on what the agent reports to inventory)
|
14
|
+
* Use the new Hawkular-metrics endpoints if the hawkular-metrics version we talk to is >= 0.16
|
15
|
+
|
16
|
+
Full list of items can be found at https://github.com/hawkular/hawkular-client-ruby/issues?q=milestone%3A2.3.0+is%3Aclosed
|
17
|
+
|
6
18
|
=== V 2.2.1
|
7
19
|
|
8
20
|
* Fix a regression where URI:HTTP objects were no longer accepted as input for entrypoints.
|
data/README.rdoc
CHANGED
@@ -128,10 +128,12 @@ Integration tests are recorded and played against cassettes recorded with VCR
|
|
128
128
|
rake spec
|
129
129
|
* To run the tests against a live server, set +VCR_OFF+ to +1+ as in
|
130
130
|
VCR_OFF=1 rake spec
|
131
|
-
* To update the VCR tapes that supports it, set +VCR_UPDATE+ to +1+ as in
|
131
|
+
* To update the VCR tapes that supports it (metrics and inventory), set +VCR_UPDATE+ to +1+ as in
|
132
132
|
VCR_UPDATE=1 rake spec
|
133
|
-
*
|
134
|
-
|
133
|
+
* Currently, we support two posible metrics contexts: <code>hawkular-metrics 0.8.0.Final</code> and <code>hawkular-services</code> that contain metrics. If you want to run/re-record the tests only for services, you can skip the other context by <code>SKIP_V8_METRICS=1</code>, or similarly <code>SKIP_SERVICES_METRICS=1</code>. So for instance updating the VCR templates only for hawkular-services would require command:
|
134
|
+
VCR_UPDATE=1 SKIP_V8_METRICS=1 rspec ./spec/integration/metric_spec.rb
|
135
|
+
|
136
|
+
For more details consult the {spec readme}[link:spec/README.rdoc].
|
135
137
|
|
136
138
|
== Logging
|
137
139
|
|
data/Rakefile
CHANGED
@@ -2,11 +2,19 @@ require 'bundler/gem_tasks'
|
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
require 'rubocop/rake_task'
|
4
4
|
|
5
|
+
desc 'Runs all the specs'
|
5
6
|
RSpec::Core::RakeTask.new(:spec) do |task|
|
6
7
|
task.pattern = './spec/**/*_spec.rb'
|
7
8
|
task.rspec_opts = ['--color']
|
8
9
|
end
|
9
10
|
|
11
|
+
desc 'Runs the specs for metrics 0.8.0.Final'
|
12
|
+
RSpec::Core::RakeTask.new(:'old-metrics') do |task|
|
13
|
+
task.pattern = './spec/integration/metric_spec.rb'
|
14
|
+
task.rspec_opts = ['--color']
|
15
|
+
ENV['SKIP_SERVICES_METRICS'] = '1'
|
16
|
+
end
|
17
|
+
|
10
18
|
RuboCop::RakeTask.new
|
11
19
|
|
12
20
|
task default: [:rubocop, :spec]
|
data/hawkularclient.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
22
|
gem.require_paths = ['lib']
|
23
23
|
|
24
|
-
gem.add_runtime_dependency('rest-client')
|
24
|
+
gem.add_runtime_dependency('rest-client', '~> 2.0.0')
|
25
25
|
gem.add_runtime_dependency('websocket-client-simple', '~> 0.3.0')
|
26
26
|
gem.add_runtime_dependency('addressable')
|
27
27
|
gem.add_development_dependency('shoulda')
|
data/lib/hawkular/base_client.rb
CHANGED
@@ -163,6 +163,9 @@ module Hawkular
|
|
163
163
|
attr_reader :message, :status_code
|
164
164
|
end
|
165
165
|
|
166
|
+
class HawkularConnectionException < HawkularException
|
167
|
+
end
|
168
|
+
|
166
169
|
private
|
167
170
|
|
168
171
|
def token_header
|
@@ -175,7 +178,20 @@ module Hawkular
|
|
175
178
|
headers
|
176
179
|
end
|
177
180
|
|
181
|
+
# @!visibility private
|
182
|
+
def connect_error(fault)
|
183
|
+
if fault.is_a?(SocketError)
|
184
|
+
HawkularConnectionException.new(fault.to_s)
|
185
|
+
elsif [Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH,
|
186
|
+
Errno::EADDRNOTAVAIL, Errno::ENETDOWN, Errno::ENETUNREACH,
|
187
|
+
Errno::ETIMEDOUT].include?(fault.class)
|
188
|
+
HawkularConnectionException.new(fault.to_s, fault.class::Errno)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
178
192
|
def handle_fault(f)
|
193
|
+
http_code = (f.respond_to?(:http_code) ? f.http_code : 0)
|
194
|
+
fail HawkularException.new('Unauthorized', http_code) if f.instance_of? RestClient::Unauthorized
|
179
195
|
if f.respond_to?(:http_body) && !f.http_body.nil?
|
180
196
|
begin
|
181
197
|
json_body = JSON.parse(f.http_body)
|
@@ -183,7 +199,9 @@ module Hawkular
|
|
183
199
|
rescue JSON::ParserError
|
184
200
|
fault_message = f.http_body
|
185
201
|
end
|
186
|
-
fail HawkularException.new(fault_message,
|
202
|
+
fail HawkularException.new(fault_message, http_code)
|
203
|
+
elsif (connect_error_exception = connect_error(f))
|
204
|
+
fail connect_error_exception
|
187
205
|
else
|
188
206
|
fail f
|
189
207
|
end
|
@@ -58,7 +58,7 @@ module Hawkular
|
|
58
58
|
|
59
59
|
# this is in a dedicated method, because constructor opens the websocket connection to make the handshake
|
60
60
|
def init_operations_client
|
61
|
-
Operations::OperationsClient.new(entrypoint: @state[:entrypoint].
|
61
|
+
Operations::OperationsClient.new(entrypoint: @state[:entrypoint].to_s.sub(/^https?/, 'ws'),
|
62
62
|
credentials: @state[:credentials],
|
63
63
|
options: @state[:options])
|
64
64
|
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# It contains class definitions that are used by the inventory REST client
|
2
|
+
module Hawkular::Inventory
|
3
|
+
# A Basic inventory entity with id, name, path and optional properties
|
4
|
+
class BaseEntity
|
5
|
+
# @return [String] Full path of the entity
|
6
|
+
attr_reader :path
|
7
|
+
# @return [String] Name of the entity
|
8
|
+
attr_reader :name
|
9
|
+
# @return [String] Id of the entity
|
10
|
+
attr_reader :id
|
11
|
+
# @return [String] Feed this entity belongs to (or nil in case of a feedless entity)
|
12
|
+
attr_reader :feed
|
13
|
+
# @return [String] Name of the environment for this entity
|
14
|
+
attr_reader :env
|
15
|
+
# @return [String] Properties of this entity
|
16
|
+
attr_reader :properties
|
17
|
+
|
18
|
+
def initialize(hash)
|
19
|
+
@id = hash['id']
|
20
|
+
@path = hash['path']
|
21
|
+
@name = hash['name'] || @id
|
22
|
+
@properties = hash['properties'] || {}
|
23
|
+
@_hash = hash.dup
|
24
|
+
|
25
|
+
return if @path.nil?
|
26
|
+
|
27
|
+
tmp = @path.split('/')
|
28
|
+
tmp.each do |pair|
|
29
|
+
(key, val) = pair.split(';')
|
30
|
+
case key
|
31
|
+
when 'f'
|
32
|
+
@feed = val
|
33
|
+
when 'e'
|
34
|
+
@env = val
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def ==(other)
|
40
|
+
self.equal?(other) || other.class == self.class && other.id == @id
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns a hash representation of the resource type
|
44
|
+
# @return [Hash<String,Object>] hash of the type
|
45
|
+
def to_h
|
46
|
+
@_hash.dup
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# A ResourceType is like a class definition for {Resource}s
|
51
|
+
# ResourceTypes are currently unique per feed, but one can assume
|
52
|
+
# that a two types with the same name of two different feeds are
|
53
|
+
# (more or less) the same.
|
54
|
+
class ResourceType < BaseEntity
|
55
|
+
def initialize(rt_hash)
|
56
|
+
super(rt_hash)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# A Resource is an instantiation of a {ResourceType}
|
61
|
+
class Resource < BaseEntity
|
62
|
+
# @return [String] Full path of the {ResourceType}
|
63
|
+
attr_reader :type_path
|
64
|
+
|
65
|
+
def initialize(res_hash)
|
66
|
+
super(res_hash)
|
67
|
+
if res_hash.key? :resourceTypePath
|
68
|
+
@type_path = res_hash[:resourceTypePath]
|
69
|
+
else
|
70
|
+
@type = res_hash['type']
|
71
|
+
@type_path = res_hash['type']['path']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Fields that are common for MetricType and Metric
|
77
|
+
module MetricFields
|
78
|
+
# @return [String] GAUGE, COUNTER, etc.
|
79
|
+
attr_reader :type
|
80
|
+
# @return [String] metric unit such as NONE, BYTES, etc.
|
81
|
+
attr_reader :unit
|
82
|
+
# @return [Long] collection interval in seconds, it has different semantics for MetricType and for Metric
|
83
|
+
# for MetricType it's a default that will be applied to all the metric of that type,
|
84
|
+
# in the Metric this can be overridden
|
85
|
+
attr_reader :collection_interval
|
86
|
+
end
|
87
|
+
|
88
|
+
# Definition of a Metric Type inside the inventory.
|
89
|
+
class MetricType < BaseEntity
|
90
|
+
include MetricFields
|
91
|
+
|
92
|
+
def initialize(type_hash)
|
93
|
+
super(type_hash)
|
94
|
+
@type = type_hash['type']
|
95
|
+
@unit = type_hash['unit']
|
96
|
+
@collection_interval = type_hash['collectionInterval']
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Definition of a Metric inside the inventory.
|
101
|
+
class Metric < BaseEntity
|
102
|
+
include MetricFields
|
103
|
+
|
104
|
+
def initialize(metric_hash)
|
105
|
+
super(metric_hash)
|
106
|
+
@type = metric_hash['type']['type']
|
107
|
+
@type_path = metric_hash['type']['path']
|
108
|
+
@unit = metric_hash['type']['unit']
|
109
|
+
@collection_interval = metric_hash['type']['collectionInterval']
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class OperationDefinition < BaseEntity
|
114
|
+
attr_reader :params
|
115
|
+
|
116
|
+
def initialize(op_hash)
|
117
|
+
super(op_hash)
|
118
|
+
@params = {}
|
119
|
+
param_list = op_hash['properties']['params']
|
120
|
+
return if param_list.nil?
|
121
|
+
param_list.each do |p|
|
122
|
+
@params.store p['name'], p
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Definition of a Relationship between two entities in Inventory
|
128
|
+
class Relationship
|
129
|
+
attr_accessor :source_id
|
130
|
+
attr_reader :target_id
|
131
|
+
attr_reader :properties
|
132
|
+
attr_reader :name
|
133
|
+
attr_reader :id
|
134
|
+
|
135
|
+
def initialize(hash = {})
|
136
|
+
if hash.empty?
|
137
|
+
@properties = {}
|
138
|
+
return
|
139
|
+
end
|
140
|
+
|
141
|
+
@source_id = hash['source']
|
142
|
+
@target_id = hash['target']
|
143
|
+
@properties = hash['properties']
|
144
|
+
@name = hash['name']
|
145
|
+
@id = hash['id']
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_h
|
149
|
+
hash = {}
|
150
|
+
hash['source'] = @source_id
|
151
|
+
hash['target'] = @target_id
|
152
|
+
hash['properties'] = @properties
|
153
|
+
hash['name'] = @name
|
154
|
+
hash['id'] = @id
|
155
|
+
hash
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
class CanonicalPath
|
160
|
+
attr_reader :tenant_id
|
161
|
+
attr_reader :feed_id
|
162
|
+
attr_reader :environment_id
|
163
|
+
attr_reader :resource_ids
|
164
|
+
attr_reader :metric_id
|
165
|
+
attr_reader :resource_type_id
|
166
|
+
attr_reader :metric_type_id
|
167
|
+
|
168
|
+
def initialize(hash)
|
169
|
+
@tenant_id = hash[:tenant_id]
|
170
|
+
@feed_id = hash[:feed_id]
|
171
|
+
@environment_id = hash[:environment_id]
|
172
|
+
@resource_type_id = hash[:resource_type_id]
|
173
|
+
@metric_type_id = hash[:metric_type_id]
|
174
|
+
@resource_ids = hash[:resource_ids]
|
175
|
+
@metric_id = hash[:metric_id]
|
176
|
+
end
|
177
|
+
|
178
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
179
|
+
def self.parse(path)
|
180
|
+
fail 'CanonicalPath must not be nil or empty' if path.to_s.strip.length == 0
|
181
|
+
tmp = path.split('/')
|
182
|
+
hash = {}
|
183
|
+
tmp.each do |pair|
|
184
|
+
(key, val) = pair.split(';')
|
185
|
+
case key
|
186
|
+
when 't'
|
187
|
+
hash[:tenant_id] = val
|
188
|
+
when 'f'
|
189
|
+
hash[:feed_id] = val
|
190
|
+
when 'e'
|
191
|
+
hash[:environment_id] = val
|
192
|
+
when 'm'
|
193
|
+
hash[:metric_id] = val
|
194
|
+
when 'r'
|
195
|
+
hash[:resource_ids] = [] if hash[:resource_ids].nil?
|
196
|
+
hash[:resource_ids].push(val)
|
197
|
+
when 'mt'
|
198
|
+
hash[:metric_type_id] = val
|
199
|
+
when 'rt'
|
200
|
+
hash[:resource_type_id] = val
|
201
|
+
end
|
202
|
+
end
|
203
|
+
CanonicalPath.new(hash)
|
204
|
+
end
|
205
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
206
|
+
|
207
|
+
def ==(other)
|
208
|
+
self.equal?(other) || other.class == self.class && other.state == state
|
209
|
+
end
|
210
|
+
|
211
|
+
def to_s
|
212
|
+
ret = "/t;#{@tenant_id}"
|
213
|
+
ret += "/f;#{@feed_id}" unless @feed_id.nil?
|
214
|
+
ret += "/e;#{@environment_id}" unless @environment_id.nil?
|
215
|
+
ret += "/rt;#{@resource_type_id}" unless @resource_type_id.nil?
|
216
|
+
ret += "/mt;#{@metric_type_id}" unless @metric_type_id.nil?
|
217
|
+
ret += "/m;#{@metric_id}" unless @metric_id.nil?
|
218
|
+
ret += resources_chunk.to_s
|
219
|
+
ret
|
220
|
+
end
|
221
|
+
|
222
|
+
protected
|
223
|
+
|
224
|
+
def state
|
225
|
+
[@tenant_id, @feed_id, @environment_id, @resource_ids, @metric_id, @metric_type_id, @resource_type_id]
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def resources_chunk
|
231
|
+
@resource_ids.map { |r| "/r;#{r}" }.join unless @resource_ids.nil?
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
@@ -2,6 +2,8 @@ require 'hawkular/base_client'
|
|
2
2
|
require 'websocket-client-simple'
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
require 'hawkular/inventory/entities'
|
6
|
+
|
5
7
|
# Inventory module provides access to the Hawkular Inventory REST API.
|
6
8
|
# @see http://www.hawkular.org/docs/rest/rest-inventory.html
|
7
9
|
#
|
@@ -10,6 +12,8 @@ require 'json'
|
|
10
12
|
module Hawkular::Inventory
|
11
13
|
# Client class to interact with Hawkular Inventory
|
12
14
|
class InventoryClient < Hawkular::BaseClient
|
15
|
+
attr_reader :version
|
16
|
+
|
13
17
|
# Create a new Inventory Client
|
14
18
|
# @param entrypoint [String] base url of Hawkular-inventory - e.g
|
15
19
|
# http://localhost:8080/hawkular/inventory
|
@@ -20,21 +24,7 @@ module Hawkular::Inventory
|
|
20
24
|
@entrypoint = entrypoint
|
21
25
|
super(entrypoint, credentials, options)
|
22
26
|
version = fetch_version_and_status['Implementation-Version']
|
23
|
-
|
24
|
-
@entrypoint << '/deprecated' unless major == 0 && minor < 17
|
25
|
-
end
|
26
|
-
|
27
|
-
def fetch_version_and_status
|
28
|
-
if @entrypoint.end_with? '/deprecated'
|
29
|
-
begin
|
30
|
-
backup_entrypoint = @entrypoint
|
31
|
-
@entrypoint = @entrypoint[0...-'/deprecated'.size]
|
32
|
-
return http_get('/status')
|
33
|
-
ensure
|
34
|
-
@entrypoint = backup_entrypoint
|
35
|
-
end
|
36
|
-
end
|
37
|
-
http_get('/status')
|
27
|
+
@version = version.scan(/\d+/).map(&:to_i)
|
38
28
|
end
|
39
29
|
|
40
30
|
# Creates a new Inventory Client
|
@@ -52,6 +42,8 @@ module Hawkular::Inventory
|
|
52
42
|
# If no credentials are passed, the ones from the constructor are used
|
53
43
|
# @param credentials [Hash{String=>String}] Hash of username, password, token(optional)
|
54
44
|
# @return [String] tenant id
|
45
|
+
# @deprecated this doesn't provide any value, because it merely returns the tenant ID which is known before the
|
46
|
+
# call anyway.
|
55
47
|
def get_tenant(credentials = {})
|
56
48
|
creds = credentials.empty? ? @credentials : credentials
|
57
49
|
auth_header = { Authorization: base_64_credentials(creds) }
|
@@ -61,16 +53,10 @@ module Hawkular::Inventory
|
|
61
53
|
ret['id']
|
62
54
|
end
|
63
55
|
|
64
|
-
# TODO: revisit and potentially move to Base ?
|
65
|
-
def impersonate!(credentials = {})
|
66
|
-
@tenant = get_tenant(credentials)
|
67
|
-
@options[:tenant] = @tenant
|
68
|
-
end
|
69
|
-
|
70
56
|
# List feeds in the system
|
71
57
|
# @return [Array<String>] List of feed ids
|
72
|
-
def list_feeds
|
73
|
-
ret = http_get('
|
58
|
+
def list_feeds
|
59
|
+
ret = http_get('/traversal/type=f')
|
74
60
|
ret.map { |f| f['id'] }
|
75
61
|
end
|
76
62
|
|
@@ -79,10 +65,10 @@ module Hawkular::Inventory
|
|
79
65
|
# @return [Array<ResourceType>] List of types, that can be empty
|
80
66
|
def list_resource_types(feed_id = nil)
|
81
67
|
if feed_id.nil?
|
82
|
-
ret = http_get('/
|
68
|
+
ret = http_get('/traversal/type=rt')
|
83
69
|
else
|
84
70
|
the_feed = hawk_escape_id feed_id
|
85
|
-
ret = http_get("/
|
71
|
+
ret = http_get("/traversal/f;#{the_feed}/type=rt")
|
86
72
|
end
|
87
73
|
ret.map { |rt| ResourceType.new(rt) }
|
88
74
|
end
|
@@ -94,7 +80,7 @@ module Hawkular::Inventory
|
|
94
80
|
def list_resources_for_feed(feed_id, fetch_properties = false, filter = {})
|
95
81
|
fail 'Feed id must be given' unless feed_id
|
96
82
|
the_feed = hawk_escape_id feed_id
|
97
|
-
ret = http_get("/
|
83
|
+
ret = http_get("/traversal/f;#{the_feed}/type=r")
|
98
84
|
to_filter = ret.map do |r|
|
99
85
|
if fetch_properties
|
100
86
|
p = get_config_data_for_resource(r['path'])
|
@@ -117,10 +103,9 @@ module Hawkular::Inventory
|
|
117
103
|
resource_type_id = path.resource_type_id
|
118
104
|
feed_id = path.feed_id
|
119
105
|
if feed_id.nil?
|
120
|
-
ret = http_get("
|
106
|
+
ret = http_get("/traversal/rt;#{resource_type_id}/rl;defines/type=r")
|
121
107
|
else
|
122
|
-
|
123
|
-
ret = http_get("/feeds/#{feed_id}/resourceTypes/#{resource_type_id}/resources")
|
108
|
+
ret = http_get("/traversal/f;#{feed_id}/rt;#{resource_type_id}/rl;defines/type=r")
|
124
109
|
end
|
125
110
|
ret.map do |r|
|
126
111
|
if fetch_properties && !feed_id.nil?
|
@@ -136,10 +121,9 @@ module Hawkular::Inventory
|
|
136
121
|
# @return [Hash<String,Object] Hash with additional data
|
137
122
|
def get_config_data_for_resource(resource_path)
|
138
123
|
path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
|
139
|
-
resource_path = path.resource_ids.join('/')
|
124
|
+
resource_path = 'r;' + path.resource_ids.join('/r;')
|
140
125
|
feed_id = path.feed_id
|
141
|
-
|
142
|
-
http_get("feeds/#{feed_id}/resources/#{resource_path}/data#{query}")
|
126
|
+
http_get("/entity/f;#{feed_id}/#{resource_path}/d;configuration")
|
143
127
|
rescue
|
144
128
|
{}
|
145
129
|
end
|
@@ -152,10 +136,14 @@ module Hawkular::Inventory
|
|
152
136
|
# Can be empty
|
153
137
|
def list_child_resources(parent_res_path, recursive = false)
|
154
138
|
path = parent_res_path.is_a?(CanonicalPath) ? parent_res_path : CanonicalPath.parse(parent_res_path)
|
155
|
-
parent_resource_path = path.resource_ids.join('/')
|
139
|
+
parent_resource_path = 'r;' + path.resource_ids.join('/r;')
|
156
140
|
feed_id = path.feed_id
|
157
|
-
|
158
|
-
|
141
|
+
|
142
|
+
if recursive
|
143
|
+
ret = http_get("/traversal/f;#{feed_id}/#{parent_resource_path}/recursive;over=isParentOf;type=r")
|
144
|
+
else
|
145
|
+
ret = http_get("/traversal/f;#{feed_id}/#{parent_resource_path}/type=r")
|
146
|
+
end
|
159
147
|
ret.map { |r| Resource.new(r) }
|
160
148
|
end
|
161
149
|
|
@@ -168,9 +156,14 @@ module Hawkular::Inventory
|
|
168
156
|
query_params = {
|
169
157
|
sort: '__targetCp'
|
170
158
|
}
|
171
|
-
|
159
|
+
|
172
160
|
query = generate_query_params query_params
|
173
|
-
|
161
|
+
if named.nil?
|
162
|
+
ret = http_get("/traversal#{path}/relationships#{query}")
|
163
|
+
else
|
164
|
+
ret = http_get("/traversal#{path}/relationships;name=#{named}#{query}")
|
165
|
+
end
|
166
|
+
|
174
167
|
ret.map { |r| Relationship.new(r) }
|
175
168
|
end
|
176
169
|
|
@@ -183,9 +176,14 @@ module Hawkular::Inventory
|
|
183
176
|
query_params = {
|
184
177
|
sort: '__targetCp'
|
185
178
|
}
|
186
|
-
|
179
|
+
|
187
180
|
query = generate_query_params query_params
|
188
|
-
|
181
|
+
if named.nil?
|
182
|
+
ret = http_get("/traversal/f;#{the_feed}/relationships#{query}")
|
183
|
+
else
|
184
|
+
ret = http_get("/traversal;/f;#{the_feed}/relationships;named=#{named}#{query}")
|
185
|
+
end
|
186
|
+
|
189
187
|
ret.map { |r| Relationship.new(r) }
|
190
188
|
rescue
|
191
189
|
[]
|
@@ -196,29 +194,9 @@ module Hawkular::Inventory
|
|
196
194
|
# @return inventory entity
|
197
195
|
def get_entity(path)
|
198
196
|
c_path = path.is_a?(CanonicalPath) ? path : CanonicalPath.parse(path)
|
199
|
-
http_get("
|
197
|
+
http_get("/entity/#{c_path}")
|
200
198
|
end
|
201
199
|
|
202
|
-
# [15:01:51] <jkremser> pilhuhn, this works for me curl -XPOST
|
203
|
-
# -H "Content-Type: application/json"
|
204
|
-
# -u jdoe:password -d
|
205
|
-
# '{"id" : "foo", "source": "/t;28026b36-8fe4-4332-84c8-524e173a68bf/f;localhost",
|
206
|
-
# "target": "/t;28026b36-8fe4-4332-84c8-524e173a68bf/f;localhost/r;localhost~Local~~/
|
207
|
-
# r;localhost~Local~%2Fsubsystem=hawkular-bus-broker",
|
208
|
-
# "name": "isRelatedTo"}'
|
209
|
-
# 'http://localhost:8080/hawkular/inventory/feeds/localhost/relationships'
|
210
|
-
#
|
211
|
-
# def create_relationship(source_resource, target_resource, name, properties = {})
|
212
|
-
# rel = Relationship.new
|
213
|
-
# rel.source_id = source_resource.path
|
214
|
-
# rel.target_id = target_resource.path
|
215
|
-
# rel.name = name
|
216
|
-
# rel.properties = properties
|
217
|
-
#
|
218
|
-
# http_post('/feeds/' + source_resource.feed + '/relationships',
|
219
|
-
# rel.to_h)
|
220
|
-
# end
|
221
|
-
|
222
200
|
# List the metrics for the passed metric type. If feed is not passed in the path,
|
223
201
|
# all the metrics across all the feeds of a given type will be retrieved
|
224
202
|
# This method may perform multiple REST calls.
|
@@ -230,16 +208,12 @@ module Hawkular::Inventory
|
|
230
208
|
metric_type_id = path.metric_type_id
|
231
209
|
feed_id = path.feed_id
|
232
210
|
if feed_id.nil?
|
233
|
-
|
211
|
+
ret = http_get("/traversal/mt;#{metric_type_id}/rl;defines/type=m")
|
234
212
|
else
|
235
|
-
|
213
|
+
ret = http_get("/traversal/f;#{feed_id}/mt;#{metric_type_id}/rl;defines/type=m")
|
236
214
|
end
|
237
215
|
|
238
|
-
|
239
|
-
relations.map do |rel|
|
240
|
-
metric_hash = get_entity rel.target_id.to_s
|
241
|
-
Metric.new(metric_hash)
|
242
|
-
end
|
216
|
+
ret.map { |m| Metric.new(m) }
|
243
217
|
rescue
|
244
218
|
[]
|
245
219
|
end
|
@@ -255,21 +229,14 @@ module Hawkular::Inventory
|
|
255
229
|
resource_type_id = path.resource_type_id
|
256
230
|
feed_id = path.feed_id
|
257
231
|
|
232
|
+
query = generate_query_params sort: 'id'
|
258
233
|
if feed_id.nil?
|
259
|
-
ret = http_get("
|
234
|
+
ret = http_get("/traversal/rt;#{resource_type_id}/rl;defines/type=r/rl;incorporates/type=m#{query}")
|
260
235
|
else
|
261
|
-
ret = http_get(
|
262
|
-
|
263
|
-
ret.flat_map do |r|
|
264
|
-
path = CanonicalPath.parse(r['path'])
|
265
|
-
query = generate_query_params sort: 'id'
|
266
|
-
if !path.feed_id.nil?
|
267
|
-
nested_ret = http_get("feeds/#{path.feed_id}/resources/#{path.resource_ids.join('/')}/metrics#{query}")
|
268
|
-
else
|
269
|
-
nested_ret = http_get("#{path.environment_id}/resources/#{path.resource_ids.join('/')}/metrics#{query}")
|
270
|
-
end
|
271
|
-
nested_ret.map { |m| Metric.new(m) }
|
236
|
+
ret = http_get(
|
237
|
+
"/traversal/f;#{feed_id}/rt;#{resource_type_id}/rl;defines/type=r/rl;incorporates/type=m#{query}")
|
272
238
|
end
|
239
|
+
ret.map { |m| Metric.new(m) }
|
273
240
|
end
|
274
241
|
|
275
242
|
# List metric (definitions) for the passed resource. It is possible to filter down the
|
@@ -289,10 +256,10 @@ module Hawkular::Inventory
|
|
289
256
|
def list_metrics_for_resource(resource_path, filter = {})
|
290
257
|
path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
|
291
258
|
feed_id = path.feed_id
|
292
|
-
resource_path_escaped = path.resource_ids.join('/')
|
259
|
+
resource_path_escaped = 'r;' + path.resource_ids.join('/r;')
|
293
260
|
|
294
261
|
query = generate_query_params sort: 'id'
|
295
|
-
ret = http_get("/
|
262
|
+
ret = http_get("/traversal/f;#{feed_id}/#{resource_path_escaped}/rl;incorporates/type=m#{query}")
|
296
263
|
to_filter = ret.map { |m| Metric.new(m) }
|
297
264
|
filter_entities(to_filter, filter)
|
298
265
|
end
|
@@ -307,12 +274,12 @@ module Hawkular::Inventory
|
|
307
274
|
feed[:name] = feed_name
|
308
275
|
|
309
276
|
begin
|
310
|
-
return http_post('/
|
277
|
+
return http_post('/entity/feed', feed)
|
311
278
|
rescue HawkularException => error
|
312
279
|
# 409 We already exist -> that is ok
|
313
280
|
if error.status_code == 409
|
314
281
|
the_feed = hawk_escape_id feed_id
|
315
|
-
http_get("/
|
282
|
+
http_get("/entity/f;#{the_feed}")
|
316
283
|
else
|
317
284
|
raise
|
318
285
|
end
|
@@ -323,7 +290,7 @@ module Hawkular::Inventory
|
|
323
290
|
# @param feed_id Id of the feed to be deleted.
|
324
291
|
def delete_feed(feed_id)
|
325
292
|
the_feed = hawk_escape_id feed_id
|
326
|
-
http_delete("/
|
293
|
+
http_delete("/entity/f;#{the_feed}")
|
327
294
|
end
|
328
295
|
|
329
296
|
# Create a new resource type
|
@@ -339,13 +306,13 @@ module Hawkular::Inventory
|
|
339
306
|
type[:name] = type_name
|
340
307
|
|
341
308
|
begin
|
342
|
-
http_post("/
|
309
|
+
http_post("/entity/f;#{the_feed}/resourceType", type)
|
343
310
|
rescue HawkularException => error
|
344
311
|
# 409 We already exist -> that is ok
|
345
312
|
raise unless error.status_code == 409
|
346
313
|
ensure
|
347
314
|
the_type = hawk_escape_id type_id
|
348
|
-
res = http_get("/
|
315
|
+
res = http_get("/entity/f;#{the_feed}/rt;#{the_type}")
|
349
316
|
end
|
350
317
|
ResourceType.new(res)
|
351
318
|
end
|
@@ -381,11 +348,11 @@ module Hawkular::Inventory
|
|
381
348
|
|
382
349
|
begin
|
383
350
|
if parent_res_path.nil?
|
384
|
-
res = http_post("/
|
351
|
+
res = http_post("/entity/f;#{feed_id}/resource", res)
|
385
352
|
else
|
386
353
|
path = parent_res_path.is_a?(CanonicalPath) ? parent_res_path : CanonicalPath.parse(parent_res_path)
|
387
|
-
resource_path = path.resource_ids.join('/')
|
388
|
-
res = http_post("/
|
354
|
+
resource_path = 'r;' + path.resource_ids.join('/r;')
|
355
|
+
res = http_post("/entity/f;#{feed_id}/#{resource_path}/resource", res)
|
389
356
|
end
|
390
357
|
rescue HawkularException => error
|
391
358
|
# 409 We already exist -> that is ok
|
@@ -400,9 +367,9 @@ module Hawkular::Inventory
|
|
400
367
|
def get_resource(resource_path, fetch_resource_config = true)
|
401
368
|
path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
|
402
369
|
feed_id = path.feed_id
|
403
|
-
res_path = path.resource_ids.join('/')
|
370
|
+
res_path = 'r;' + path.resource_ids.join('/r;')
|
404
371
|
|
405
|
-
res = http_get("/
|
372
|
+
res = http_get("/entity/f;#{feed_id}/#{res_path}")
|
406
373
|
if fetch_resource_config
|
407
374
|
p = get_config_data_for_resource(resource_path)
|
408
375
|
res['properties'] ||= {}
|
@@ -427,13 +394,13 @@ module Hawkular::Inventory
|
|
427
394
|
mt = build_metric_type_hash(collection_interval, metric_kind, metric_type_id, unit)
|
428
395
|
|
429
396
|
begin
|
430
|
-
http_post("/
|
397
|
+
http_post("/entity/f;#{the_feed}/metricType", mt)
|
431
398
|
rescue HawkularException => error
|
432
399
|
# 409 We already exist -> that is ok
|
433
400
|
raise unless error.status_code == 409
|
434
401
|
end
|
435
402
|
|
436
|
-
new_mt = http_get("/
|
403
|
+
new_mt = http_get("/entity/f;#{the_feed}/mt;#{metric_type_id}")
|
437
404
|
|
438
405
|
MetricType.new(new_mt)
|
439
406
|
end
|
@@ -445,8 +412,13 @@ module Hawkular::Inventory
|
|
445
412
|
parsed_path = CanonicalPath.parse(resource_type_path.to_s)
|
446
413
|
feed_id = parsed_path.feed_id
|
447
414
|
resource_type_id = parsed_path.resource_type_id
|
448
|
-
ret = http_get("/
|
449
|
-
|
415
|
+
ret = http_get("/traversal/f;#{feed_id}/rt;#{resource_type_id}/type=ot")
|
416
|
+
res = {}
|
417
|
+
ret.each do |ot|
|
418
|
+
od = OperationDefinition.new ot
|
419
|
+
res.store od.name, od
|
420
|
+
end
|
421
|
+
res
|
450
422
|
end
|
451
423
|
|
452
424
|
# List operation definitions (types) for a given resource
|
@@ -467,7 +439,7 @@ module Hawkular::Inventory
|
|
467
439
|
type_path = metric_type_path.is_a?(CanonicalPath) ? metric_type_path : CanonicalPath.parse(metric_type_path)
|
468
440
|
feed_id = type_path.feed_id
|
469
441
|
res_path = resource_path.is_a?(CanonicalPath) ? resource_path : CanonicalPath.parse(resource_path)
|
470
|
-
res_path_str = res_path.resource_ids.join('/')
|
442
|
+
res_path_str = 'r;' + res_path.resource_ids.join('/r;')
|
471
443
|
|
472
444
|
m = {}
|
473
445
|
m['id'] = metric_id
|
@@ -475,17 +447,20 @@ module Hawkular::Inventory
|
|
475
447
|
m['metricTypePath'] = type_path.to_s
|
476
448
|
|
477
449
|
begin
|
478
|
-
http_post("/
|
450
|
+
http_post("/entity/f;#{feed_id}/metric", m)
|
479
451
|
rescue HawkularException => error
|
480
452
|
# 409 We already exist -> that is ok
|
481
453
|
raise unless error.status_code == 409
|
482
454
|
end
|
483
455
|
|
484
|
-
ret = http_get("/
|
456
|
+
ret = http_get("/entity/f;#{feed_id}/m;#{metric_id}")
|
485
457
|
the_metric = Metric.new(ret)
|
486
458
|
|
487
459
|
begin
|
488
|
-
|
460
|
+
rl = {}
|
461
|
+
rl['otherEnd'] = the_metric.path.to_s
|
462
|
+
rl['name'] = 'incorporates'
|
463
|
+
http_post("/entity/f;#{feed_id}/#{res_path_str}/relationship", [rl])
|
489
464
|
rescue HawkularException => error
|
490
465
|
# 409 We already exist -> that is ok
|
491
466
|
raise unless error.status_code == 409
|
@@ -500,8 +475,18 @@ module Hawkular::Inventory
|
|
500
475
|
# Allowed values: created, updated, deleted, copied, registered
|
501
476
|
def events(type = 'resource', action = 'created')
|
502
477
|
tenant_id = get_tenant
|
478
|
+
|
479
|
+
base64_creds = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack('m').delete("\r\n")
|
480
|
+
ws_options = {
|
481
|
+
headers: {
|
482
|
+
Authorization: 'Basic ' + base64_creds,
|
483
|
+
Accept: 'application/json'
|
484
|
+
}
|
485
|
+
}
|
486
|
+
ws_options[:headers][:'Hawkular-Tenant'] = tenant_id
|
487
|
+
|
503
488
|
url = "#{entrypoint.gsub(/https?/, 'ws')}/ws/events?tenantId=#{tenant_id}&type=#{type}&action=#{action}"
|
504
|
-
@ws = WebSocket::Client::Simple.connect url do |client|
|
489
|
+
@ws = WebSocket::Client::Simple.connect url, ws_options do |client|
|
505
490
|
client.on :message do |msg|
|
506
491
|
parsed_message = JSON.parse(msg.data)
|
507
492
|
entity = case type
|
@@ -527,6 +512,13 @@ module Hawkular::Inventory
|
|
527
512
|
@ws.close
|
528
513
|
end
|
529
514
|
|
515
|
+
# Return version and status information for the used version of Hawkular-Inventory
|
516
|
+
# @return [Hash{String=>String}]
|
517
|
+
# ('Implementation-Version', 'Built-From-Git-SHA1', 'Status')
|
518
|
+
def fetch_version_and_status
|
519
|
+
http_get('/status')
|
520
|
+
end
|
521
|
+
|
530
522
|
private
|
531
523
|
|
532
524
|
# Creates a hash with the fields required by the Blueprint api in Hawkular-Inventory
|
@@ -562,215 +554,4 @@ module Hawkular::Inventory
|
|
562
554
|
end
|
563
555
|
end
|
564
556
|
end
|
565
|
-
|
566
|
-
# A Basic inventory entity with id, name, path and optional properties
|
567
|
-
class BaseEntity
|
568
|
-
# @return [String] Full path of the entity
|
569
|
-
attr_reader :path
|
570
|
-
# @return [String] Name of the entity
|
571
|
-
attr_reader :name
|
572
|
-
# @return [String] Name of the entity
|
573
|
-
attr_reader :id
|
574
|
-
# @return [String] Feed this entity belongs to (or nil in case of a feedless entity)
|
575
|
-
attr_reader :feed
|
576
|
-
# @return [String] Name of the environment for this entity
|
577
|
-
attr_reader :env
|
578
|
-
# @return [String] Properties of this entity
|
579
|
-
attr_reader :properties
|
580
|
-
|
581
|
-
def initialize(hash)
|
582
|
-
@id = hash['id']
|
583
|
-
@path = hash['path']
|
584
|
-
@name = hash['name'] || @id
|
585
|
-
@properties = hash['properties'] || {}
|
586
|
-
@_hash = hash.dup
|
587
|
-
|
588
|
-
return if @path.nil?
|
589
|
-
|
590
|
-
tmp = @path.split('/')
|
591
|
-
tmp.each do |pair|
|
592
|
-
(key, val) = pair.split(';')
|
593
|
-
case key
|
594
|
-
when 'f'
|
595
|
-
@feed = val
|
596
|
-
when 'e'
|
597
|
-
@env = val
|
598
|
-
end
|
599
|
-
end
|
600
|
-
end
|
601
|
-
|
602
|
-
def ==(other)
|
603
|
-
self.eql?(other) || other.class == self.class && other.id == @id
|
604
|
-
end
|
605
|
-
|
606
|
-
# Returns a hash representation of the resource type
|
607
|
-
# @return [Hash<String,Object>] hash of the type
|
608
|
-
def to_h
|
609
|
-
@_hash.dup
|
610
|
-
end
|
611
|
-
end
|
612
|
-
|
613
|
-
# A ResourceType is like a class definition for {Resource}s
|
614
|
-
# ResourceTypes are currently unique per feed, but one can assume
|
615
|
-
# that a two types with the same name of two different feeds are
|
616
|
-
# (more or less) the same.
|
617
|
-
class ResourceType < BaseEntity
|
618
|
-
def initialize(rt_hash)
|
619
|
-
super(rt_hash)
|
620
|
-
end
|
621
|
-
end
|
622
|
-
|
623
|
-
# A Resource is an instantiation of a {ResourceType}
|
624
|
-
class Resource < BaseEntity
|
625
|
-
# @return [String] Full path of the {ResourceType}
|
626
|
-
attr_reader :type_path
|
627
|
-
|
628
|
-
def initialize(res_hash)
|
629
|
-
super(res_hash)
|
630
|
-
@type = res_hash['type']
|
631
|
-
@type_path = res_hash['type']['path']
|
632
|
-
end
|
633
|
-
end
|
634
|
-
|
635
|
-
class MetricType < BaseEntity
|
636
|
-
# @return [String] GAUGE, COUNTER, etc.
|
637
|
-
attr_reader :type
|
638
|
-
# @return [String] metric unit such as NONE, BYTES, etc.
|
639
|
-
attr_reader :unit
|
640
|
-
# @return [Long] collection interval in seconds
|
641
|
-
attr_reader :collection_interval
|
642
|
-
|
643
|
-
def initialize(type_hash)
|
644
|
-
super(type_hash)
|
645
|
-
@type = type_hash['type']
|
646
|
-
@unit = type_hash['unit']
|
647
|
-
@collection_interval = type_hash['collectionInterval']
|
648
|
-
end
|
649
|
-
end
|
650
|
-
|
651
|
-
# Definition of a Metric inside the inventory.
|
652
|
-
class Metric < BaseEntity
|
653
|
-
# @return [String] GAUGE, COUNTER, etc.
|
654
|
-
attr_reader :type
|
655
|
-
# @return [String] metric unit such as NONE, BYTES, etc.
|
656
|
-
attr_reader :unit
|
657
|
-
# @return [Long] collection interval in seconds
|
658
|
-
attr_reader :collection_interval
|
659
|
-
|
660
|
-
def initialize(metric_hash)
|
661
|
-
super(metric_hash)
|
662
|
-
@type = metric_hash['type']['type']
|
663
|
-
@type_path = metric_hash['type']['path']
|
664
|
-
@unit = metric_hash['type']['unit']
|
665
|
-
@collection_interval = metric_hash['type']['collectionInterval']
|
666
|
-
end
|
667
|
-
end
|
668
|
-
|
669
|
-
# Definition of a Relationship between two entities in Inventory
|
670
|
-
class Relationship
|
671
|
-
attr_accessor :source_id
|
672
|
-
attr_reader :target_id
|
673
|
-
attr_reader :properties
|
674
|
-
attr_reader :name
|
675
|
-
attr_reader :id
|
676
|
-
|
677
|
-
def initialize(hash = {})
|
678
|
-
if hash.empty?
|
679
|
-
@properties = {}
|
680
|
-
return
|
681
|
-
end
|
682
|
-
|
683
|
-
@source_id = hash['source']
|
684
|
-
@target_id = hash['target']
|
685
|
-
@properties = hash['properties']
|
686
|
-
@name = hash['name']
|
687
|
-
@id = hash['id']
|
688
|
-
end
|
689
|
-
|
690
|
-
def to_h
|
691
|
-
hash = {}
|
692
|
-
hash['source'] = @source_id
|
693
|
-
hash['target'] = @target_id
|
694
|
-
hash['properties'] = @properties
|
695
|
-
hash['name'] = @name
|
696
|
-
hash['id'] = @id
|
697
|
-
hash
|
698
|
-
end
|
699
|
-
end
|
700
|
-
|
701
|
-
class CanonicalPath
|
702
|
-
attr_reader :tenant_id
|
703
|
-
attr_reader :feed_id
|
704
|
-
attr_reader :environment_id
|
705
|
-
attr_reader :resource_ids
|
706
|
-
attr_reader :metric_id
|
707
|
-
attr_reader :resource_type_id
|
708
|
-
attr_reader :metric_type_id
|
709
|
-
|
710
|
-
def initialize(hash)
|
711
|
-
@tenant_id = hash[:tenant_id]
|
712
|
-
@feed_id = hash[:feed_id]
|
713
|
-
@environment_id = hash[:environment_id]
|
714
|
-
@resource_type_id = hash[:resource_type_id]
|
715
|
-
@metric_type_id = hash[:metric_type_id]
|
716
|
-
@resource_ids = hash[:resource_ids]
|
717
|
-
@metric_id = hash[:metric_id]
|
718
|
-
end
|
719
|
-
|
720
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
721
|
-
def self.parse(path)
|
722
|
-
fail 'CanonicalPath must not be nil or emtpy' if path.to_s.strip.length == 0
|
723
|
-
tmp = path.split('/')
|
724
|
-
hash = {}
|
725
|
-
tmp.each do |pair|
|
726
|
-
(key, val) = pair.split(';')
|
727
|
-
case key
|
728
|
-
when 't'
|
729
|
-
hash[:tenant_id] = val
|
730
|
-
when 'f'
|
731
|
-
hash[:feed_id] = val
|
732
|
-
when 'e'
|
733
|
-
hash[:environment_id] = val
|
734
|
-
when 'm'
|
735
|
-
hash[:metric_id] = val
|
736
|
-
when 'r'
|
737
|
-
hash[:resource_ids] = [] if hash[:resource_ids].nil?
|
738
|
-
hash[:resource_ids].push(val)
|
739
|
-
when 'mt'
|
740
|
-
hash[:metric_type_id] = val
|
741
|
-
when 'rt'
|
742
|
-
hash[:resource_type_id] = val
|
743
|
-
end
|
744
|
-
end
|
745
|
-
CanonicalPath.new(hash)
|
746
|
-
end
|
747
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
748
|
-
|
749
|
-
def ==(other)
|
750
|
-
self.eql?(other) || other.class == self.class && other.state == state
|
751
|
-
end
|
752
|
-
|
753
|
-
def to_s
|
754
|
-
ret = "/t;#{@tenant_id}"
|
755
|
-
ret += "/f;#{@feed_id}" unless @feed_id.nil?
|
756
|
-
ret += "/e;#{@environment_id}" unless @environment_id.nil?
|
757
|
-
ret += "/rt;#{@resource_type_id}" unless @resource_type_id.nil?
|
758
|
-
ret += "/mt;#{@metric_type_id}" unless @metric_type_id.nil?
|
759
|
-
ret += "/m;#{@metric_id}" unless @metric_id.nil?
|
760
|
-
ret += resources_chunk.to_s
|
761
|
-
ret
|
762
|
-
end
|
763
|
-
|
764
|
-
protected
|
765
|
-
|
766
|
-
def state
|
767
|
-
[@tenant_id, @feed_id, @environment_id, @resource_ids, @metric_id, @metric_type_id, @resource_type_id]
|
768
|
-
end
|
769
|
-
|
770
|
-
private
|
771
|
-
|
772
|
-
def resources_chunk
|
773
|
-
@resource_ids.map { |r| "/r;#{r}" }.join unless @resource_ids.nil?
|
774
|
-
end
|
775
|
-
end
|
776
557
|
end
|