http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java deleted file mode 100644 index 7d78ba5..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/ConversionMonitor.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor; - -import java.util.concurrent.TimeUnit; - -import org.jclouds.abiquo.domain.cloud.Conversion; -import org.jclouds.abiquo.features.services.MonitoringService; -import org.jclouds.abiquo.monitor.internal.BaseConversionMonitor; - -import com.google.inject.ImplementedBy; - -/** - * {@link Conversion} monitoring features. - */ -@ImplementedBy(BaseConversionMonitor.class) -public interface ConversionMonitor extends MonitoringService { - /** - * Monitor the given {@link Conversion}s and block until they finishes. - * - * @param conversions - * The {@link Conversion}s to monitor. - */ - void awaitCompletion(final Conversion... conversions); - - /** - * Monitor the given {@link Conversion}s and populate an event when they - * finish. - * - * @param conversions - * The {@link Conversion}s to monitor. - */ - void monitor(final Conversion... conversions); - - /** - * Monitor the given {@link Conversion}s and block until they finish. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param conversions - * The {@link Conversion}s to monitor. - */ - void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, final Conversion... conversions); - - /** - * Monitor the given {@link Conversion}s and populate an event when they - * finish. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param conversions - * The {@link Conversion}s to monitor. - */ - void monitor(final Long maxWait, final TimeUnit timeUnit, final Conversion... conversions); -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java deleted file mode 100644 index 1ff4d10..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/MonitorStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor; - -/** - * Represents the states of a running monitor. - */ -public enum MonitorStatus { - /** The monitoring job has finished. */ - DONE, - - /** The monitoring job has finished and the result is not the expected one. */ - FAILED, - - /** The monitoring job must continue. */ - CONTINUE -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java deleted file mode 100644 index 13b9cc9..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualApplianceMonitor.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor; - -import java.util.concurrent.TimeUnit; - -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.features.services.MonitoringService; -import org.jclouds.abiquo.monitor.internal.BaseVirtualApplianceMonitor; - -import com.google.inject.ImplementedBy; - -/** - * {@link VirtualAppliance} monitoring features. - */ -@ImplementedBy(BaseVirtualApplianceMonitor.class) -public interface VirtualApplianceMonitor extends MonitoringService { - /** - * Monitor the given {@link VirtualAppliance}s and block until the deploy - * finishes. - * - * @param vapp - * The {@link VirtualAppliance}s to monitor. - */ - void awaitCompletionDeploy(final VirtualAppliance... vapp); - - /** - * Monitor the given {@link VirtualAppliance}s and populate an event when the - * deploy finishes. - * - * @param VirtualAppliance - * The {@link VirtualAppliance}s to monitor. - */ - void monitorDeploy(final VirtualAppliance... vapps); - - /** - * Monitor the given {@link VirtualAppliance}s and block until the deploy - * finishes. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vapp - * The {@link VirtualAppliance}s to monitor. - */ - void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapp); - - /** - * Monitor the given {@link VirtualAppliance}s and populate an event when - * deploy finishes. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vapps - * The {@link VirtualAppliance}s to monitor. - */ - void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapps); - - /** - * Monitor the given {@link VirtualAppliance}s and block until the undeploy - * finishes. - * - * @param vapp - * The {@link VirtualAppliance}s to monitor. - */ - void awaitCompletionUndeploy(final VirtualAppliance... vapp); - - /** - * Monitor the given {@link VirtualAppliance}s and call populate an event - * when undeploy finishes. - * - * @param vapps - * The {@link VirtualAppliance}s to monitor. - */ - void monitorUndeploy(final VirtualAppliance... vapps); - - /** - * Monitor the given {@link VirtualAppliance}s and blocks until the undeploy - * finishes. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vapp - * The {@link VirtualAppliance}s to monitor. - */ - void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapp); - - /** - * Monitor the given {@link VirtualAppliance}s and populate an event when - * undeploy finishes. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param callback - * The callback. - * @param vapps - * The {@link VirtualAppliance}s to monitor. - */ - void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapps); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java deleted file mode 100644 index c4cc034..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/VirtualMachineMonitor.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor; - -import java.util.concurrent.TimeUnit; - -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.features.services.MonitoringService; -import org.jclouds.abiquo.monitor.internal.BaseVirtualMachineMonitor; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.inject.ImplementedBy; - -/** - * {@link VirtualMachine} monitoring features. - */ -@ImplementedBy(BaseVirtualMachineMonitor.class) -public interface VirtualMachineMonitor extends MonitoringService { - /** - * Monitor the given {@link VirtualMachine}s and block until all deploys - * finish. - * - * @param vm - * The {@link VirtualMachine}s to monitor. - */ - void awaitCompletionDeploy(final VirtualMachine... vm); - - /** - * Monitor the given {@link VirtualMachine}s and populate an event when all - * deploys finish. - * - * @param vms - * The {@link VirtualMachine}s to monitor. - */ - void monitorDeploy(final VirtualMachine... vms); - - /** - * Monitor the given {@link VirtualMachine}s and block until all deploys - * finish. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vm - * The {@link VirtualMachine}s to monitor. - */ - void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vm); - - /** - * Monitor the given {@link VirtualMachine}s and populate an event when all - * deploys finish. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vms - * The {@link VirtualMachine}s to monitor. - */ - void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vms); - - /** - * Monitor the given {@link VirtualMachine}s and block until all undeploys - * finish. - * - * @param vm - * The {@link VirtualMachine}s to monitor. - */ - void awaitCompletionUndeploy(final VirtualMachine... vm); - - /** - * Monitor the given {@link VirtualMachine}s and populate an event when all - * undeploys finish. - * - * @param vms - * The {@link VirtualMachine}s to monitor. - */ - void monitorUndeploy(final VirtualMachine... vms); - - /** - * Monitor the given {@link VirtualMachine}s and blocks until all undeploys - * finish. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vm - * The {@link VirtualMachine}s to monitor. - */ - void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vm); - - /** - * Monitor the given {@link VirtualMachine}s and populate an event when all - * undeploys finish. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param callback - * The callback. - * @param vms - * The {@link VirtualMachine}s to monitor. - */ - void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vms); - - /** - * Monitor the given {@link VirtualMachine}s and block until it is in the - * given state. - * - * @param vm - * The {@link VirtualMachine}s to monitor. - */ - void awaitState(VirtualMachineState state, final VirtualMachine... vm); - - /** - * Monitor the given {@link VirtualMachine}s and populate an event when it is - * in the given state. - * - * @param vms - * The {@link VirtualMachine}s to monitor. - */ - void monitorState(VirtualMachineState state, final VirtualMachine... vms); - - /** - * Monitor the given {@link VirtualMachine}s and block until it is in the - * given state. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param vm - * The {@link VirtualMachine}s to monitor. - */ - void awaitState(final Long maxWait, final TimeUnit timeUnit, VirtualMachineState state, final VirtualMachine... vm); - - /** - * Monitor the given {@link VirtualMachine}s and populate an event when it is - * in the given state. - * - * @param maxWait - * The maximum time to wait. - * @param timeUnit - * The time unit for the maxWait parameter. - * @param callback - * The callback. - * @param vms - * The {@link VirtualMachine}s to monitor. - */ - void monitorState(final Long maxWait, final TimeUnit timeUnit, VirtualMachineState state, - final VirtualMachine... vms); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java deleted file mode 100644 index 18ab9b3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/CompletedEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.events; - -/** - * Event dispatched when a monitoring job completes without error. - */ -public class CompletedEvent<T> extends MonitorEvent<T> { - public CompletedEvent(final T target) { - super(MonitorEvent.Type.COMPLETED, target); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java deleted file mode 100644 index 5d35b1c..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/FailedEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.events; - -/** - * Event dispatched when a monitoring job completes with errors. - */ -public class FailedEvent<T> extends MonitorEvent<T> { - public FailedEvent(final T target) { - super(MonitorEvent.Type.FAILED, target); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java deleted file mode 100644 index 5b3f0c3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/MonitorEvent.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.events; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * base class for all monitor events. - */ -public class MonitorEvent<T> { - /** - * The type of the event. - */ - public static enum Type { - COMPLETED, FAILED, TIMEOUT; - } - - /** The type of the event. */ - private Type type; - - /** The target object being monitored. */ - private T target; - - public MonitorEvent(final Type type, final T target) { - super(); - this.type = checkNotNull(type, "type"); - this.target = checkNotNull(target, "target"); - } - - public Type getType() { - return type; - } - - public void setType(final Type type) { - this.type = type; - } - - public T getTarget() { - return target; - } - - public void setTarget(final T target) { - this.target = target; - } - - @Override - public String toString() { - return "MonitorEvent [type=" + type + ", target=" + target + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java deleted file mode 100644 index 03aecae..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/events/TimeoutEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.events; - -/** - * Event dispatched when a monitoring job times out. - */ -public class TimeoutEvent<T> extends MonitorEvent<T> { - public TimeoutEvent(final T target) { - super(MonitorEvent.Type.TIMEOUT, target); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java deleted file mode 100644 index c8544fa..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/AsyncTaskStatusMonitor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.task.AsyncTask; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; - -/** - * This class takes care of monitoring {@link AsyncTask} jobs. - */ -@Singleton -public class AsyncTaskStatusMonitor implements Function<AsyncTask<?, ?>, MonitorStatus> { - @Resource - protected Logger logger = Logger.NULL; - - @Override - public MonitorStatus apply(final AsyncTask<?, ?> asyncTask) { - checkNotNull(asyncTask, "asyncTask"); - - try { - asyncTask.refresh(); - - switch (asyncTask.getState()) { - case ABORTED: - case FINISHED_UNSUCCESSFULLY: - return MonitorStatus.FAILED; - case FINISHED_SUCCESSFULLY: - return MonitorStatus.DONE; - case STARTED: - case PENDING: - return MonitorStatus.CONTINUE; - default: - throw new IllegalStateException("Unsupported task status"); - } - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", asyncTask, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java deleted file mode 100644 index 711b812..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/ConversionStatusMonitor.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.Conversion; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; - -/** - * This class takes care of monitoring {@link Conversion} jobs. - */ -@Singleton -public class ConversionStatusMonitor implements Function<Conversion, MonitorStatus> { - @Resource - protected Logger logger = Logger.NULL; - - @Override - public MonitorStatus apply(final Conversion conversion) { - checkNotNull(conversion, "conversion"); - - try { - conversion.refresh(); - - switch (conversion.getState()) { - case ENQUEUED: - return MonitorStatus.CONTINUE; - case FAILED: - return MonitorStatus.FAILED; - case FINISHED: - return MonitorStatus.DONE; - default: - throw new IllegalStateException("Unsupported conversion status"); - } - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", conversion, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java deleted file mode 100644 index 4bc5507..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceDeployMonitor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; - -import com.abiquo.server.core.cloud.VirtualApplianceState; -import com.google.common.base.Function; - -/** - * This class takes care of monitoring the a deploy of a - * {@link VirtualAppliance}. - */ -@Singleton -public class VirtualApplianceDeployMonitor implements Function<VirtualAppliance, MonitorStatus> { - @Resource - protected Logger logger = Logger.NULL; - - @Override - public MonitorStatus apply(final VirtualAppliance virtualAppliance) { - checkNotNull(virtualAppliance, "virtualAppliance"); - - try { - VirtualApplianceState state = virtualAppliance.getState(); - - switch (state) { - case UNKNOWN: - case NEEDS_SYNC: - case NOT_DEPLOYED: - return MonitorStatus.FAILED; - case DEPLOYED: - return MonitorStatus.DONE; - case LOCKED: - default: - return MonitorStatus.CONTINUE; - } - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", virtualAppliance, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java deleted file mode 100644 index 124fbf8..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualApplianceUndeployMonitor.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ResourceNotFoundException; - -import com.abiquo.server.core.cloud.VirtualApplianceState; -import com.google.common.base.Function; - -/** - * This class takes care of monitoring the a undeploy of a - * {@link VirtualAppliance}. - */ -@Singleton -public class VirtualApplianceUndeployMonitor implements Function<VirtualAppliance, MonitorStatus> { - @Resource - protected Logger logger = Logger.NULL; - - @Override - public MonitorStatus apply(final VirtualAppliance virtualAppliance) { - checkNotNull(virtualAppliance, "virtualAppliance"); - - try { - VirtualApplianceState state = virtualAppliance.getState(); - - switch (state) { - case DEPLOYED: - case UNKNOWN: - case NEEDS_SYNC: - return MonitorStatus.FAILED; - case NOT_DEPLOYED: - return MonitorStatus.DONE; - case LOCKED: - default: - return MonitorStatus.CONTINUE; - } - } catch (ResourceNotFoundException nfe) { - logger.warn("virtual appliance %s not found, assuming it was undeployed successfully, " - + "stop monitor with DONE", virtualAppliance); - return MonitorStatus.DONE; - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", virtualAppliance, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java deleted file mode 100644 index 17a63d8..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineDeployMonitor.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; - -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.base.Function; -import com.google.inject.Singleton; - -/** - * This class takes care of monitoring the a deploy of a {@link VirtualMachine}. - * - * @see MonitoringService - */ -@Singleton -public class VirtualMachineDeployMonitor implements Function<VirtualMachine, MonitorStatus> { - @Resource - private Logger logger = Logger.NULL; - - @Override - public MonitorStatus apply(final VirtualMachine virtualMachine) { - checkNotNull(virtualMachine, "virtualMachine"); - - try { - VirtualMachineState state = virtualMachine.getState(); - - switch (state) { - case NOT_ALLOCATED: - case UNKNOWN: - return MonitorStatus.FAILED; - case ON: - return MonitorStatus.DONE; - default: - return MonitorStatus.CONTINUE; - } - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", virtualMachine, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java deleted file mode 100644 index 759be2e..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineStateMonitor.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; - -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.base.Function; - -/** - * This class takes care of monitoring the state of a {@link VirtualMachine}. - * - * @see MonitoringService - */ -public class VirtualMachineStateMonitor implements Function<VirtualMachine, MonitorStatus> { - @Resource - private Logger logger = Logger.NULL; - - private VirtualMachineState expectedState; - - public VirtualMachineStateMonitor(final VirtualMachineState expectedState) { - super(); - this.expectedState = checkNotNull(expectedState, "expectedState"); - } - - @Override - public MonitorStatus apply(final VirtualMachine virtualMachine) { - checkNotNull(virtualMachine, "virtualMachine"); - - try { - VirtualMachineState state = virtualMachine.getState(); - return state == expectedState ? MonitorStatus.DONE : MonitorStatus.CONTINUE; - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", virtualMachine, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java deleted file mode 100644 index 82cfdc8..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/functions/VirtualMachineUndeployMonitor.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; -import javax.inject.Singleton; - -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.monitor.MonitorStatus; -import org.jclouds.logging.Logger; -import org.jclouds.rest.ResourceNotFoundException; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.base.Function; - -/** - * This class takes care of monitoring the a undeploy of a - * {@link VirtualMachine}. - */ -@Singleton -public class VirtualMachineUndeployMonitor implements Function<VirtualMachine, MonitorStatus> { - @Resource - protected Logger logger = Logger.NULL; - - @Override - public MonitorStatus apply(final VirtualMachine virtualMachine) { - checkNotNull(virtualMachine, "virtualMachine"); - - try { - VirtualMachineState state = virtualMachine.getState(); - - // This state may be reached if the undeploy process fails and a - // rollback is done - if (state.existsInHypervisor()) { - return MonitorStatus.FAILED; - } - - switch (state) { - case UNKNOWN: - return MonitorStatus.FAILED; - case NOT_ALLOCATED: - return MonitorStatus.DONE; - default: - return MonitorStatus.CONTINUE; - } - } catch (ResourceNotFoundException nfe) { - logger.warn("virtual machine %s not found, assuming it was undeployed successfully, " - + "stop monitor with DONE", virtualMachine); - return MonitorStatus.DONE; - } catch (Exception ex) { - logger.warn(ex, "exception thrown while monitoring %s on %s, returning CONTINUE", virtualMachine, getClass() - .getName()); - - return MonitorStatus.CONTINUE; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java deleted file mode 100644 index 7f85bc2..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/AbstractEventHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.handlers; - -import javax.annotation.Resource; - -import org.jclouds.abiquo.monitor.events.MonitorEvent; -import org.jclouds.logging.Logger; - -/** - * Base class for all {@link MonitorEvent} handlers. - */ -public abstract class AbstractEventHandler<T> { - @Resource - protected Logger logger = Logger.NULL; - - /** - * Checks if the current handler must handle the dispatched event. - * - * @param event - * The event being dispatched. - * @return Boolean indicating if the event must be handled by the current - * handler. - */ - protected abstract boolean handles(MonitorEvent<T> event); - - // Public getters and setters to allow non-guice code to set the appropriate - // logger - - public Logger getLogger() { - return logger; - } - - public void setLogger(final Logger logger) { - this.logger = logger; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java deleted file mode 100644 index 7ba2e69..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/handlers/BlockingEventHandler.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.handlers; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import org.jclouds.abiquo.monitor.events.MonitorEvent; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Throwables; -import com.google.common.collect.Lists; -import com.google.common.eventbus.Subscribe; - -/** - * An event handler that blocks the thread until all monitored objects have been - * finished being watched. - * <p> - * Due to <a - * href="http://code.google.com/p/guava-libraries/issues/detail?id=783">Guava - * Issue 786</a> {@link #handle(MonitorEvent)} is marked <code>final</code>to - * avoid having duplicate events. - * - * @param <T> - * The monitored object. - */ -public class BlockingEventHandler<T> extends AbstractEventHandler<T> { - /** The signal used to lock the thread. */ - @VisibleForTesting - CountDownLatch completeSignal; - - /** - * The objects being locked. - * <p> - * This class handles events in a thread safe way. Otherwise this collections - * should be synchronised. - */ - protected List<T> lockedObjects; - - public BlockingEventHandler(final T... lockedObjects) { - this(Logger.NULL, lockedObjects); - } - - public BlockingEventHandler(final Logger logger, final T... lockedObjects) { - super(); - checkArgument(checkNotNull(lockedObjects, "lockedObjects").length > 0, "must provide at least one object"); - this.logger = checkNotNull(logger, "logger"); - this.lockedObjects = Lists.newArrayList(lockedObjects); - this.logger.debug("created BlockingEventHandler locking %s objects", lockedObjects.length); - } - - @Override - protected boolean handles(final MonitorEvent<T> event) { - logger.debug("checking if %s event on %s must be handled by %s", event.getType(), event.getTarget(), this); - boolean handles = lockedObjects.contains(event.getTarget()); - logger.debug("%s event on %s must %sbe handled", event.getType(), event.getTarget(), handles ? "" : "not "); - return handles; - } - - /** - * Handles the dispatched event in a thread safe way. - * <p> - * Due to <a - * href="http://code.google.com/p/guava-libraries/issues/detail?id=783">Guava - * Issue 786</a> {@link #handle(MonitorEvent)} is marked <code>final</code>to - * avoid having duplicate events. - * - * @see {@link #doBeforeRelease(MonitorEvent)} - */ - @Subscribe - public final void handle(final MonitorEvent<T> event) { - if (handles(event)) { - logger.debug("handling %s", event); - - try { - doBeforeRelease(event); - } finally { - // Always release the lock, even if the handler code fails - release(event.getTarget()); - } - } - } - - /** - * Blocks the thread until all locked objects have been released. - */ - public void lock() { - // When invoking the lock, it is possible that all events have - // already been consumed. If there are no objects to monitor, - // just ignore the lock. - if (!lockedObjects.isEmpty()) { - try { - completeSignal = new CountDownLatch(lockedObjects.size()); - logger.debug("creating lock for %s object(s)", lockedObjects.size()); - completeSignal.await(); - } catch (InterruptedException ex) { - throw Throwables.propagate(ex); - } - } else { - logger.debug("there is nothing to watch. Ignoring lock."); - } - } - - /** - * Releases the lock on the given object. - */ - protected void release(final T target) { - logger.debug("releasing %s", target); - lockedObjects.remove(target); - - // The completeSignal might be null if the events have been consumed - // before acquiring the lock - if (completeSignal != null) { - completeSignal.countDown(); - logger.debug("releasing lock for %s. %s remaining objects", target, completeSignal.getCount()); - } - } - - /** - * Convenience method to bypass the <a - * href="http://code.google.com/p/guava-libraries/issues/detail?id=783">Guava - * Issue 786</a> that forces the subscriber method to be <code>final</code>. - */ - protected void doBeforeRelease(final MonitorEvent<T> event) { - // Let subclasses may override it to customize behavior - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java deleted file mode 100644 index edbebb6..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseAsyncTaskMonitor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.task.AsyncTask; -import org.jclouds.abiquo.internal.BaseMonitoringService; -import org.jclouds.abiquo.monitor.AsyncTaskMonitor; -import org.jclouds.abiquo.monitor.functions.AsyncTaskStatusMonitor; -import org.jclouds.rest.ApiContext; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.eventbus.EventBus; - -/** - * Default monitor for {@link AsyncTask} objects. - */ -@Singleton -public class BaseAsyncTaskMonitor extends BaseMonitoringService implements AsyncTaskMonitor { - - @VisibleForTesting - protected AsyncTaskStatusMonitor taskMonitor; - - @Inject - public BaseAsyncTaskMonitor(final ApiContext<AbiquoApi> context, - @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, - @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, - final AsyncTaskStatusMonitor monitor) { - super(context, scheduler, pollingDelay, eventBus); - this.taskMonitor = checkNotNull(monitor, "monitor"); - } - - @Override - public void awaitCompletion(final AsyncTask<?, ?>... tasks) { - awaitCompletion(taskMonitor, tasks); - } - - @Override - public void monitor(final AsyncTask<?, ?>... tasks) { - monitor(taskMonitor, tasks); - } - - @Override - public void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, final AsyncTask<?, ?>... tasks) { - awaitCompletion(maxWait, timeUnit, taskMonitor, tasks); - } - - @Override - public void monitor(final Long maxWait, final TimeUnit timeUnit, final AsyncTask<?, ?>... tasks) { - monitor(maxWait, timeUnit, taskMonitor, tasks); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java deleted file mode 100644 index 98457dc..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseConversionMonitor.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.Conversion; -import org.jclouds.abiquo.internal.BaseMonitoringService; -import org.jclouds.abiquo.monitor.ConversionMonitor; -import org.jclouds.abiquo.monitor.functions.ConversionStatusMonitor; -import org.jclouds.rest.ApiContext; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.eventbus.EventBus; - -/** - * Default monitor for {@link Conversion} objects. - */ -@Singleton -public class BaseConversionMonitor extends BaseMonitoringService implements ConversionMonitor { - - @VisibleForTesting - protected ConversionStatusMonitor conversionMonitor; - - @Inject - public BaseConversionMonitor(final ApiContext<AbiquoApi> context, - @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, - @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, - final ConversionStatusMonitor monitor) { - super(context, scheduler, pollingDelay, eventBus); - this.conversionMonitor = checkNotNull(monitor, "monitor"); - } - - @Override - public void awaitCompletion(final Conversion... conversions) { - awaitCompletion(conversionMonitor, conversions); - } - - @Override - public void monitor(final Conversion... conversions) { - monitor(conversionMonitor, conversions); - } - - @Override - public void awaitCompletion(final Long maxWait, final TimeUnit timeUnit, final Conversion... conversions) { - awaitCompletion(maxWait, timeUnit, conversionMonitor, conversions); - } - - @Override - public void monitor(final Long maxWait, final TimeUnit timeUnit, final Conversion... conversions) { - monitor(maxWait, timeUnit, conversionMonitor, conversions); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java deleted file mode 100644 index 16ce43f..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualApplianceMonitor.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.internal.BaseMonitoringService; -import org.jclouds.abiquo.monitor.VirtualApplianceMonitor; -import org.jclouds.abiquo.monitor.functions.VirtualApplianceDeployMonitor; -import org.jclouds.abiquo.monitor.functions.VirtualApplianceUndeployMonitor; -import org.jclouds.rest.ApiContext; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.eventbus.EventBus; - -/** - * Default monitor for {@link VirtualAppliance} objects. - */ -@Singleton -public class BaseVirtualApplianceMonitor extends BaseMonitoringService implements VirtualApplianceMonitor { - @VisibleForTesting - protected VirtualApplianceDeployMonitor deployMonitor; - - @VisibleForTesting - protected VirtualApplianceUndeployMonitor undeployMonitor; - - @Inject - public BaseVirtualApplianceMonitor(final ApiContext<AbiquoApi> context, - @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, - @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, - final VirtualApplianceDeployMonitor deployMonitor, final VirtualApplianceUndeployMonitor undeployMonitor) { - super(context, scheduler, pollingDelay, eventBus); - this.deployMonitor = checkNotNull(deployMonitor, "deployMonitor"); - this.undeployMonitor = checkNotNull(undeployMonitor, "undeployMonitor"); - } - - @Override - public void awaitCompletionDeploy(final VirtualAppliance... vapps) { - awaitCompletion(deployMonitor, vapps); - } - - @Override - public void monitorDeploy(final VirtualAppliance... vapps) { - monitor(deployMonitor, vapps); - } - - @Override - public void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapps) { - awaitCompletion(maxWait, timeUnit, deployMonitor, vapps); - } - - @Override - public void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapps) { - monitor(maxWait, timeUnit, deployMonitor, vapps); - } - - @Override - public void awaitCompletionUndeploy(final VirtualAppliance... vapps) { - awaitCompletion(undeployMonitor, vapps); - } - - @Override - public void monitorUndeploy(final VirtualAppliance... vapps) { - monitor(undeployMonitor, vapps); - } - - @Override - public void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapps) { - awaitCompletion(maxWait, timeUnit, undeployMonitor, vapps); - } - - @Override - public void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualAppliance... vapps) { - monitor(maxWait, timeUnit, undeployMonitor, vapps); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java b/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java deleted file mode 100644 index 1fdb111..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/monitor/internal/BaseVirtualMachineMonitor.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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.jclouds.abiquo.monitor.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.Constants.PROPERTY_SCHEDULER_THREADS; -import static org.jclouds.abiquo.config.AbiquoProperties.ASYNC_TASK_MONITOR_DELAY; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.internal.BaseMonitoringService; -import org.jclouds.abiquo.monitor.VirtualMachineMonitor; -import org.jclouds.abiquo.monitor.functions.VirtualMachineDeployMonitor; -import org.jclouds.abiquo.monitor.functions.VirtualMachineStateMonitor; -import org.jclouds.abiquo.monitor.functions.VirtualMachineUndeployMonitor; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.eventbus.EventBus; - -/** - * Default monitor for {@link VirtualMachine} objects. - */ -@Singleton -public class BaseVirtualMachineMonitor extends BaseMonitoringService implements VirtualMachineMonitor { - @VisibleForTesting - protected VirtualMachineDeployMonitor deployMonitor; - - @VisibleForTesting - protected VirtualMachineUndeployMonitor undeployMonitor; - - @Inject - public BaseVirtualMachineMonitor(final ApiContext<AbiquoApi> context, - @Named(PROPERTY_SCHEDULER_THREADS) final ScheduledExecutorService scheduler, - @Named(ASYNC_TASK_MONITOR_DELAY) final Long pollingDelay, final EventBus eventBus, - final VirtualMachineDeployMonitor deployMonitor, final VirtualMachineUndeployMonitor undeployMonitor) { - super(context, scheduler, pollingDelay, eventBus); - this.deployMonitor = checkNotNull(deployMonitor, "deployMonitor"); - this.undeployMonitor = checkNotNull(undeployMonitor, "undeployMonitor"); - } - - @Override - public void awaitCompletionDeploy(final VirtualMachine... vms) { - awaitCompletion(deployMonitor, vms); - } - - @Override - public void monitorDeploy(final VirtualMachine... vms) { - monitor(deployMonitor, vms); - } - - @Override - public void awaitCompletionDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vms) { - awaitCompletion(maxWait, timeUnit, deployMonitor, vms); - } - - @Override - public void monitorDeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vms) { - monitor(maxWait, timeUnit, deployMonitor, vms); - } - - @Override - public void awaitCompletionUndeploy(final VirtualMachine... vms) { - awaitCompletion(undeployMonitor, vms); - } - - @Override - public void monitorUndeploy(final VirtualMachine... vms) { - monitor(undeployMonitor, vms); - } - - @Override - public void awaitCompletionUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vms) { - awaitCompletion(maxWait, timeUnit, undeployMonitor, vms); - } - - @Override - public void monitorUndeploy(final Long maxWait, final TimeUnit timeUnit, final VirtualMachine... vms) { - monitor(maxWait, timeUnit, undeployMonitor, vms); - } - - @Override - public void awaitState(final VirtualMachineState state, final VirtualMachine... vms) { - awaitCompletion(new VirtualMachineStateMonitor(state), vms); - } - - @Override - public void monitorState(final VirtualMachineState state, final VirtualMachine... vms) { - monitor(new VirtualMachineStateMonitor(state), vms); - } - - @Override - public void awaitState(final Long maxWait, final TimeUnit timeUnit, final VirtualMachineState state, - final VirtualMachine... vms) { - awaitCompletion(maxWait, timeUnit, new VirtualMachineStateMonitor(state), vms); - } - - @Override - public void monitorState(final Long maxWait, final TimeUnit timeUnit, final VirtualMachineState state, - final VirtualMachine... vms) { - monitor(maxWait, timeUnit, new VirtualMachineStateMonitor(state), vms); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java deleted file mode 100644 index 2ea3ca7..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/IpPredicates.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.jclouds.abiquo.predicates; - -import org.jclouds.abiquo.domain.network.AbstractPublicIp; -import org.jclouds.abiquo.domain.network.Ip; - -import com.google.common.base.Predicate; - -/** - * Container for {@link Network} filters. - */ -public class IpPredicates { - - public static <T extends AbstractPublicIp<?, ?>> Predicate<T> available() { - return new Predicate<T>() { - @Override - public boolean apply(final T address) { - return address.isAvailable(); - } - }; - } - - public static <T extends Ip<?, ?>> Predicate<T> notUsed() { - return new Predicate<T>() { - @Override - public boolean apply(final T address) { - return address.unwrap().searchLink("virtualmachine") == null; - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java deleted file mode 100644 index c722ed6..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/LinkPredicates.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.jclouds.abiquo.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.regex.Pattern; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.infrastructure.network.NicDto; -import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; -import com.google.common.base.Predicate; - -/** - * Container for {@link RESTLink} filters. - */ -public class LinkPredicates { - - private static final Pattern IS_NIC_REL_PATTERN = Pattern.compile("^" + NicDto.REL_PREFIX + "[0-9]+$"); - private static final Pattern IS_DISK_REL_PATTERN = Pattern.compile("^" + VolumeManagementDto.REL_PREFIX + "[0-9]+$"); - - public static Predicate<RESTLink> rel(final String rel) { - checkNotNull(rel, "rel must be defined"); - return new Predicate<RESTLink>() { - @Override - public boolean apply(final RESTLink link) { - return link.getRel().equals(rel); - } - }; - } - - public static Predicate<RESTLink> isNic() { - return new Predicate<RESTLink>() { - @Override - public boolean apply(final RESTLink link) { - return IS_NIC_REL_PATTERN.matcher(link.getRel()).matches(); - } - }; - } - - public static Predicate<RESTLink> isDisk() { - return new Predicate<RESTLink>() { - @Override - public boolean apply(RESTLink link) { - return IS_DISK_REL_PATTERN.matcher(link.getRel()).matches(); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java deleted file mode 100644 index b7527f3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/NetworkServiceTypePredicates.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.jclouds.abiquo.predicates; - -import org.jclouds.abiquo.domain.network.NetworkServiceType; - -import com.google.common.base.Predicate; - -/** - * Container for {@link NetworkServiceType} filters. - */ -public class NetworkServiceTypePredicates { - public static Predicate<NetworkServiceType> isDefault() { - return new Predicate<NetworkServiceType>() { - @Override - public boolean apply(final NetworkServiceType ni) { - return ni.isDefaultNST(); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java deleted file mode 100644 index 4ad1011..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualDatacenterPredicates.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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.jclouds.abiquo.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.isEmpty; - -import org.jclouds.abiquo.domain.cloud.Conversion; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; - -import com.abiquo.model.enumerator.ConversionState; -import com.abiquo.model.enumerator.HypervisorType; -import com.google.common.base.Predicate; - -/** - * Container for {@link VirtualDatacenter} filters. - */ -public class VirtualDatacenterPredicates { - - public static Predicate<VirtualDatacenter> datacenter(final Datacenter datacenter) { - checkNotNull(datacenter, "datacenter must be defined"); - - return new Predicate<VirtualDatacenter>() { - @Override - public boolean apply(final VirtualDatacenter virtualDatacenter) { - // Avoid using the getDatacenter() method since it will generate an - // unnecessary API - // call. We can get the ID from the datacenter link. - Integer datacenterId = checkNotNull(virtualDatacenter.unwrap().getIdFromLink(ParentLinkName.DATACENTER), - ValidationErrors.MISSING_REQUIRED_LINK); - - return datacenterId.equals(datacenter.getId()); - } - }; - } - - /** - * Check if the given template type is compatible with the given virtual - * datacenter type taking into account the conversions of the template. - * - * @param template - * The template to check. - * @return Predicate to check if the template or its conversions are - * compatibles with the given virtual datacenter. - */ - public static Predicate<VirtualDatacenter> compatibleWithTemplateOrConversions(final VirtualMachineTemplate template) { - return new Predicate<VirtualDatacenter>() { - @Override - public boolean apply(final VirtualDatacenter vdc) { - HypervisorType type = vdc.getHypervisorType(); - boolean compatible = type.isCompatible(template.getDiskFormatType()); - if (!compatible) { - Iterable<Conversion> compatibleConversions = template.listConversions(type, ConversionState.FINISHED); - compatible = compatibleConversions != null && !isEmpty(compatibleConversions); - } - return compatible; - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java b/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java deleted file mode 100644 index 8af9f6f..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/predicates/VirtualMachineTemplatePredicates.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.jclouds.abiquo.predicates; - -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; - -import com.google.common.base.Predicate; - -/** - * Container for {@link VirtualMachineTemplate} filters. - */ -public class VirtualMachineTemplatePredicates { - - public static Predicate<VirtualMachineTemplate> isShared() { - return new Predicate<VirtualMachineTemplate>() { - @Override - public boolean apply(final VirtualMachineTemplate input) { - return input.unwrap().isShared(); - } - }; - } - - public static Predicate<VirtualMachineTemplate> isInstance() { - return new Predicate<VirtualMachineTemplate>() { - @Override - public boolean apply(final VirtualMachineTemplate input) { - return input.unwrap().searchLink("master") != null; - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java b/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java deleted file mode 100644 index 67d7f88..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/reference/ValidationErrors.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.jclouds.abiquo.reference; - -/** - * Error constants. - */ -public class ValidationErrors { - public static final String NULL_RESOURCE = "The resource should be assigned to a "; - - public static final String MISSING_REQUIRED_FIELD = "Missing required field "; - - public static final String MISSING_REQUIRED_LINK = "Missing required link "; - - public static final String INVALID_NETWORK_TYPE = "Invalid network type "; - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java b/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java deleted file mode 100644 index 9fc9b84..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/reference/rest/ParentLinkName.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.jclouds.abiquo.reference.rest; - -/** - * Names of the "rel" attribute of the links that point to parent objects. - */ -public class ParentLinkName { - public static final String RACK = "rack"; - - public static final String DATACENTER = "datacenter"; - - public static final String ENTERPRISE = "enterprise"; - - public static final String ROLE = "role"; - - public static final String TIER = "tier"; - - public static final String STORAGE_DEVICE = "device"; - - public static final String VIRTUAL_DATACENTER = "virtualdatacenter"; - - public static final String VIRTUAL_APPLIANCE = "virtualappliance"; - - public static final String VIRTUAL_MACHINE_TEMPLATE = "virtualmachinetemplate"; - - public static final String DATACENTER_REPOSITORY = "datacenterrepository"; - - public static final String CATEGORY = "category"; - - public static final String ICON = "icon"; - - public static final String PRIVATE_NETWORK = "privatenetwork"; - - public static final String PUBLIC_NETWORK = "publicnetwork"; - - public static final String EXTERNAL_NETWORK = "externalnetwork"; - - public static final String UNMANAGED_NETWORK = "unmanagednetwork"; - - public static final String NETWORK_CONFIGURATIONS = "configurations"; - - public static final String NETWORK_GATEWAY = "network_configuration"; - - public static final String TASK_RESULT = "result"; - - public static final String VIRTUAL_MACHINE = "virtualmachine"; -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java b/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java deleted file mode 100644 index 84d87d4..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/rest/annotations/EndpointLink.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.jclouds.abiquo.rest.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates the link to be used to generate the endpoint for the request. - */ -@Target({ ElementType.PARAMETER }) -@Retention(RetentionPolicy.RUNTIME) -public @interface EndpointLink { - - /** - * The name of the link that will be used to generate the request endpoint. - */ - String value(); -}
