| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.ec2.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.ec2.EC2AsyncClient; |
| 24 | |
| 25 | import com.google.common.base.CaseFormat; |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * The current state of the instance.. |
| 30 | * |
| 31 | * @author Adrian Cole |
| 32 | * @see EC2AsyncClient#describeInstances |
| 33 | * @see EC2AsyncClient#runInstances |
| 34 | * @see EC2AsyncClient#terminateInstances |
| 35 | * |
| 36 | */ |
| 37 | public enum InstanceState { |
| 38 | |
| 39 | /** |
| 40 | * the instance is in the process of being launched |
| 41 | */ |
| 42 | PENDING, |
| 43 | |
| 44 | /** |
| 45 | * the instance launched (although the boot process might not be completed) |
| 46 | */ |
| 47 | RUNNING, |
| 48 | |
| 49 | /** |
| 50 | * the instance started shutting down |
| 51 | */ |
| 52 | SHUTTING_DOWN, |
| 53 | /** |
| 54 | * the instance terminated |
| 55 | */ |
| 56 | TERMINATED, |
| 57 | /** |
| 58 | * the instance is stopping |
| 59 | */ |
| 60 | STOPPING, |
| 61 | /** |
| 62 | * the instance is stopped |
| 63 | */ |
| 64 | STOPPED, UNRECOGNIZED; |
| 65 | |
| 66 | public String value() { |
| 67 | return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name())); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public String toString() { |
| 72 | return value(); |
| 73 | } |
| 74 | |
| 75 | public static InstanceState fromValue(String state) { |
| 76 | try { |
| 77 | return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); |
| 78 | } catch (IllegalArgumentException e) { |
| 79 | return UNRECOGNIZED; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public static InstanceState fromValue(int v) { |
| 84 | switch (v) { |
| 85 | case 0: |
| 86 | return PENDING; |
| 87 | case 16: |
| 88 | return RUNNING; |
| 89 | case 32: |
| 90 | return SHUTTING_DOWN; |
| 91 | case 48: |
| 92 | return TERMINATED; |
| 93 | case 64: |
| 94 | return STOPPING; |
| 95 | case 80: |
| 96 | return STOPPED; |
| 97 | default: |
| 98 | return UNRECOGNIZED; |
| 99 | } |
| 100 | } |
| 101 | } |