Skip to content

Commit 367a08d

Browse files
committed
Merge pull request woorea#177 from danielerez/cinder_prep_v3.1.x
Cinder prep v3.1.x
2 parents 2675987 + 5c8ec0e commit 367a08d

File tree

9 files changed

+93
-28
lines changed

9 files changed

+93
-28
lines changed

nova-model/src/main/java/com/woorea/openstack/nova/model/ServerForCreate.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public void setName(String name) {
7373
@JsonProperty("availability_zone")
7474
private String availabilityZone;
7575

76+
@JsonProperty("config_drive")
77+
private boolean configDrive;
78+
7679
/**
7780
* @return the name
7881
*/
@@ -278,5 +281,12 @@ public String getAvailabilityZone() {
278281
public void setAvailabilityZone(String availabilityZone) {
279282
this.availabilityZone = availabilityZone;
280283
}
281-
284+
285+
public boolean isConfigDrive() {
286+
return configDrive;
287+
}
288+
289+
public void setConfigDrive(boolean configDrive) {
290+
this.configDrive = configDrive;
291+
}
282292
}

openstack-client-connectors/jersey-connector/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
<version>1.9.12</version>
2121
</dependency>
2222
</dependencies>
23-
</project>
23+
</project>

openstack-client-connectors/jersey-connector/src/main/java/com/woorea/openstack/connector/JerseyConnector.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Map;
55

6+
import javax.ws.rs.core.MultivaluedMap;
67
import javax.ws.rs.ext.ContextResolver;
78
import javax.ws.rs.ext.Provider;
89

@@ -14,13 +15,17 @@
1415
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
1516

1617
import com.sun.jersey.api.client.Client;
18+
import com.sun.jersey.api.client.ClientResponse;
1719
import com.sun.jersey.api.client.UniformInterfaceException;
1820
import com.sun.jersey.api.client.WebResource;
1921
import com.sun.jersey.api.client.config.ClientConfig;
2022
import com.sun.jersey.api.client.config.DefaultClientConfig;
2123
import com.sun.jersey.api.client.filter.LoggingFilter;
24+
import com.sun.jersey.client.impl.ClientRequestImpl;
25+
import com.sun.jersey.core.header.OutBoundHeaders;
2226
import com.woorea.openstack.base.client.OpenStackClientConnector;
2327
import com.woorea.openstack.base.client.OpenStackRequest;
28+
import com.woorea.openstack.base.client.OpenStackResponse;
2429
import com.woorea.openstack.base.client.OpenStackResponseException;
2530

2631
public class JerseyConnector implements OpenStackClientConnector {
@@ -35,46 +40,36 @@ public JerseyConnector() {
3540
}
3641

3742
@Override
38-
public <T> T execute(OpenStackRequest<T> request) {
43+
public <T> OpenStackResponse request(OpenStackRequest<T> request) {
3944
WebResource target = client.resource(request.endpoint()).path(request.path());
4045
for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) {
4146
for (Object o : entry.getValue()) {
4247
target = target.queryParam(entry.getKey(), String.valueOf(o));
4348
}
4449
}
4550
target.addFilter(new LoggingFilter());
46-
47-
WebResource.Builder tb = target.getRequestBuilder();
51+
MultivaluedMap<String, Object> headers = new OutBoundHeaders();
4852
for(Map.Entry<String, List<Object>> h : request.headers().entrySet()) {
49-
StringBuilder sb = new StringBuilder();
5053
for(Object v : h.getValue()) {
51-
sb.append(String.valueOf(v));
54+
headers.add(h.getKey(), v);
5255
}
53-
tb.header(h.getKey(), sb);
5456
}
5557
if(request.entity() != null && request.entity().getContentType() != null) {
56-
tb.header("Content-Type", request.entity().getContentType());
58+
headers.add("Content-Type", request.entity().getContentType());
5759
} else {
58-
tb.header("Content-Type", "application/json");
60+
headers.add("Content-Type", "application/json");
5961
}
6062
try {
63+
ClientResponse response = null;
6164
if (request.entity() != null && request.entity().getEntity() != null) {
62-
if (request.returnType() == null || Void.class == request.returnType()) {
63-
tb.method(request.method().name(), request.entity().getEntity());
64-
} else {
65-
return tb.method(request.method().name(), request.returnType(), request.entity().getEntity());
66-
}
65+
response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), request.entity().getEntity(), headers));
6766
} else {
68-
if (request.returnType() == null || Void.class == request.returnType()) {
69-
tb.method(request.method().name());
70-
} else {
71-
return tb.method(request.method().name(), request.returnType());
72-
}
67+
response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), null, headers));
7368
}
69+
return new JerseyResponse(response);
7470
} catch (UniformInterfaceException e) {
7571
throw new OpenStackResponseException(e.getResponse().getClientResponseStatus().getReasonPhrase(), e.getResponse().getStatus());
7672
}
77-
return null;
7873
}
7974

8075
@Provider
@@ -86,12 +81,14 @@ public static class OpenStackObjectMapper implements ContextResolver<ObjectMappe
8681
DEFAULT_MAPPER.setSerializationInclusion(Inclusion.NON_NULL);
8782
DEFAULT_MAPPER.enable(SerializationConfig.Feature.INDENT_OUTPUT);
8883
DEFAULT_MAPPER.enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
84+
DEFAULT_MAPPER.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
8985
WRAPPED_MAPPER = new ObjectMapper();
9086
WRAPPED_MAPPER.setSerializationInclusion(Inclusion.NON_NULL);
9187
WRAPPED_MAPPER.enable(SerializationConfig.Feature.INDENT_OUTPUT);
9288
WRAPPED_MAPPER.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
9389
WRAPPED_MAPPER.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
9490
WRAPPED_MAPPER.enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
91+
WRAPPED_MAPPER.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
9592
}
9693

9794
@Override
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.woorea.openstack.connector;
2+
3+
import java.io.InputStream;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
import com.sun.jersey.api.client.ClientResponse;
8+
import com.woorea.openstack.base.client.OpenStackResponse;
9+
10+
public class JerseyResponse implements OpenStackResponse {
11+
12+
private ClientResponse response;
13+
14+
public JerseyResponse(ClientResponse response) {
15+
this.response = response;
16+
}
17+
18+
@Override
19+
public <T> T getEntity(Class<T> returnType) {
20+
if(response.hasEntity() && returnType != null && Void.class != returnType) {
21+
return response.getEntity(returnType);
22+
} else {
23+
return null;
24+
}
25+
}
26+
27+
@Override
28+
public InputStream getInputStream() {
29+
if(response.hasEntity()) {
30+
return response.getEntityInputStream();
31+
} else {
32+
return null;
33+
}
34+
}
35+
36+
@Override
37+
public String header(String name) {
38+
return response.getHeaders().getFirst(name);
39+
}
40+
41+
@Override
42+
public Map<String, String> headers() {
43+
Map<String, String> headers = new HashMap<String, String>();
44+
for(String k : response.getHeaders().keySet()) {
45+
headers.put(k, response.getHeaders().getFirst(k));
46+
}
47+
return headers;
48+
}
49+
}

openstack-client-connectors/jersey2-connector/src/main/java/com/woorea/openstack/connector/JaxRs20Connector.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import javax.ws.rs.client.Entity;
1010
import javax.ws.rs.client.Invocation;
1111
import javax.ws.rs.client.WebTarget;
12+
import javax.ws.rs.core.MediaType;
1213

1314
import org.glassfish.jersey.filter.LoggingFilter;
1415

16+
import com.woorea.openstack.base.client.HttpMethod;
1517
import com.woorea.openstack.base.client.OpenStackClientConnector;
1618
import com.woorea.openstack.base.client.OpenStackRequest;
1719
import com.woorea.openstack.base.client.OpenStackResponse;
@@ -49,7 +51,11 @@ public <T> OpenStackResponse request(OpenStackRequest<T> request) {
4951
if (entity != null) {
5052
return new JaxRs20Response(invocation.method(request.method().name(), entity));
5153
} else {
52-
return new JaxRs20Response(invocation.method(request.method().name()));
54+
if(HttpMethod.PUT == request.method()) {
55+
return new JaxRs20Response(invocation.method(request.method().name(), Entity.entity("", MediaType.APPLICATION_JSON)));
56+
} else {
57+
return new JaxRs20Response(invocation.method(request.method().name()));
58+
}
5359
}
5460
} catch (ClientErrorException e) {
5561
throw new OpenStackResponseException(e.getResponse()

openstack-client-connectors/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<profile>
1414
<id>jersey</id>
1515
<activation>
16-
<activeByDefault>false</activeByDefault>
16+
<activeByDefault>true</activeByDefault>
1717
</activation>
1818
<modules>
1919
<module>jersey-connector</module>

openstack-client-connectors/resteasy-connector/src/main/java/com/woorea/openstack/connector/RESTEasyConnector.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public ObjectMapper getContext(Class<?> type) {
6363
DEFAULT_MAPPER.setSerializationInclusion(Inclusion.NON_NULL);
6464
DEFAULT_MAPPER.enable(SerializationConfig.Feature.INDENT_OUTPUT);
6565
DEFAULT_MAPPER.enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
66+
DEFAULT_MAPPER.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
6667

6768
WRAPPED_MAPPER = new ObjectMapper();
6869

@@ -71,6 +72,7 @@ public ObjectMapper getContext(Class<?> type) {
7172
WRAPPED_MAPPER.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
7273
WRAPPED_MAPPER.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
7374
WRAPPED_MAPPER.enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
75+
WRAPPED_MAPPER.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
7476

7577
providerFactory = new OpenStackProviderFactory();
7678
}
@@ -107,7 +109,8 @@ public <T> OpenStackResponse request(OpenStackRequest<T> request) {
107109

108110
if (response.getStatus() == HttpStatus.SC_OK
109111
|| response.getStatus() == HttpStatus.SC_CREATED
110-
|| response.getStatus() == HttpStatus.SC_NO_CONTENT) {
112+
|| response.getStatus() == HttpStatus.SC_NO_CONTENT
113+
|| response.getStatus() == HttpStatus.SC_ACCEPTED) {
111114
return new RESTEasyResponse(client, response);
112115
}
113116

openstack-client/src/main/java/com/woorea/openstack/base/client/OpenStackClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public <T> OpenStackResponse request(OpenStackRequest<T> request) {
6464

6565
public <T> T execute(OpenStackRequest<T> request) {
6666
OpenStackResponse response = request(request);
67-
return request.returnType() != null ? response.getEntity(request.returnType()) : null;
67+
return (request.returnType() != null && request.returnType() != Void.class) ? response.getEntity(request.returnType()) : null;
6868
}
6969

7070
public void property(String property, String value) {

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@
9393
<plugin>
9494
<groupId>org.apache.maven.plugins</groupId>
9595
<artifactId>maven-compiler-plugin</artifactId>
96-
<version>3.0</version>
96+
<version>3.1</version>
9797
<configuration>
98-
<source>1.6</source>
99-
<target>1.6</target>
98+
<source>1.7</source>
99+
<target>1.7</target>
100100
<encoding>UTF-8</encoding>
101101
</configuration>
102102
</plugin>

0 commit comments

Comments
 (0)