You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/11/03 09:12:19 UTC
[2/2] jclouds-labs git commit: JCLOUDS-1183
oneandone-monitoringpolicy-api
JCLOUDS-1183 oneandone-monitoringpolicy-api
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/87c54700
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/87c54700
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/87c54700
Branch: refs/heads/master
Commit: 87c54700316eef3722b41e6953f121766b9d9ba8
Parents: d68a2d3
Author: alibazlamit <al...@ali-G751JT>
Authored: Mon Oct 31 13:55:34 2016 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Thu Nov 3 10:05:06 2016 +0100
----------------------------------------------------------------------
.../jclouds/oneandone/rest/OneAndOneApi.java | 8 +
.../oneandone/rest/domain/MonitoringCenter.java | 208 +++++++
.../oneandone/rest/domain/MonitoringPolicy.java | 537 ++++++++++++++++++
.../jclouds/oneandone/rest/domain/Types.java | 40 ++
.../domain/options/GenericDateQueryOptions.java | 46 ++
.../rest/features/MonitoringCenterApi.java | 55 ++
.../rest/features/MonitoringPolicyApi.java | 158 ++++++
.../features/MonitoringCenterApiLiveTest.java | 93 ++++
.../features/MonitoringCenterApiMockTest.java | 159 ++++++
.../features/MonitoringPolicyApiLiveTest.java | 282 ++++++++++
.../features/MonitoringPolicyApiMockTest.java | 543 +++++++++++++++++++
.../test/resources/monitoringcenters/get.json | 165 ++++++
.../test/resources/monitoringcenters/list.json | 98 ++++
.../monitoringcenters/list.options.json | 98 ++++
.../test/resources/monitoringpolicy/get.json | 83 +++
.../resources/monitoringpolicy/get.port.json | 7 +
.../resources/monitoringpolicy/get.process.json | 6 +
.../resources/monitoringpolicy/get.server.json | 4 +
.../test/resources/monitoringpolicy/list.json | 173 ++++++
.../monitoringpolicy/list.options.json | 173 ++++++
.../resources/monitoringpolicy/list.ports.json | 16 +
.../monitoringpolicy/list.process.json | 14 +
.../monitoringpolicy/list.servers.json | 10 +
23 files changed, 2976 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/OneAndOneApi.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/OneAndOneApi.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/OneAndOneApi.java
index c12a75f..50610de 100644
--- a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/OneAndOneApi.java
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/OneAndOneApi.java
@@ -20,6 +20,8 @@ import java.io.Closeable;
import org.apache.jclouds.oneandone.rest.features.FirewallPolicyApi;
import org.apache.jclouds.oneandone.rest.features.ImageApi;
import org.apache.jclouds.oneandone.rest.features.LoadBalancerApi;
+import org.apache.jclouds.oneandone.rest.features.MonitoringCenterApi;
+import org.apache.jclouds.oneandone.rest.features.MonitoringPolicyApi;
import org.apache.jclouds.oneandone.rest.features.PrivateNetworkApi;
import org.apache.jclouds.oneandone.rest.features.PublicIpApi;
import org.apache.jclouds.oneandone.rest.features.ServerApi;
@@ -52,4 +54,10 @@ public interface OneAndOneApi extends Closeable {
@Delegate
VpnApi vpnApi();
+
+ @Delegate
+ MonitoringCenterApi monitoringCenterApi();
+
+ @Delegate
+ MonitoringPolicyApi monitoringPolicyApi();
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringCenter.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringCenter.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringCenter.java
new file mode 100644
index 0000000..d6a1e72
--- /dev/null
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringCenter.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.domain;
+
+import com.google.auto.value.AutoValue;
+import org.apache.jclouds.oneandone.rest.domain.Types.ServerState;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
+
+@AutoValue
+public abstract class MonitoringCenter {
+
+ public abstract String id();
+
+ public abstract String name();
+
+ @Nullable
+ public abstract String description();
+
+ @Nullable
+ public abstract Status status();
+
+ @Nullable
+ public abstract Alerts alerts();
+
+ @Nullable
+ public abstract Agent agent();
+
+ @SerializedNames({"id", "name", "description", "status", "alerts", "agent"})
+ public static MonitoringCenter create(String id, String name, String description, Status status, Alerts alerts, Agent agent) {
+ return new AutoValue_MonitoringCenter(id, name, description, status, alerts, agent);
+ }
+
+ @AutoValue
+ public abstract static class Status {
+
+ @Nullable
+ public abstract Cpu cpu();
+
+ @Nullable
+ public abstract Disk disk();
+
+ @Nullable
+ public abstract InternalPing internalPing();
+
+ @Nullable
+ public abstract Ram ram();
+
+ @Nullable
+ public abstract Transfer transfer();
+
+ public abstract ServerState state();
+
+ @SerializedNames({"cpu", "disk", "internal_ping", "ram", "transfer", "state"})
+ public static Status create(Cpu cpu, Disk disk, InternalPing internalPing, Ram ram, Transfer transfer, ServerState state) {
+ return new AutoValue_MonitoringCenter_Status(cpu, disk, internalPing, ram, transfer, state);
+ }
+
+ @AutoValue
+ public abstract static class Cpu {
+
+ @Nullable
+ public abstract String state();
+
+ @SerializedNames({"state"})
+ public static Cpu create(String state) {
+ return new AutoValue_MonitoringCenter_Status_Cpu(state);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Disk {
+
+ @Nullable
+ public abstract String state();
+
+ @SerializedNames({"state"})
+ public static Disk create(String state) {
+ return new AutoValue_MonitoringCenter_Status_Disk(state);
+ }
+ }
+
+ @AutoValue
+ public abstract static class InternalPing {
+
+ @Nullable
+ public abstract String state();
+
+ @SerializedNames({"state"})
+ public static InternalPing create(String state) {
+ return new AutoValue_MonitoringCenter_Status_InternalPing(state);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Ram {
+
+ @Nullable
+ public abstract String state();
+
+ @SerializedNames({"state"})
+ public static Ram create(String state) {
+ return new AutoValue_MonitoringCenter_Status_Ram(state);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Transfer {
+
+ @Nullable
+ public abstract String state();
+
+ @SerializedNames({"state"})
+ public static Transfer create(String state) {
+ return new AutoValue_MonitoringCenter_Status_Transfer(state);
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class Alerts {
+
+ public abstract Resources resources();
+
+ public abstract Ports ports();
+
+ public abstract Process process();
+
+ @AutoValue
+ public abstract static class Resources {
+
+ public abstract int critical();
+
+ public abstract int warning();
+
+ public abstract int ok();
+
+ @SerializedNames({"critical", "warning", "ok"})
+ public static Resources create(int critical, int warning, int ok) {
+ return new AutoValue_MonitoringCenter_Alerts_Resources(critical, warning, ok);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Ports {
+
+ public abstract int critical();
+
+ public abstract int warning();
+
+ public abstract int ok();
+
+ @SerializedNames({"critical", "warning", "ok"})
+ public static Ports create(int critical, int warning, int ok) {
+ return new AutoValue_MonitoringCenter_Alerts_Ports(critical, warning, ok);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Process {
+
+ public abstract int critical();
+
+ public abstract int warning();
+
+ public abstract int ok();
+
+ @SerializedNames({"critical", "warning", "ok"})
+ public static Process create(int critical, int warning, int ok) {
+ return new AutoValue_MonitoringCenter_Alerts_Process(critical, warning, ok);
+ }
+ }
+
+ @SerializedNames({"resources", "ports", "process"})
+ public static Alerts create(Resources resources, Ports ports, Process process) {
+ return new AutoValue_MonitoringCenter_Alerts(resources, ports, process);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Agent {
+
+ public abstract boolean agentinstalled();
+
+ public abstract boolean monitoringNeedsAgent();
+
+ public abstract boolean missingAgentAlert();
+
+ @SerializedNames({"agent_installed", "monitoring_needs_agent", "missing_agent_alert"})
+ public static Agent create(boolean agentinstalled, boolean monitoringNeedsAgent, boolean missingAgentAlert) {
+ return new AutoValue_MonitoringCenter_Agent(agentinstalled, monitoringNeedsAgent, missingAgentAlert);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringPolicy.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringPolicy.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringPolicy.java
new file mode 100644
index 0000000..64c528a
--- /dev/null
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/MonitoringPolicy.java
@@ -0,0 +1,537 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.domain;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.collect.ImmutableList;
+import java.util.Date;
+import java.util.List;
+import org.apache.jclouds.oneandone.rest.domain.Types.AlertIfType;
+import org.apache.jclouds.oneandone.rest.domain.Types.ProcessAlertType;
+import org.apache.jclouds.oneandone.rest.domain.Types.ProtocolType;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
+
+@AutoValue
+public abstract class MonitoringPolicy {
+
+ public abstract String id();
+
+ public abstract String name();
+
+ @Nullable
+ public abstract String description();
+
+ @Nullable
+ public abstract String state();
+
+ @Nullable
+ public abstract Date creationDate();
+
+ public abstract int isDefault();
+
+ @Nullable
+ public abstract String email();
+
+ public abstract boolean agent();
+
+ @Nullable
+ public abstract List<Server> servers();
+
+ public abstract Threshold thresholds();
+
+ @Nullable
+ public abstract List<Port> ports();
+
+ @Nullable
+ public abstract List<Process> processes();
+
+ public abstract String cloudpanelId();
+
+ @SerializedNames({"id", "name", "description", "state", "creation_date", "default", "email", "agent", "servers", "thresholds", "ports", "processes", "cloudpanel_id"})
+ public static MonitoringPolicy create(String id, String name, String description, String state,
+ Date creationDate, int isDefault, String email, boolean agent, List<Server> servers, Threshold thresholds, List<Port> ports, List<Process> processes, String cloudpanelId) {
+ return new AutoValue_MonitoringPolicy(id, name, description, state, creationDate, isDefault, email, agent, servers == null ? ImmutableList.<Server>of() : ImmutableList.copyOf(servers), thresholds, ports == null ? ImmutableList.<Port>of() : ImmutableList.copyOf(ports), processes == null ? ImmutableList.<Process>of() : ImmutableList.copyOf(processes), cloudpanelId);
+ }
+
+ @AutoValue
+ public abstract static class Server {
+
+ public abstract String id();
+
+ public abstract String name();
+
+ @SerializedNames({"id", "name"})
+ public static Server create(String id, String name) {
+ return new AutoValue_MonitoringPolicy_Server(id, name);
+ }
+
+ @AutoValue
+ public abstract static class CreateServer {
+
+ public abstract List<String> servers();
+
+ @SerializedNames({"servers"})
+ public static CreateServer create(List<String> servers) {
+ return new AutoValue_MonitoringPolicy_Server_CreateServer(servers == null ? ImmutableList.<String>of() : ImmutableList.copyOf(servers));
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class Threshold {
+
+ public abstract Cpu cpu();
+
+ public abstract Ram ram();
+
+ @Nullable
+ public abstract Disk disk();
+
+ public abstract Transfer transfer();
+
+ public abstract InternalPing internalPing();
+
+ @SerializedNames({"cpu", "ram", "disk", "transfer", "internal_ping"})
+ public static Threshold create(Cpu cpu, Ram ram, Disk disk, Transfer transfer, InternalPing internalPing) {
+ return new AutoValue_MonitoringPolicy_Threshold(cpu, ram, disk, transfer, internalPing);
+ }
+
+ @AutoValue
+ public abstract static class Cpu {
+
+ public abstract Warning warning();
+
+ public abstract Critical critical();
+
+ @SerializedNames({"warning", "critical"})
+ public static Cpu create(Warning warning, Critical critical) {
+ return new AutoValue_MonitoringPolicy_Threshold_Cpu(warning, critical);
+ }
+
+ @AutoValue
+ public abstract static class Warning {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Warning create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Cpu_Warning(value, alert);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Critical {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Critical create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Cpu_Critical(value, alert);
+ }
+
+ }
+
+ }
+
+ @AutoValue
+ public abstract static class Disk {
+
+ public abstract Warning warning();
+
+ public abstract Critical critical();
+
+ @SerializedNames({"warning", "critical"})
+ public static Disk create(Warning warning, Critical critical) {
+ return new AutoValue_MonitoringPolicy_Threshold_Disk(warning, critical);
+ }
+
+ @AutoValue
+ public abstract static class Warning {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Warning create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Disk_Warning(value, alert);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Critical {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Critical create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Disk_Critical(value, alert);
+ }
+
+ }
+
+ }
+
+ @AutoValue
+ public abstract static class Ram {
+
+ public abstract Warning warning();
+
+ public abstract Critical critical();
+
+ @SerializedNames({"warning", "critical"})
+ public static Ram create(Warning warning, Critical critical) {
+ return new AutoValue_MonitoringPolicy_Threshold_Ram(warning, critical);
+ }
+
+ @AutoValue
+ public abstract static class Warning {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Warning create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Ram_Warning(value, alert);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Critical {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Critical create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Ram_Critical(value, alert);
+ }
+
+ }
+
+ }
+
+ @AutoValue
+ public abstract static class Transfer {
+
+ public abstract Warning warning();
+
+ public abstract Critical critical();
+
+ @SerializedNames({"warning", "critical"})
+ public static Transfer create(Warning warning, Critical critical) {
+ return new AutoValue_MonitoringPolicy_Threshold_Transfer(warning, critical);
+ }
+
+ @AutoValue
+ public abstract static class Warning {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Warning create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Transfer_Warning(value, alert);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Critical {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Critical create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_Transfer_Critical(value, alert);
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class InternalPing {
+
+ public abstract Warning warning();
+
+ public abstract Critical critical();
+
+ @SerializedNames({"warning", "critical"})
+ public static InternalPing create(Warning warning, Critical critical) {
+ return new AutoValue_MonitoringPolicy_Threshold_InternalPing(warning, critical);
+ }
+
+ @AutoValue
+ public abstract static class Warning {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Warning create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_InternalPing_Warning(value, alert);
+ }
+ }
+
+ @AutoValue
+ public abstract static class Critical {
+
+ public abstract int value();
+
+ public abstract boolean alert();
+
+ @SerializedNames({"value", "alert"})
+ public static Critical create(int value, boolean alert) {
+ return new AutoValue_MonitoringPolicy_Threshold_InternalPing_Critical(value, alert);
+ }
+
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class Port {
+
+ public abstract String id();
+
+ public abstract ProtocolType protocol();
+
+ public abstract int port();
+
+ public abstract AlertIfType alertIf();
+
+ public abstract boolean emailNotification();
+
+ @SerializedNames({"id", "protocol", "port", "alert_if", "email_notification"})
+ public static Port create(String id, ProtocolType protocol, int port, AlertIfType alertIf, boolean emailNotification) {
+ return new AutoValue_MonitoringPolicy_Port(id, protocol, port, alertIf, emailNotification);
+ }
+
+ @AutoValue
+ public abstract static class AddPort {
+
+ public abstract int port();
+
+ public abstract AlertIfType alertIf();
+
+ public abstract boolean emailNotification();
+
+ public abstract ProtocolType protocol();
+
+ @SerializedNames({"port", "alert_if", "email_notification", "protocol"})
+ public static AddPort create(int port, AlertIfType alertIf, boolean emailNotification, ProtocolType protocol) {
+ return new AutoValue_MonitoringPolicy_Port_AddPort(port, alertIf, emailNotification, protocol);
+ }
+ }
+
+ @AutoValue
+ public abstract static class CreatePort {
+
+ public abstract List<AddPort> ports();
+
+ @SerializedNames({"ports"})
+ public static CreatePort create(List<AddPort> ports) {
+ return new AutoValue_MonitoringPolicy_Port_CreatePort(ports == null ? ImmutableList.<AddPort>of() : ImmutableList.copyOf(ports));
+ }
+ }
+
+ @AutoValue
+ public abstract static class UpdatePort {
+
+ public abstract AddPort ports();
+
+ @SerializedNames({"ports"})
+ public static UpdatePort create(AddPort ports) {
+ return new AutoValue_MonitoringPolicy_Port_UpdatePort(ports);
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class Process {
+
+ public abstract String id();
+
+ public abstract String process();
+
+ public abstract int port();
+
+ public abstract ProcessAlertType alertIf();
+
+ public abstract boolean emailNotification();
+
+ @SerializedNames({"id", "process", "port", "alert_if", "email_notification"})
+ public static Process create(String id, String process, int port, ProcessAlertType alertIf, boolean emailNotification) {
+ return new AutoValue_MonitoringPolicy_Process(id, process, port, alertIf, emailNotification);
+ }
+
+ @AutoValue
+ public abstract static class AddProcess {
+
+ public abstract String process();
+
+ public abstract AlertIfType alertIf();
+
+ public abstract boolean emailNotification();
+
+ @SerializedNames({"process", "alert_if", "email_notification"})
+ public static AddProcess create(String process, AlertIfType alertIf, boolean emailNotification) {
+ return new AutoValue_MonitoringPolicy_Process_AddProcess(process, alertIf, emailNotification);
+ }
+ }
+
+ @AutoValue
+ public abstract static class CreateProcess {
+
+ public abstract List<AddProcess> processes();
+
+ @SerializedNames({"processes"})
+ public static CreateProcess create(List<AddProcess> processes) {
+ return new AutoValue_MonitoringPolicy_Process_CreateProcess(processes == null ? ImmutableList.<AddProcess>of() : ImmutableList.copyOf(processes));
+ }
+ }
+
+ @AutoValue
+ public abstract static class UpdateProcess {
+
+ public abstract Process.AddProcess processes();
+
+ @SerializedNames({"processes"})
+ public static UpdateProcess create(Process.AddProcess processes) {
+ return new AutoValue_MonitoringPolicy_Process_UpdateProcess(processes);
+ }
+ }
+ }
+
+ @AutoValue
+ public abstract static class CreatePolicy {
+
+ public abstract String name();
+
+ @Nullable
+ public abstract String description();
+
+ public abstract String email();
+
+ public abstract boolean agent();
+
+ public abstract Threshold thresholds();
+
+ public abstract List<Port.AddPort> ports();
+
+ public abstract List<Process.AddProcess> processes();
+
+ @SerializedNames({"name", "description", "email", "agent", "thresholds", "ports", "processes"})
+ public static CreatePolicy create(String name, String description, String email,
+ boolean agent, Threshold thresholds, List<Port.AddPort> ports, List<Process.AddProcess> processes) {
+ return builder()
+ .agent(agent)
+ .description(description)
+ .email(email)
+ .name(name)
+ .ports(ports == null ? ImmutableList.<Port.AddPort>of() : ImmutableList.copyOf(ports))
+ .processes(processes == null ? ImmutableList.<Process.AddProcess>of() : ImmutableList.copyOf(processes))
+ .thresholds(thresholds)
+ .build();
+
+ }
+
+ public static Builder builder() {
+ return new AutoValue_MonitoringPolicy_CreatePolicy.Builder();
+ }
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+
+ public abstract Builder name(String name);
+
+ public abstract Builder description(String description);
+
+ public abstract Builder email(String email);
+
+ public abstract Builder agent(boolean agent);
+
+ public abstract Builder thresholds(Threshold thresholds);
+
+ public abstract Builder ports(List<Port.AddPort> ports);
+
+ public abstract Builder processes(List<Process.AddProcess> processes);
+
+ public abstract CreatePolicy build();
+ }
+ }
+
+ @AutoValue
+ public abstract static class UpdatePolicy {
+
+ @Nullable
+ public abstract String name();
+
+ @Nullable
+ public abstract String description();
+
+ public abstract String email();
+
+ public abstract boolean agent();
+
+ public abstract Threshold thresholds();
+
+ @SerializedNames({"name", "description", "email", "agent", "thresholds"})
+ public static UpdatePolicy create(String name, String description, String email,
+ boolean agent, Threshold thresholds, List<Port.AddPort> ports, List<Process.AddProcess> processes) {
+ return builder()
+ .agent(agent)
+ .description(description)
+ .email(email)
+ .name(name)
+ .thresholds(thresholds)
+ .build();
+
+ }
+
+ public static Builder builder() {
+ return new AutoValue_MonitoringPolicy_UpdatePolicy.Builder();
+ }
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+
+ public abstract Builder name(String name);
+
+ public abstract Builder description(String description);
+
+ public abstract Builder email(String email);
+
+ public abstract Builder agent(boolean agent);
+
+ public abstract Builder thresholds(Threshold thresholds);
+
+ public abstract UpdatePolicy build();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/Types.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/Types.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/Types.java
index 6d8c67b..8f70ee4 100644
--- a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/Types.java
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/Types.java
@@ -202,4 +202,44 @@ public class Types {
return Enums.getIfPresent(VPNType.class, v).or(UNRECOGNIZED);
}
}
+
+ public enum PeriodType {
+ LAST_HOUR, LAST_24H, LAST_7D, LAST_30D, LAST_365D, UNRECOGNIZED;
+
+ public static PeriodType fromValue(String v) {
+ return Enums.getIfPresent(PeriodType.class, v).or(UNRECOGNIZED);
+}
+ }
+
+ public enum CustomPeriodType {
+ CUSTOM, UNRECOGNIZED;
+
+ public static CustomPeriodType fromValue(String v) {
+ return Enums.getIfPresent(CustomPeriodType.class, v).or(UNRECOGNIZED);
+ }
+ }
+
+ public enum ProtocolType {
+ TCP, UDP, UNRECOGNIZED;
+
+ public static ProtocolType fromValue(String v) {
+ return Enums.getIfPresent(ProtocolType.class, v).or(UNRECOGNIZED);
+ }
+ }
+
+ public enum AlertIfType {
+ RESPONDING, NOT_RESPONDING, UNRECOGNIZED;
+
+ public static AlertIfType fromValue(String v) {
+ return Enums.getIfPresent(AlertIfType.class, v).or(UNRECOGNIZED);
+ }
+ }
+
+ public enum ProcessAlertType {
+ RUNNING, NOT_RUNNING, UNRECOGNIZED;
+
+ public static ProcessAlertType fromValue(String v) {
+ return Enums.getIfPresent(ProcessAlertType.class, v).or(UNRECOGNIZED);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/options/GenericDateQueryOptions.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/options/GenericDateQueryOptions.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/options/GenericDateQueryOptions.java
new file mode 100644
index 0000000..4d26751
--- /dev/null
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/domain/options/GenericDateQueryOptions.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.domain.options;
+
+import java.util.Date;
+import org.apache.jclouds.oneandone.rest.domain.Types.CustomPeriodType;
+import org.apache.jclouds.oneandone.rest.domain.Types.PeriodType;
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+public class GenericDateQueryOptions extends BaseHttpRequestOptions {
+
+ public static final String PERIOD = "period";
+ public static final String STARTDATE = "start_date";
+ public static final String ENDDATE = "end_date";
+ private static final DateService DATE_SERVICE = new SimpleDateFormatDateService();
+
+ public GenericDateQueryOptions customPeriod(Date startDate, Date endDate) {
+
+ queryParameters.put(PERIOD, CustomPeriodType.CUSTOM.toString());
+ queryParameters.put(STARTDATE, DATE_SERVICE.iso8601SecondsDateFormat(startDate));
+ queryParameters.put(ENDDATE, DATE_SERVICE.iso8601SecondsDateFormat(endDate));
+ return this;
+ }
+
+ public GenericDateQueryOptions fixedPeriods(PeriodType period) {
+
+ queryParameters.put(PERIOD, period.toString());
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApi.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApi.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApi.java
new file mode 100644
index 0000000..85f2912
--- /dev/null
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApi.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.features;
+
+import java.util.List;
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import org.apache.jclouds.oneandone.rest.domain.MonitoringCenter;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericDateQueryOptions;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
+import org.apache.jclouds.oneandone.rest.filters.AuthenticateRequest;
+import org.jclouds.Fallbacks;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.RequestFilters;
+
+@Path("/monitoring_center")
+@Produces("application/json")
+@Consumes("application/json")
+@RequestFilters(AuthenticateRequest.class)
+public interface MonitoringCenterApi {
+
+ @Named("monitoringcenter:list")
+ @GET
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringCenter> list();
+
+ @Named("monitoringcenter:list")
+ @GET
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringCenter> list(GenericQueryOptions options);
+
+ @Named("monitoringcenter:get")
+ @GET
+ @Path("/{serverId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ MonitoringCenter get(@PathParam("serverId") String serverId, GenericDateQueryOptions options);
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApi.java
----------------------------------------------------------------------
diff --git a/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApi.java b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApi.java
new file mode 100644
index 0000000..6890b09
--- /dev/null
+++ b/oneandone/src/main/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApi.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.features;
+
+import java.util.List;
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import org.apache.jclouds.oneandone.rest.domain.MonitoringPolicy;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
+import org.apache.jclouds.oneandone.rest.filters.AuthenticateRequest;
+import org.jclouds.Fallbacks;
+import org.jclouds.rest.annotations.BinderParam;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.MapBinder;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.binders.BindToJsonPayload;
+
+@Path("/monitoring_policies")
+@Produces("application/json")
+@Consumes("application/json")
+@RequestFilters(AuthenticateRequest.class)
+public interface MonitoringPolicyApi {
+
+ @Named("monitoringpolicy:list")
+ @GET
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringPolicy> list();
+
+ @Named("monitoringpolicy:list")
+ @GET
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringPolicy> list(GenericQueryOptions options);
+
+ @Named("monitoringpolicy:get")
+ @GET
+ @Path("/{policyId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ MonitoringPolicy get(@PathParam("policyId") String policyId);
+
+ @Named("monitoringpolicy:create")
+ @POST
+ MonitoringPolicy create(@BinderParam(BindToJsonPayload.class) MonitoringPolicy.CreatePolicy policy);
+
+ @Named("monitoringpolicy:update")
+ @PUT
+ @Path("/{policyId}")
+ MonitoringPolicy update(@PathParam("policyId") String policyId, @BinderParam(BindToJsonPayload.class) MonitoringPolicy.UpdatePolicy policy);
+
+ @Named("monitoringpolicy:delete")
+ @DELETE
+ @Path("/{policyId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ @MapBinder(BindToJsonPayload.class)
+ MonitoringPolicy delete(@PathParam("policyId") String policyId);
+
+ @Named("monitoringpolicy:ports:list")
+ @GET
+ @Path("/{policyId}/ports")
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringPolicy.Port> listPorts(@PathParam("policyId") String policyId);
+
+ @Named("monitoringpolicy:ports:get")
+ @GET
+ @Path("/{policyId}/ports/{portId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ MonitoringPolicy.Port getPort(@PathParam("policyId") String policyId, @PathParam("portId") String portId);
+
+ @Named("monitoringpolicy:ports:create")
+ @POST
+ @Path("/{policyId}/ports")
+ MonitoringPolicy addPort(@PathParam("policyId") String policyId, @BinderParam(BindToJsonPayload.class) MonitoringPolicy.Port.CreatePort port);
+
+ @Named("monitoringpolicy:ports:update")
+ @PUT
+ @Path("/{policyId}/ports/{portId}")
+ MonitoringPolicy updatePort(@PathParam("policyId") String policyId, @PathParam("portId") String portId, @BinderParam(BindToJsonPayload.class) MonitoringPolicy.Port.UpdatePort port);
+
+ @Named("monitoringpolicy:ports:delete")
+ @DELETE
+ @Path("/{policyId}/ports/{portId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ @MapBinder(BindToJsonPayload.class)
+ MonitoringPolicy deletePort(@PathParam("policyId") String policyId, @PathParam("portId") String portId);
+
+ @Named("monitoringpolicy:processes:list")
+ @GET
+ @Path("/{policyId}/processes")
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringPolicy.Process> listProcesses(@PathParam("policyId") String policyId);
+
+ @Named("monitoringpolicy:processes:get")
+ @GET
+ @Path("/{policyId}/processes/{processId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ MonitoringPolicy.Process getProcess(@PathParam("policyId") String policyId, @PathParam("processId") String processId);
+
+ @Named("monitoringpolicy:processes:create")
+ @POST
+ @Path("/{policyId}/processes")
+ MonitoringPolicy addProcess(@PathParam("policyId") String policyId, @BinderParam(BindToJsonPayload.class) MonitoringPolicy.Process.CreateProcess process);
+
+ @Named("monitoringpolicy:processes:update")
+ @PUT
+ @Path("/{policyId}/processes/{processId}")
+ MonitoringPolicy updateProcess(@PathParam("policyId") String policyId, @PathParam("processId") String processId, @BinderParam(BindToJsonPayload.class) MonitoringPolicy.Process.UpdateProcess process);
+
+ @Named("monitoringpolicy:processes:delete")
+ @DELETE
+ @Path("/{policyId}/processes/{processId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ @MapBinder(BindToJsonPayload.class)
+ MonitoringPolicy deleteProcess(@PathParam("policyId") String policyId, @PathParam("processId") String processId);
+
+ @Named("monitoringpolicy:servers:list")
+ @GET
+ @Path("/{policyId}/servers")
+ @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class)
+ List<MonitoringPolicy.Server> listServers(@PathParam("policyId") String policyId);
+
+ @Named("monitoringpolicy:servers:create")
+ @POST
+ @Path("/{policyId}/servers")
+ MonitoringPolicy attachServer(@PathParam("policyId") String policyId, @BinderParam(BindToJsonPayload.class) MonitoringPolicy.Server.CreateServer server);
+
+ @Named("monitoringpolicy:servers:get")
+ @GET
+ @Path("/{policyId}/servers/{serverId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ MonitoringPolicy.Server getServer(@PathParam("policyId") String policyId, @PathParam("serverId") String serverId);
+
+ @Named("monitoringpolicy:servers:delete")
+ @DELETE
+ @Path("/{policyId}/servers/{serverId}")
+ @Fallback(Fallbacks.NullOnNotFoundOr404.class)
+ @MapBinder(BindToJsonPayload.class)
+ MonitoringPolicy detachServer(@PathParam("policyId") String policyId, @PathParam("serverId") String serverId);
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiLiveTest.java
----------------------------------------------------------------------
diff --git a/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiLiveTest.java b/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiLiveTest.java
new file mode 100644
index 0000000..57ab678
--- /dev/null
+++ b/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiLiveTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.features;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import org.apache.jclouds.oneandone.rest.domain.MonitoringCenter;
+import org.apache.jclouds.oneandone.rest.domain.Server;
+import org.apache.jclouds.oneandone.rest.domain.Types;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericDateQueryOptions;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
+import org.apache.jclouds.oneandone.rest.internal.BaseOneAndOneLiveTest;
+import org.testng.Assert;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Test(groups = "live", testName = "MonitoringCenterApiLiveTest")
+public class MonitoringCenterApiLiveTest extends BaseOneAndOneLiveTest {
+
+ private Server currentServer;
+
+ private MonitoringCenterApi monitoringCenterApi() {
+
+ return api.monitoringCenterApi();
+ }
+
+ @BeforeClass
+ public void setupTest() throws InterruptedException {
+ currentServer = createServer("Monitoring Center jclouds server");
+ assertNodeAvailable(currentServer);
+ }
+
+ @Test
+ public void testList() {
+ List<MonitoringCenter> result = monitoringCenterApi().list();
+
+ assertNotNull(result);
+ Assert.assertTrue(result.size() >= 1);
+ }
+
+ @Test
+ public void testListWithOption() {
+ GenericQueryOptions options = new GenericQueryOptions();
+ options.options(1, 1, null, null, null);
+ List<MonitoringCenter> resultWithQuery = monitoringCenterApi().list(options);
+
+ assertNotNull(resultWithQuery);
+ Assert.assertTrue(resultWithQuery.size() >= 1);
+ }
+
+ @Test
+ public void testGetCustomPeriod() {
+ GenericDateQueryOptions options = new GenericDateQueryOptions();
+ Calendar cal = Calendar.getInstance();
+ Date end = cal.getTime();
+ cal.add(Calendar.DATE, -2);
+ Date start = cal.getTime();
+ options.customPeriod(start, end);
+ MonitoringCenter result = monitoringCenterApi().get(currentServer.id(), options);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetFixedPeriod() {
+ GenericDateQueryOptions options = new GenericDateQueryOptions();
+ options.fixedPeriods(Types.PeriodType.LAST_7D);
+ MonitoringCenter result = monitoringCenterApi().get(currentServer.id(), options);
+ assertNotNull(result);
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void teardownTest() throws InterruptedException {
+ assertNodeAvailable(currentServer);
+ deleteServer(currentServer.id());
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiMockTest.java
----------------------------------------------------------------------
diff --git a/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiMockTest.java b/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiMockTest.java
new file mode 100644
index 0000000..dc74551
--- /dev/null
+++ b/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringCenterApiMockTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.features;
+
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+import org.apache.jclouds.oneandone.rest.domain.MonitoringCenter;
+import org.apache.jclouds.oneandone.rest.domain.Types;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericDateQueryOptions;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
+import org.apache.jclouds.oneandone.rest.internal.BaseOneAndOneApiMockTest;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "MonitoringCenterApiMockTest", singleThreaded = true)
+public class MonitoringCenterApiMockTest extends BaseOneAndOneApiMockTest {
+
+ private MonitoringCenterApi monitoringCenterApi() {
+ return api.monitoringCenterApi();
+ }
+
+ @Test
+ public void testList() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/monitoringcenters/list.json"))
+ );
+
+ List<MonitoringCenter> result = monitoringCenterApi().list();
+
+ assertNotNull(result);
+ assertEquals(result.size(), 2);
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center");
+ }
+
+ @Test
+ public void testList404() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setResponseCode(404));
+
+ List<MonitoringCenter> result = monitoringCenterApi().list();
+
+ assertEquals(result.size(), 0);
+
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center");
+ }
+
+ @Test
+ public void testListWithOption() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/monitoringcenters/list.options.json"))
+ );
+ GenericQueryOptions options = new GenericQueryOptions();
+ options.options(0, 0, null, "New", null);
+ List<MonitoringCenter> result = monitoringCenterApi().list(options);
+
+ assertEquals(result.size(), 2);
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center?q=New");
+ }
+
+ @Test
+ public void testListWithOption404() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setResponseCode(404));
+
+ GenericQueryOptions options = new GenericQueryOptions();
+ options.options(0, 0, null, "New", null);
+ List<MonitoringCenter> result = monitoringCenterApi().list(options);
+
+ assertEquals(result.size(), 0);
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center?q=New");
+ }
+
+ public void testGetCustomPeriod() throws InterruptedException, ParseException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/monitoringcenters/get.json"))
+ );
+ GenericDateQueryOptions options = new GenericDateQueryOptions();
+ String startStr = "11-11-2012";
+ String endStr = "11-11-2013";
+ DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ Date end = dateFormat.parse(endStr);
+ Date start = dateFormat.parse(startStr);
+ options.customPeriod(start, end);
+
+ MonitoringCenter result = monitoringCenterApi().get("serverId", options);
+ assertNotNull(result);
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center/serverId?period=CUSTOM&start_date=2012-11-11T00%3A00%3A00Z&end_date=2013-11-11T00%3A00%3A00Z");
+ }
+
+ public void testGetCustomPeriod404() throws InterruptedException, ParseException {
+ server.enqueue(
+ new MockResponse().setResponseCode(404));
+ GenericDateQueryOptions options = new GenericDateQueryOptions();
+ String startStr = "11-11-2012";
+ String endStr = "11-11-2013";
+ DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ Date end = dateFormat.parse(endStr);
+ Date start = dateFormat.parse(startStr);
+ options.customPeriod(start, end);
+ MonitoringCenter result = monitoringCenterApi().get("serverId", options);
+
+ assertEquals(result, null);
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center/serverId?period=CUSTOM&start_date=2012-11-11T00%3A00%3A00Z&end_date=2013-11-11T00%3A00%3A00Z");
+ }
+
+ public void testGetFixedPeriod() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setBody(stringFromResource("/monitoringcenters/get.json"))
+ );
+ GenericDateQueryOptions options = new GenericDateQueryOptions();
+ options.fixedPeriods(Types.PeriodType.LAST_24H);
+ MonitoringCenter result = monitoringCenterApi().get("serverId", options);
+
+ assertNotNull(result);
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center/serverId?period=LAST_24H");
+ }
+
+ public void testGetFixedPeriod404() throws InterruptedException {
+ server.enqueue(
+ new MockResponse().setResponseCode(404));
+ GenericDateQueryOptions options = new GenericDateQueryOptions();
+ options.fixedPeriods(Types.PeriodType.LAST_24H);
+ MonitoringCenter result = monitoringCenterApi().get("serverId", options);
+
+ assertEquals(result, null);
+ assertEquals(server.getRequestCount(), 1);
+ assertSent(server, "GET", "/monitoring_center/serverId?period=LAST_24H");
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/87c54700/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApiLiveTest.java
----------------------------------------------------------------------
diff --git a/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApiLiveTest.java b/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApiLiveTest.java
new file mode 100644
index 0000000..a9efc56
--- /dev/null
+++ b/oneandone/src/test/java/org/apache/jclouds/oneandone/rest/features/MonitoringPolicyApiLiveTest.java
@@ -0,0 +1,282 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jclouds.oneandone.rest.features;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.jclouds.oneandone.rest.domain.MonitoringPolicy;
+import org.apache.jclouds.oneandone.rest.domain.Server;
+import org.apache.jclouds.oneandone.rest.domain.Types;
+import org.apache.jclouds.oneandone.rest.domain.options.GenericQueryOptions;
+import org.apache.jclouds.oneandone.rest.internal.BaseOneAndOneLiveTest;
+import org.testng.Assert;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Test(groups = "live", testName = "MonitoringPolicyApiLiveTest")
+public class MonitoringPolicyApiLiveTest extends BaseOneAndOneLiveTest {
+
+ private MonitoringPolicy currentPolicy;
+ private MonitoringPolicy.Port currentPort;
+ private MonitoringPolicy.Process currentProcess;
+ private List<MonitoringPolicy> policies;
+ private Server currentServer;
+
+ private MonitoringPolicyApi monitoringPolicyApi() {
+
+ return api.monitoringPolicyApi();
+ }
+
+ @BeforeClass
+ public void setupTest() {
+ currentServer = createServer("Monitoring Policy jclouds server");
+ assertNodeAvailable(currentServer);
+
+ List<MonitoringPolicy.Port.AddPort> ports = new ArrayList<MonitoringPolicy.Port.AddPort>();
+ MonitoringPolicy.Port.AddPort port = MonitoringPolicy.Port.AddPort.create(80, Types.AlertIfType.RESPONDING, true, Types.ProtocolType.TCP);
+ ports.add(port);
+
+ List<org.apache.jclouds.oneandone.rest.domain.MonitoringPolicy.Process.AddProcess> processes = new ArrayList<org.apache.jclouds.oneandone.rest.domain.MonitoringPolicy.Process.AddProcess>();
+ org.apache.jclouds.oneandone.rest.domain.MonitoringPolicy.Process.AddProcess process = org.apache.jclouds.oneandone.rest.domain.MonitoringPolicy.Process.AddProcess.create("", Types.AlertIfType.RESPONDING, true);
+ processes.add(process);
+
+ MonitoringPolicy.Threshold.Cpu.Warning warning = MonitoringPolicy.Threshold.Cpu.Warning.create(90, true);
+ MonitoringPolicy.Threshold.Cpu.Critical critical = MonitoringPolicy.Threshold.Cpu.Critical.create(95, true);
+ MonitoringPolicy.Threshold.Cpu cpu = MonitoringPolicy.Threshold.Cpu.create(warning, critical);
+
+ MonitoringPolicy.Threshold.Ram.Warning ramWarning = MonitoringPolicy.Threshold.Ram.Warning.create(90, true);
+ MonitoringPolicy.Threshold.Ram.Critical ramCritical = MonitoringPolicy.Threshold.Ram.Critical.create(95, true);
+ MonitoringPolicy.Threshold.Ram ram = MonitoringPolicy.Threshold.Ram.create(ramWarning, ramCritical);
+
+ MonitoringPolicy.Threshold.Disk.Warning diskWarning = MonitoringPolicy.Threshold.Disk.Warning.create(90, true);
+ MonitoringPolicy.Threshold.Disk.Critical diskCritical = MonitoringPolicy.Threshold.Disk.Critical.create(95, true);
+ MonitoringPolicy.Threshold.Disk disk = MonitoringPolicy.Threshold.Disk.create(diskWarning, diskCritical);
+
+ MonitoringPolicy.Threshold.InternalPing.Warning pingWarning = MonitoringPolicy.Threshold.InternalPing.Warning.create(50, true);
+ MonitoringPolicy.Threshold.InternalPing.Critical pingCritical = MonitoringPolicy.Threshold.InternalPing.Critical.create(100, true);
+ MonitoringPolicy.Threshold.InternalPing ping = MonitoringPolicy.Threshold.InternalPing.create(pingWarning, pingCritical);
+
+ MonitoringPolicy.Threshold.Transfer.Warning tranWarning = MonitoringPolicy.Threshold.Transfer.Warning.create(1000, true);
+ MonitoringPolicy.Threshold.Transfer.Critical tranCritical = MonitoringPolicy.Threshold.Transfer.Critical.create(2000, true);
+ MonitoringPolicy.Threshold.Transfer transfer = MonitoringPolicy.Threshold.Transfer.create(tranWarning, tranCritical);
+
+ MonitoringPolicy.Threshold threshold = MonitoringPolicy.Threshold.create(cpu, ram, disk, transfer, ping);
+ MonitoringPolicy.CreatePolicy payload = MonitoringPolicy.CreatePolicy.builder()
+ .name("jclouds policy")
+ .agent(true)
+ .email("j@clouds.com")
+ .ports(ports)
+ .processes(processes)
+ .description("dsec")
+ .thresholds(threshold)
+ .build();
+ currentPolicy = monitoringPolicyApi().create(payload);
+ }
+
+ @Test
+ public void testList() {
+ policies = monitoringPolicyApi().list();
+
+ assertNotNull(policies);
+ Assert.assertTrue(policies.size() > 0);
+ }
+
+ @Test
+ public void testListWithOption() {
+ GenericQueryOptions options = new GenericQueryOptions();
+ options.options(0, 0, null, "jclouds", null);
+ List<MonitoringPolicy> resultWithQuery = monitoringPolicyApi().list(options);
+
+ assertNotNull(resultWithQuery);
+ Assert.assertTrue(resultWithQuery.size() > 0);
+ }
+
+ @Test
+ public void testGet() {
+ MonitoringPolicy result = monitoringPolicyApi().get(currentPolicy.id());
+
+ assertNotNull(result);
+ assertEquals(result.id(), currentPolicy.id());
+ }
+
+ @Test(dependsOnMethods = "testGet")
+ public void testUpdate() throws InterruptedException {
+ String updatedName = "updatejclouds PN";
+ MonitoringPolicy.Threshold.Cpu.Warning warning = MonitoringPolicy.Threshold.Cpu.Warning.create(91, true);
+ MonitoringPolicy.Threshold.Cpu.Critical critical = MonitoringPolicy.Threshold.Cpu.Critical.create(96, true);
+ MonitoringPolicy.Threshold.Cpu cpu = MonitoringPolicy.Threshold.Cpu.create(warning, critical);
+
+ MonitoringPolicy.Threshold.Ram.Warning ramWarning = MonitoringPolicy.Threshold.Ram.Warning.create(91, true);
+ MonitoringPolicy.Threshold.Ram.Critical ramCritical = MonitoringPolicy.Threshold.Ram.Critical.create(96, true);
+ MonitoringPolicy.Threshold.Ram ram = MonitoringPolicy.Threshold.Ram.create(ramWarning, ramCritical);
+
+ MonitoringPolicy.Threshold.Disk.Warning diskWarning = MonitoringPolicy.Threshold.Disk.Warning.create(90, true);
+ MonitoringPolicy.Threshold.Disk.Critical diskCritical = MonitoringPolicy.Threshold.Disk.Critical.create(95, true);
+ MonitoringPolicy.Threshold.Disk disk = MonitoringPolicy.Threshold.Disk.create(diskWarning, diskCritical);
+
+ MonitoringPolicy.Threshold.InternalPing.Warning pingWarning = MonitoringPolicy.Threshold.InternalPing.Warning.create(50, true);
+ MonitoringPolicy.Threshold.InternalPing.Critical pingCritical = MonitoringPolicy.Threshold.InternalPing.Critical.create(100, true);
+ MonitoringPolicy.Threshold.InternalPing ping = MonitoringPolicy.Threshold.InternalPing.create(pingWarning, pingCritical);
+
+ MonitoringPolicy.Threshold.Transfer.Warning tranWarning = MonitoringPolicy.Threshold.Transfer.Warning.create(1100, true);
+ MonitoringPolicy.Threshold.Transfer.Critical tranCritical = MonitoringPolicy.Threshold.Transfer.Critical.create(2100, true);
+ MonitoringPolicy.Threshold.Transfer transfer = MonitoringPolicy.Threshold.Transfer.create(tranWarning, tranCritical);
+
+ MonitoringPolicy.Threshold threshold = MonitoringPolicy.Threshold.create(cpu, ram, disk, transfer, ping);
+ MonitoringPolicy.UpdatePolicy payload = MonitoringPolicy.UpdatePolicy.builder()
+ .name(updatedName)
+ .agent(true)
+ .email("j@jtestclouds.com")
+ .description("dsec")
+ .thresholds(threshold)
+ .build();
+
+ MonitoringPolicy updateResult = monitoringPolicyApi().update(currentPolicy.id(), payload);
+
+ assertNotNull(updateResult);
+ assertEquals(updateResult.name(), updatedName);
+
+ }
+
+ @Test(dependsOnMethods = "testUpdate")
+ public void testAddPort() throws InterruptedException {
+ List<MonitoringPolicy.Port.AddPort> ports = new ArrayList<MonitoringPolicy.Port.AddPort>();
+ MonitoringPolicy.Port.AddPort port = MonitoringPolicy.Port.AddPort.create(80, Types.AlertIfType.RESPONDING, true, Types.ProtocolType.TCP);
+ ports.add(port);
+ MonitoringPolicy response = monitoringPolicyApi().addPort(currentPolicy.id(), MonitoringPolicy.Port.CreatePort.create(ports));
+
+ assertNotNull(response);
+ assertNotNull(response.ports().get(0));
+ currentPort = response.ports().get(0);
+ }
+
+ @Test(dependsOnMethods = "testAddPort")
+ public void testListPorts() throws InterruptedException {
+ List<MonitoringPolicy.Port> result = monitoringPolicyApi().listPorts(currentPolicy.id());
+
+ assertNotNull(result);
+ assertEquals(result.size(), 1);
+ }
+
+ @Test(dependsOnMethods = "testUpdatePort")
+ public void testGetPort() throws InterruptedException {
+ MonitoringPolicy.Port result = monitoringPolicyApi().getPort(currentPolicy.id(), currentPort.id());
+ assertNotNull(result);
+ }
+
+ @Test(dependsOnMethods = "testListPorts")
+ public void testUpdatePort() throws InterruptedException {
+
+ MonitoringPolicy.Port.AddPort port = MonitoringPolicy.Port.AddPort.create(80, Types.AlertIfType.RESPONDING, true, Types.ProtocolType.TCP);
+
+ MonitoringPolicy response = monitoringPolicyApi().updatePort(currentPolicy.id(), currentPort.id(), MonitoringPolicy.Port.UpdatePort.create(port));
+ assertNotNull(response);
+ }
+
+ @Test(dependsOnMethods = "testGetPort")
+ public void testDeletePort() throws InterruptedException {
+ MonitoringPolicy response = monitoringPolicyApi().deletePort(currentPolicy.id(), currentPort.id());
+
+ assertNotNull(response);
+ }
+
+ @Test(dependsOnMethods = "testDeletePort")
+ public void testAddProcess() throws InterruptedException {
+ List<MonitoringPolicy.Process.AddProcess> processes = new ArrayList<MonitoringPolicy.Process.AddProcess>();
+ MonitoringPolicy.Process.AddProcess process = MonitoringPolicy.Process.AddProcess.create("process", Types.AlertIfType.RESPONDING, true);
+ processes.add(process);
+ MonitoringPolicy response = monitoringPolicyApi().addProcess(currentPolicy.id(), MonitoringPolicy.Process.CreateProcess.create(processes));
+ currentProcess = response.processes().get(0);
+
+ assertNotNull(response);
+ }
+
+ @Test(dependsOnMethods = "testAddProcess")
+ public void testListProcesses() throws InterruptedException {
+ List<MonitoringPolicy.Process> result = monitoringPolicyApi().listProcesses(currentPolicy.id());
+
+ assertNotNull(result);
+ assertEquals(result.size(), 2);
+ }
+
+ @Test(dependsOnMethods = "testUpdateProcess")
+ public void testGetProcess() throws InterruptedException {
+ MonitoringPolicy.Process result = monitoringPolicyApi().getProcess(currentPolicy.id(), currentProcess.id());
+ assertNotNull(result);
+ }
+
+ @Test(dependsOnMethods = "testListProcesses")
+ public void testUpdateProcess() throws InterruptedException {
+
+ MonitoringPolicy.Process.AddProcess process = MonitoringPolicy.Process.AddProcess.create("process", Types.AlertIfType.RESPONDING, true);
+ MonitoringPolicy response = monitoringPolicyApi().updateProcess(currentPolicy.id(), currentProcess.id(), MonitoringPolicy.Process.UpdateProcess.create(process));
+ assertNotNull(response);
+ }
+
+ @Test(dependsOnMethods = "testGetProcess")
+ public void testDeleteProcess() throws InterruptedException {
+ MonitoringPolicy response = monitoringPolicyApi().deleteProcess(currentPolicy.id(), currentProcess.id());
+
+ assertNotNull(response);
+ }
+
+ @Test(dependsOnMethods = "testAttachServer")
+ public void testListServers() throws InterruptedException {
+ List<MonitoringPolicy.Server> servers = monitoringPolicyApi().listServers(currentPolicy.id());
+
+ assertNotNull(servers);
+ Assert.assertTrue(servers.size() > 0);
+ }
+
+ @Test(dependsOnMethods = "testListServers")
+ public void testGetServer() throws InterruptedException {
+ MonitoringPolicy.Server result = monitoringPolicyApi().getServer(currentPolicy.id(), currentServer.id());
+
+ assertNotNull(result);
+ }
+
+ @Test(dependsOnMethods = "testDeleteProcess")
+ public void testAttachServer() throws InterruptedException {
+ List<String> servers = new ArrayList<String>();
+ servers.add(currentServer.id());
+
+ MonitoringPolicy response = monitoringPolicyApi().attachServer(currentPolicy.id(), MonitoringPolicy.Server.CreateServer.create(servers));
+ assertNotNull(response);
+ }
+
+ @Test(dependsOnMethods = "testGetServer")
+ public void testDetachServer() throws InterruptedException {
+ MonitoringPolicy response = monitoringPolicyApi().detachServer(currentPolicy.id(), currentServer.id());
+
+ assertNotNull(response);
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void teardownTest() throws InterruptedException {
+ if (currentServer != null) {
+ assertNodeAvailable(currentServer);
+ deleteServer(currentServer.id());
+ }
+ if (currentPolicy != null) {
+ monitoringPolicyApi().delete(currentPolicy.id());
+ }
+ }
+
+}