|
| 1 | +Java SDK for RunAbove API |
| 2 | +============= |
| 3 | + |
| 4 | + |
| 5 | +This is a Java SDK to use Instances and Object Storage on [RunAbove](https://www.runabove.com). The SDK uses the simple API provided by RunAbove. |
| 6 | + |
| 7 | +Benefits : |
| 8 | + - Auth made easy |
| 9 | + - Embedded api cryptography process |
| 10 | + - All POJO availables |
| 11 | + - All services exposed |
| 12 | + - Create Instances and Containers in one line |
| 13 | + - Play with Openstack Swift through the API or with JOSS Library |
| 14 | + |
| 15 | +The Runabove API Console is available [here](https://manager.runabove.com/console). |
| 16 | + |
| 17 | + |
| 18 | +Quickstart |
| 19 | +---------- |
| 20 | + |
| 21 | +The easiest way to start with the SDK is to install clone it from github and package it : |
| 22 | + |
| 23 | + mvn clean install package |
| 24 | + |
| 25 | +RunAbove SDK can then be included in your java programs. Some examples of |
| 26 | +applications using the SDK are available in the `examples` directory. |
| 27 | + |
| 28 | +Once build, add this dependency to your project : |
| 29 | + |
| 30 | + |
| 31 | + ```xml |
| 32 | +<dependency> |
| 33 | + <groupId>com.runabove</groupId> |
| 34 | + <artifactId>api</artifactId> |
| 35 | + <version>1.0.0</version> |
| 36 | +</dependency> |
| 37 | +``` |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +Authenticate to RunAbove API |
| 42 | +---------------------------- |
| 43 | + |
| 44 | +Each **application** that uses RunAbove API needs to be authenticated. For that |
| 45 | +you have to register your application, it is very easy and can be done at this |
| 46 | +address: https://api.runabove.com/createApp |
| 47 | + |
| 48 | +Then each **user** using your application will be securely authenticated with a |
| 49 | +consumer key. Thanks to this mecanism users don't need to give their plain text |
| 50 | +password to the application. The first time a user will use your application, |
| 51 | +he will be redirected to a web page where he can securely get his **consumer |
| 52 | +key**. |
| 53 | + |
| 54 | + |
| 55 | +How to get a consumer key with the SDK? |
| 56 | +--------------------------------------- |
| 57 | + |
| 58 | +To communicate with the API, each call made by your application must be signed |
| 59 | +and include the consumer key of the user. The signature process is |
| 60 | +automatically handled by the SDK. However if the user don't have a valid |
| 61 | +consumer key yet you can redirect him to RunAbove authentication page. |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +How to manage instances? |
| 66 | +------------------------ |
| 67 | + |
| 68 | +Launching an instance is easy. First get the flavor, image and region where you |
| 69 | +want your instance to be created and call `create()`. To |
| 70 | +delete an instance just call the `instance.delete()` method: |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +```java |
| 75 | + |
| 76 | +// initialize configuration |
| 77 | +RunAboveConfig config = new RunAboveConfig() |
| 78 | + .setErrorHandlder(new SystemOutErrorHandler()) |
| 79 | + .setApplicationKey(applicationKey) |
| 80 | + .setApplicationSecret(applicationSecret); |
| 81 | + |
| 82 | +// request credentials |
| 83 | +AuthManager runAboveAuth = new RunAboveBuilder(getConfig()).createAuthManager(); |
| 84 | +Credential creds = runAboveAuth.credential(new DefaultCredentialParams()); |
| 85 | + |
| 86 | +// snip snip |
| 87 | +// redirect user to authorization page at creds.getValidationUrl() |
| 88 | +// snip snip |
| 89 | + |
| 90 | +// create the manager object that handles all api calls |
| 91 | +RunAboveManager runAbove = new RunAboveBuilder(getConfig()).createManager(creds.getConsumerKey()); |
| 92 | + |
| 93 | +// create an instance detail |
| 94 | +InstanceDetail instanceDetail = new InstanceDetail(); |
| 95 | + |
| 96 | +// get a flavor |
| 97 | +Flavor[] flavors = runAbove.getFlavor(); |
| 98 | +instanceDetail.setFlavor(flavors[0]); |
| 99 | + |
| 100 | +// get a region |
| 101 | +String[] regions = runAbove.getRegions(); |
| 102 | +instanceDetail.setRegion(regions[0]); |
| 103 | + |
| 104 | +// get an image |
| 105 | +Image[] imgs = runAbove.getImages(); |
| 106 | +instanceDetail.setImage(imgs[0]); |
| 107 | + |
| 108 | +// create an instance |
| 109 | +InstanceDetail resultInstance = runAbove.createInstance(instanceDetail); |
| 110 | + |
| 111 | +// list all the instances |
| 112 | +Instance[] listInstances = runAbove.getInstances(); |
| 113 | +for (Instance instance : listInstances) { |
| 114 | + LOG.info("instance id " + instance.getInstanceId()); |
| 115 | + LOG.info("instance name " + instance.getName()); |
| 116 | +} |
| 117 | + |
| 118 | +// delete the instance we just created |
| 119 | +runAbove.deleteInstance(resultInstance.getInstanceId()); |
| 120 | +``` |
| 121 | + |
| 122 | +How to use storage? |
| 123 | +------------------- |
| 124 | + |
| 125 | +```java |
| 126 | +// initialize configuration |
| 127 | +RunAboveConfig config = new RunAboveConfig() |
| 128 | + .setErrorHandlder(new SystemOutErrorHandler()) |
| 129 | + .setApplicationKey(applicationKey) |
| 130 | + .setApplicationSecret(applicationSecret); |
| 131 | + |
| 132 | +// request credentials |
| 133 | +RunAboveAuthApi runAboveAuth = new RunAboveBuilder(config).createAuth(); |
| 134 | +Credential creds = runAboveAuth.credential(new DefaultCredentialParams()); |
| 135 | + |
| 136 | +// snip snip |
| 137 | +// redirect user to authorization page at creds.getValidationUrl() |
| 138 | +// snip snip |
| 139 | + |
| 140 | +// create the manager object that handles all api calls |
| 141 | +RunAboveManager runAbove = new RunAboveBuilder(getConfig()).createManager(creds.getConsumerKey()); |
| 142 | + |
| 143 | +// storage container creation settings |
| 144 | +StorageContainerCreate storageContainer = new StorageContainerCreate(); |
| 145 | +storageContainer.setContainerName("Container Name"); |
| 146 | +storageContainer.setContainerRegion("BHS-1"); |
| 147 | +StorageContainerDetail containerDetail = runAboveApi.createStorageContainer(storageContainer); |
| 148 | + |
| 149 | +// get all available files in all storage containers |
| 150 | +StorageContainer[] containers = runAboveApi.getStoreContainers(); |
| 151 | +for (StorageContainer storageContainer : containers) { |
| 152 | + |
| 153 | + LOG.info("StorageContainer getContainerName " + storageContainer.getName()); |
| 154 | + LOG.info("StorageContainer getTotalFiles " + storageContainer.getTotalObjects()); |
| 155 | + |
| 156 | + StorageContainer detail = runAboveApi.getStoreContainer(storageContainer.getName(), 10, storageContainer.getRegion(), null); |
| 157 | + if (detail.getObjects() != null) |
| 158 | + for (StorageContainerObject file : detail.getObjects()) { |
| 159 | + LOG.info("StorageContainerFile getContentType " + file.getContentType()); |
| 160 | + LOG.info("StorageContainerFile getLastModified " + file.getLastModified()); |
| 161 | + LOG.info("StorageContainerFile getName " + file.getName()); |
| 162 | + LOG.info("StorageContainerFile getSize " + file.getSize()); |
| 163 | + } |
| 164 | +} |
| 165 | +``` |
| 166 | + |
| 167 | +How to build the documentation? |
| 168 | +------------------------------- |
| 169 | + |
| 170 | +Documentation can be generated with the maven command: |
| 171 | + |
| 172 | + mvn site |
| 173 | + |
| 174 | +Also more documentation about the managers can be found in the knowledge base on the Runabove website. |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | +How to run tests? |
| 179 | +----------------- |
| 180 | + |
| 181 | +The tests are all mocked with proper responses from the runabove api. Just type : |
| 182 | + |
| 183 | + mvn clean test |
| 184 | + |
| 185 | + |
| 186 | + |
| 187 | + |
| 188 | +License |
| 189 | +------- |
| 190 | + |
| 191 | +The SDK code is released under a MIT style license, which means that it should |
| 192 | +be easy to integrate it to your application. |
| 193 | +Check the [LICENSE](LICENSE) file for more information. |
| 194 | + |
| 195 | + |
| 196 | + |
0 commit comments