Getting things to compile

This commit is contained in:
Alex Huang 2012-12-13 15:10:27 -08:00
parent 259e6d5f74
commit 54cce5fa18
16 changed files with 462 additions and 38 deletions

View File

@ -37,9 +37,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.9</version>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-rest</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -24,6 +24,9 @@ import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.cloudstack.engine.service.api.ProvisioningService;
import org.apache.cloudstack.framework.ws.jackson.Url;
import com.cloud.dc.DataCenter;
/**
@ -35,5 +38,6 @@ public interface ZoneEntity extends DataCenterResourceEntity, DataCenter {
@Path("/pods")
List<PodEntity> listPods();
@Url(clazz=ProvisioningService.class, method="getPod", name="id", type=List.class)
List<String> listPodIds();
}

View File

@ -36,10 +36,8 @@ import org.apache.cloudstack.engine.rest.datacenter.entity.api.PodRestTO;
import org.apache.cloudstack.engine.rest.datacenter.entity.api.ZoneRestTO;
import org.apache.cloudstack.engine.service.api.ProvisioningService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Service("provisioningService")
@Path("/provisioning")
@Produces({"application/xml", "application/json"})
@Component

View File

@ -21,6 +21,10 @@ package org.apache.cloudstack.engine.service.api;
import java.util.List;
import java.util.Map;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
@ -35,6 +39,8 @@ import com.cloud.storage.StoragePool;
* ProvisioningService registers and deregisters physical and virtual
* resources that the management server can use.
*/
@Path("/provisioning")
@Produces({"application/json"})
public interface ProvisioningService {
StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details);
@ -61,11 +67,15 @@ public interface ProvisioningService {
List<Host> listHosts();
@GET
@Path("/zone/{zoneid}/pods")
List<PodEntity> listPods();
List<ZoneEntity> listZones();
List<StoragePool> listStorage();
@GET
@Path("/{zoneid}")
ZoneEntity getZone(String id);
}

View File

@ -29,44 +29,16 @@ import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntityImpl;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.cloud.host.Host;
import com.cloud.host.Status;
import com.cloud.storage.StoragePool;
@Component
@Service("provisioningService")
public class ProvisioningServiceImpl implements ProvisioningService {
@Override
public StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public ZoneEntity registerZone(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public PodEntity registerPod(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public String registerHost(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public void deregisterStorage(String uuid) {
// TODO Auto-generated method stub
@ -137,4 +109,34 @@ public class ProvisioningServiceImpl implements ProvisioningService {
return impl;
}
@Override
public StorageEntity registerStorage(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public ZoneEntity registerZone(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public PodEntity registerPod(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public ClusterEntity registerCluster(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
@Override
public String registerHost(String name, List<String> tags, Map<String, String> details) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -42,7 +42,6 @@
<module>storage/imagemotion</module>
<module>storage/backup</module>
<module>storage/snapshot</module>
<module>storage/integration-test</module>
<module>components-api</module>
<module>schema</module>
<module>network</module>

View File

@ -18,7 +18,7 @@
<ref bean="zoneService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
</jaxrs:providers>
</jaxrs:server>
</beans>

View File

@ -51,6 +51,11 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
configuratorMaps.put(key, configurator);
}
}
// TODO: Remove this. I put this in to get over the compilation problem. Edison needs to look at Solidfire's implementation which requires this.
public DefaultPrimaryDatastoreProviderImpl() {
}
protected String generateKey(HypervisorType hypervisor, String poolType) {
return hypervisor.toString().toLowerCase() + "_" + poolType.toString().toLowerCase();

View File

@ -40,5 +40,16 @@
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>2.7.0</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.ws.jackson;
import java.lang.reflect.AnnotatedElement;
import java.util.List;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
/**
* Adds introspectors for the annotations added specifically for CloudStack
* Web Services.
*
*/
public class CSJacksonAnnotationIntrospector extends NopAnnotationIntrospector {
private static final long serialVersionUID = 5532727887216652602L;
@Override
public Version version() {
return new Version(1, 7, 0, "abc", "org.apache.cloudstack", "cloudstack-framework-rest");
}
@Override
public Object findSerializer(Annotated a) {
AnnotatedElement ae = a.getAnnotated();
Url an = ae.getAnnotation(Url.class);
if (an == null) {
return null;
}
if (an.type() == String.class) {
return new UriSerializer(an);
} else if (an.type() == List.class){
return new UrisSerializer(an);
}
throw new UnsupportedOperationException("Unsupported type " + an.type());
}
}

View File

@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.ws.jackson;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;
/**
* This module extends SimpleModle so that our annotations can be processed.
*
*/
public class CSJacksonAnnotationModule extends Module {
@Override
public String getModuleName() {
return "CloudStackSupplementalModule";
}
@Override
public void setupModule(SetupContext ctx) {
ctx.appendAnnotationIntrospector(new CSJacksonAnnotationIntrospector());
}
@Override
public Version version() {
return new Version(1, 0, 0, "", "org.apache.cloudstack", "cloudstack-framework-rest");
}
}

View File

@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.ws.jackson;
import java.io.IOException;
import javax.ws.rs.core.UriBuilder;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class UriSerializer extends JsonSerializer<String> {
Url _annotation;
public UriSerializer(Url annotation) {
_annotation = annotation;
}
protected UriSerializer() {
}
@Override
public void serialize(String id, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeStartObject();
jgen.writeStringField("id", id);
jgen.writeFieldName("uri");
jgen.writeString(buildUri(_annotation.clazz(), _annotation.method(), id));
jgen.writeEndObject();
}
protected String buildUri(Class<?> clazz, String method, String id) {
ThreadLocalUriInfo uriInfo = new ThreadLocalUriInfo();
UriBuilder ub = uriInfo.getAbsolutePathBuilder().path(clazz, method);
ub.build(id);
return ub.toString();
}
}

View File

@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.ws.jackson;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.ws.rs.core.UriBuilder;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Serializer for a list of ids.
*
*/
public class UrisSerializer extends JsonSerializer<List<? extends Object>> {
Url _annotation;
public UrisSerializer(Url annotation) {
_annotation = annotation;
}
protected UrisSerializer() {
}
@Override
public void serialize(List<? extends Object> lst, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
Iterator<? extends Object> it = lst.iterator();
jgen.writeStartObject();
while (it.hasNext()) {
Object id = it.next();
jgen.writeStartObject();
jgen.writeFieldName("id");
jgen.writeObject(id);
jgen.writeFieldName("uri");
jgen.writeString(buildUri(_annotation.clazz(), _annotation.method(), id));
jgen.writeEndObject();
}
jgen.writeEndObject();
}
protected String buildUri(Class<?> clazz, String method, Object id) {
ThreadLocalUriInfo uriInfo = new ThreadLocalUriInfo();
UriBuilder ub = uriInfo.getAbsolutePathBuilder().path(clazz, method);
ub.build(id);
return ub.toString();
}
}

View File

@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.ws.jackson;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Url can be placed onto a method to construct an URL from the returned
* results.
*
* This annotation is supplemental to JAX-RS 2.0's annotations. JAX-RS 2.0
* annotations do not include a way to construct an URL. Of
* course, this only works with how CloudStack works.
*
*/
@Target({FIELD, METHOD})
@Retention(RUNTIME)
public @interface Url {
/**
* @return the class that the path should belong to.
*/
Class<?> clazz() default Object.class;
/**
* @return the name of the method that the path should call back to.
*/
String method();
String name() default "";
Class<?> type() default String.class;
}

View File

@ -0,0 +1,101 @@
package org.apache.cloudstack.framework.ws.jackson;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule.Priority;
public class CSJacksonAnnotationTest {
@Before
public void setUp() throws Exception {
}
@Test
public void test() {
ObjectMapper mapper = new ObjectMapper();
JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule();
jaxbModule.setPriority(Priority.SECONDARY);
mapper.registerModule(jaxbModule);
mapper.registerModule(new CSJacksonAnnotationModule());
StringWriter writer = new StringWriter();
TestVO vo = new TestVO(1000, "name");
vo.names = new ArrayList<String>();
vo.names.add("name1");
vo.names.add("name2");
vo.values = new HashMap<String, Long>();
vo.values.put("key1", 1000l);
vo.values.put("key2", 2000l);
vo.vo2.name = "testvoname2";
vo.pods="abcde";
try {
mapper.writeValue(writer, vo);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(writer.getBuffer().toString());
}
@XmlRootElement(name="xml-test2")
public class Test2VO {
public String name;
}
@XmlRootElement(name="abc")
public class TestVO {
public int id;
public Map<String, Long> values;
public String name;
public List<String> names;
public String pods;
@XmlElement(name="test2")
public Test2VO vo2 = new Test2VO();
public TestVO(int id, String name) {
this.id = id;
this.name = name;
}
@Url(clazz=TestVO.class, method="getName")
public String getName() {
return name;
}
@Url(clazz=TestVO.class, method="getNames", type=List.class)
public List<String> getNames() {
return names;
}
}
}

View File

@ -38,9 +38,14 @@ public class SolidfirePrimaryDataStoreProvider extends
DefaultPrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(dsv);
SolidfirePrimaryDataStoreDriver driver = new SolidfirePrimaryDataStoreDriver();
pds.setDriver(driver);
<<<<<<< HEAD
DefaultPrimaryDataStoreLifeCycleImpl lifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(dataStoreDao);
=======
DefaultPrimaryDataStoreLifeCycleImpl lifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(super.dataStoreDao, pds);
>>>>>>> Getting things to compile
pds.setLifeCycle(lifeCycle);
return pds;
}
}
}