Fixed problems with inject checkin

This commit is contained in:
Alex Huang 2012-12-28 16:24:54 -08:00
parent 54cce5fa18
commit e936c32a04
15 changed files with 590 additions and 348 deletions

View File

@ -22,6 +22,7 @@ import java.util.List;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.apache.cloudstack.engine.service.api.ProvisioningService; import org.apache.cloudstack.engine.service.api.ProvisioningService;
@ -32,6 +33,8 @@ import com.cloud.dc.DataCenter;
/** /**
* Describes a zone and operations that can be done in a zone. * Describes a zone and operations that can be done in a zone.
*/ */
@Path("/zone/{zoneid}")
@Produces({"application/json"})
@XmlRootElement(name="zone") @XmlRootElement(name="zone")
public interface ZoneEntity extends DataCenterResourceEntity, DataCenter { public interface ZoneEntity extends DataCenterResourceEntity, DataCenter {
@GET @GET
@ -40,4 +43,8 @@ public interface ZoneEntity extends DataCenterResourceEntity, DataCenter {
@Url(clazz=ProvisioningService.class, method="getPod", name="id", type=List.class) @Url(clazz=ProvisioningService.class, method="getPod", name="id", type=List.class)
List<String> listPodIds(); List<String> listPodIds();
@Override
@Path("/enable")
boolean enable();
} }

View File

@ -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.apache.cloudstack.engine.rest.datacenter.entity.api;
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
public class PodRestTO {
public String uuid;
public String name;
public PodRestTO(PodEntity pod) {
this.uuid = pod.getUuid();
this.name = pod.getName();
}
public PodRestTO() {
}
}

View File

@ -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.apache.cloudstack.engine.rest.datacenter.entity.api;
import java.net.URI;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
import org.apache.cloudstack.engine.service.api.ProvisioningService;
import org.springframework.stereotype.Service;
@Service("zoneService")
@Path("/zone/{zoneid}")
public class ZoneRestTO {
@Inject
protected static ProvisioningService s_provisioningService;
public String id;
public URI uri;
public String name;
public URI[] pods;
public ZoneRestTO(UriInfo ui, ZoneEntity zone, URI uri) {
this.id = zone.getUuid();
this.name = zone.getName();
this.uri = uri;
List<String> podIds = zone.listPodIds();
this.pods = new URI[podIds.size()];
UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getPod");
Iterator<String> it = podIds.iterator();
for (int i = 0; i < pods.length; i++) {
String pod = it.next();
pods[i] = ub.build(pod);
}
}
public ZoneRestTO() {
}
@GET
@Path("/pods")
public URI[] listPods(@PathParam("zoneid") String zoneId) {
return this.pods;
}
@GET
@Path("/pod/{podid}")
public PodRestTO getPod(@Context UriInfo ui, @PathParam("podid") String podId) {
return null;
}
}

View File

@ -1,23 +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.apache.cloudstack.engine.rest.datacenter.entity.api;
public class ZoneRestTOs {
}

View File

@ -0,0 +1,87 @@
/*
* 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.engine.rest.service.api;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity;
import org.apache.cloudstack.engine.service.api.ProvisioningService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
@Service("ClusterRestService")
@Produces("application/json")
public class ClusterRestService {
@Inject
ProvisioningService _provisioningService;
@GET @Path("/clusters")
public List<ClusterEntity> listAll() {
return null;
}
@GET @Path("/cluster/{clusterid}")
public ClusterEntity get(@PathParam("clusterid") String clusterId) {
return null;
}
@POST @Path("/cluster/{clusterid}/enable")
public String enable(@PathParam("clusterid") String clusterId) {
return null;
}
@POST @Path("/cluster/{clusterid}/disable")
public String disable(@PathParam("clusterid") String clusterId) {
return null;
}
@POST @Path("/cluster/{clusterid}/deactivate")
public String deactivate(@PathParam("clusterid") String clusterId) {
return null;
}
@POST @Path("/cluster/{clusterid}/reactivate")
public String reactivate(@PathParam("clusterid") String clusterId) {
return null;
}
@PUT @Path("/cluster/create")
public ClusterEntity create(
@QueryParam("xid") String xid,
@QueryParam("display-name") String displayName) {
return null;
}
@PUT @Path("/cluster/{clusterid}/update")
public ClusterEntity update(
@QueryParam("display-name") String displayName) {
return null;
}
}

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.engine.rest.service.api;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Service("NetworkRestService")
@Component
@Produces("application/json")
public class NetworkRestService {
@PUT @Path("/network/create")
public NetworkEntity create(
@QueryParam("xid") String xid,
@QueryParam("display-name") String displayName) {
return null;
}
@GET @Path("/network/{network-id}")
public NetworkEntity get(@PathParam("network-id") String networkId) {
return null;
}
@GET @Path("/networks")
public List<NetworkEntity> listAll() {
return null;
}
@POST @Path("/network/{network-id}/")
public String deploy(@PathParam("network-id") String networkId) {
return null;
}
}

View File

@ -0,0 +1,80 @@
/*
* 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.engine.rest.service.api;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
import org.apache.cloudstack.engine.service.api.ProvisioningService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
@Service("PodService")
@Produces({"application/json"})
public class PodRestService {
@Inject
ProvisioningService _provisioningService;
@GET @Path("/pod/{pod-id}")
public PodEntity getPod(@PathParam("pod-id") String podId) {
return null;
}
@POST @Path("/pod/{pod-id}/enable")
public String enable(@PathParam("pod-id") String podId) {
return null;
}
@POST @Path("/pod/{pod-id}/disable")
public String disable(@PathParam("pod-id") String podId) {
return null;
}
@POST @Path("/pod/{pod-id}/deactivate")
public String deactivate(@PathParam("pod-id") String podId) {
return null;
}
@POST @Path("/pod/{pod-id}/reactivate")
public String reactivate(@PathParam("pod-id") String podId) {
return null;
}
@PUT @Path("/pod/create")
public PodEntity create(
@QueryParam("xid") String xid,
@QueryParam("display-name") String displayName) {
return null;
}
@PUT @Path("/pod/{pod-id}")
public PodEntity update(
@PathParam("pod-id") String podId,
@QueryParam("display-name") String displayName) {
return null;
}
}

View File

@ -1,82 +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.apache.cloudstack.engine.rest.service.api;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import org.apache.cloudstack.engine.datacenter.entity.api.PodEntity;
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
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;
@Path("/provisioning")
@Produces({"application/xml", "application/json"})
@Component
public class ProvisioningRestService {
@Inject
ProvisioningService _provisioningService;
@GET
@Path("/{zoneid}")
public ZoneRestTO getZone(@Context UriInfo ui, @PathParam("zoneid") String id) {
UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone");
ZoneEntity entity = _provisioningService.getZone(id);
return new ZoneRestTO(ui, entity, ub.build(entity.getUuid()));
}
@GET
@Path("/zones")
public ZoneRestTO[] listZones(@Context UriInfo ui) {
List<ZoneEntity> zones = _provisioningService.listZones();
ZoneRestTO[] tos = new ZoneRestTO[zones.size()];
UriBuilder ub = ui.getAbsolutePathBuilder().path(this.getClass(), "getZone");
Iterator<ZoneEntity> it = zones.iterator();
for (int i = 0; i < tos.length; i++) {
ZoneEntity entity = it.next();
tos[i] = new ZoneRestTO(ui, entity, ub.build(entity.getUuid()));
}
return tos;
}
@GET
@Path("/zone/{zoneid}/pods")
public PodRestTO[] listPods(@PathParam("zoneid") String zoneId) {
List<PodEntity> pods = _provisioningService.listPods();
PodRestTO[] tos = new PodRestTO[pods.size()];
Iterator<PodEntity> it = pods.iterator();
for (int i = 0; i < tos.length; i++) {
PodEntity pod = it.next();
tos[i] = new PodRestTO(pod);
}
return tos;
}
}

View File

@ -0,0 +1,56 @@
/*
* 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.engine.rest.service.api;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
@Service("VirtualMachineRestService")
@Produces("application/xml")
public class VirtualMachineRestService {
@GET @Path("/vm/{vmid}")
public VirtualMachineEntity get(@PathParam("vmid") String vmId) {
return null;
}
@PUT @Path("/vm/create")
public VirtualMachineEntity create(
@QueryParam("xid") String xid,
@QueryParam("hostname") String hostname,
@QueryParam("display-name") String displayName) {
return null;
}
@GET @Path("/vms")
public List<VirtualMachineEntity> listAll() {
return null;
}
}

View File

@ -0,0 +1,76 @@
/*
* 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.engine.rest.service.api;
import java.util.List;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
@Service("VolumeRestService")
@Produces("application/json")
public class VolumeRestService {
@PUT @Path("/vol/create")
public VolumeEntity create(
@QueryParam("xid") String xid,
@QueryParam("display-name") String displayName) {
return null;
}
@POST @Path("/vol/{volid}/deploy")
public String deploy(@PathParam("volid") String volumeId) {
return null;
}
@GET @Path("/vols")
public List<VolumeEntity> listAll() {
return null;
}
@POST @Path("/vol/{volid}/attach-to")
public String attachTo(
@PathParam("volid") String volumeId,
@QueryParam("vmid") String vmId,
@QueryParam("device-order") short device) {
return null;
}
@DELETE @Path("/vol/{volid}")
public String delete(@PathParam("volid") String volumeId) {
return null;
}
@POST @Path("/vol/{volid}/detach")
public String detach(@QueryParam("volid") String volumeId) {
return null;
}
}

View File

@ -0,0 +1,88 @@
/*
* 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.engine.rest.service.api;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import org.apache.cloudstack.engine.datacenter.entity.api.ZoneEntity;
import org.apache.cloudstack.engine.service.api.ProvisioningService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
@Service("zoneService")
@Produces({"application/json"})
public class ZoneRestService {
@Inject
ProvisioningService _provisioningService;
@GET @Path("/zones")
public List<ZoneEntity> listAll() {
return _provisioningService.listZones();
}
@GET @Path("/zone/{zone-id}")
public ZoneEntity get(@PathParam("zone-id") String zoneId) {
return _provisioningService.getZone(zoneId);
}
@POST @Path("/zone/{zone-id}/enable")
public String enable(String zoneId) {
return null;
}
@POST @Path("/zone/{zone-id}/disable")
public String disable(@PathParam("zone-id") String zoneId) {
ZoneEntity zoneEntity = _provisioningService.getZone(zoneId);
zoneEntity.disable();
return null;
}
@POST @Path("/zone/{zone-id}/deactivate")
public String deactivate(@PathParam("zone-id") String zoneId) {
return null;
}
@POST @Path("/zone/{zone-id}/activate")
public String reactivate(@PathParam("zone-id") String zoneId) {
return null;
}
@PUT @Path("/zone/create")
public ZoneEntity createZone(@QueryParam("xid") String xid,
@QueryParam("display-name") String displayName) {
return null;
}
@DELETE @Path("/zone/{zone-id}")
public String deleteZone(@QueryParam("zone-id") String xid) {
return null;
}
}

View File

@ -24,7 +24,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.stereotype.Service;
@Service("zoneService")
public class ZoneEntityImpl implements ZoneEntity { public class ZoneEntityImpl implements ZoneEntity {
String _id; String _id;
String _name; String _name;

View File

@ -10,12 +10,15 @@
<import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<context:component-scan base-package="org.apache.cloudstack" /> <context:component-scan base-package="org.apache.cloudstack.engine.rest.service" />
<jaxrs:server id="restContainer" address="/"> <jaxrs:server id="EngineService" address="/">
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
<ref bean="provisioningService" /> <ref bean="ZoneRestService" />
<ref bean="zoneService" /> <ref bean="PodRestService" />
<ref bean="ClusterRestService" />
<ref bean="VirtualMachineRestService" />
<ref bean="VolumeRestService" />
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
<jaxrs:providers> <jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" /> <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />

View File

@ -36,7 +36,6 @@ import com.cloud.dc.PodVlanVO;
import com.cloud.org.Grouping; import com.cloud.org.Grouping;
import com.cloud.utils.NumbersUtil; import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchBuilder;
@ -63,43 +62,44 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
protected SearchBuilder<DataCenterVO> ChildZonesSearch; protected SearchBuilder<DataCenterVO> ChildZonesSearch;
protected SearchBuilder<DataCenterVO> DisabledZonesSearch; protected SearchBuilder<DataCenterVO> DisabledZonesSearch;
protected SearchBuilder<DataCenterVO> TokenSearch; protected SearchBuilder<DataCenterVO> TokenSearch;
@Inject protected final DataCenterIpAddressDaoImpl _ipAllocDao; @Inject protected DataCenterIpAddressDaoImpl _ipAllocDao = null;
@Inject protected final DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao; @Inject protected DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao = null;
@Inject protected final DataCenterVnetDaoImpl _vnetAllocDao; @Inject protected DataCenterVnetDaoImpl _vnetAllocDao = null;
@Inject protected final PodVlanDaoImpl _podVlanAllocDao; @Inject protected PodVlanDaoImpl _podVlanAllocDao = null;
@Inject protected DcDetailsDaoImpl _detailsDao = null;
protected long _prefix; protected long _prefix;
protected Random _rand = new Random(System.currentTimeMillis()); protected Random _rand = new Random(System.currentTimeMillis());
protected TableGenerator _tgMacAddress; protected TableGenerator _tgMacAddress;
@Inject protected final DcDetailsDaoImpl _detailsDao;
@Override @Override
public DataCenterVO findByName(String name) { public DataCenterVO findByName(String name) {
SearchCriteria<DataCenterVO> sc = NameSearch.create(); SearchCriteria<DataCenterVO> sc = NameSearch.create();
sc.setParameters("name", name); sc.setParameters("name", name);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public DataCenterVO findByToken(String zoneToken){ public DataCenterVO findByToken(String zoneToken){
SearchCriteria<DataCenterVO> sc = TokenSearch.create(); SearchCriteria<DataCenterVO> sc = TokenSearch.create();
sc.setParameters("zoneToken", zoneToken); sc.setParameters("zoneToken", zoneToken);
return findOneBy(sc); return findOneBy(sc);
} }
@Override @Override
public List<DataCenterVO> findZonesByDomainId(Long domainId){ public List<DataCenterVO> findZonesByDomainId(Long domainId){
SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create(); SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create();
sc.setParameters("domainId", domainId); sc.setParameters("domainId", domainId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<DataCenterVO> findZonesByDomainId(Long domainId, String keyword){ public List<DataCenterVO> findZonesByDomainId(Long domainId, String keyword){
SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create(); SearchCriteria<DataCenterVO> sc = ListZonesByDomainIdSearch.create();
sc.setParameters("domainId", domainId); sc.setParameters("domainId", domainId);
if (keyword != null) { if (keyword != null) {
SearchCriteria<DataCenterVO> ssc = createSearchCriteria(); SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@ -107,12 +107,12 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
} }
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<DataCenterVO> findChildZones(Object[] ids, String keyword){ public List<DataCenterVO> findChildZones(Object[] ids, String keyword){
SearchCriteria<DataCenterVO> sc = ChildZonesSearch.create(); SearchCriteria<DataCenterVO> sc = ChildZonesSearch.create();
sc.setParameters("domainid", ids); sc.setParameters("domainid", ids);
if (keyword != null) { if (keyword != null) {
SearchCriteria<DataCenterVO> ssc = createSearchCriteria(); SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@ -120,71 +120,71 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
} }
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<DataCenterVO> listPublicZones(String keyword){ public List<DataCenterVO> listPublicZones(String keyword){
SearchCriteria<DataCenterVO> sc = PublicZonesSearch.create(); SearchCriteria<DataCenterVO> sc = PublicZonesSearch.create();
if (keyword != null) { if (keyword != null) {
SearchCriteria<DataCenterVO> ssc = createSearchCriteria(); SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc); sc.addAnd("name", SearchCriteria.Op.SC, ssc);
} }
//sc.setParameters("domainId", domainId); //sc.setParameters("domainId", domainId);
return listBy(sc); return listBy(sc);
} }
@Override @Override
public List<DataCenterVO> findByKeyword(String keyword){ public List<DataCenterVO> findByKeyword(String keyword){
SearchCriteria<DataCenterVO> ssc = createSearchCriteria(); SearchCriteria<DataCenterVO> ssc = createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%"); ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
return listBy(ssc); return listBy(ssc);
} }
@Override @Override
public void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId) { public void releaseVnet(String vnet, long dcId, long physicalNetworkId, long accountId, String reservationId) {
_vnetAllocDao.release(vnet, physicalNetworkId, accountId, reservationId); _vnetAllocDao.release(vnet, physicalNetworkId, accountId, reservationId);
} }
@Override @Override
public List<DataCenterVnetVO> findVnet(long dcId, long physicalNetworkId, String vnet) { public List<DataCenterVnetVO> findVnet(long dcId, long physicalNetworkId, String vnet) {
return _vnetAllocDao.findVnet(dcId, physicalNetworkId, vnet); return _vnetAllocDao.findVnet(dcId, physicalNetworkId, vnet);
} }
@Override @Override
public int countZoneVlans(long dcId, boolean onlyCountAllocated){ public int countZoneVlans(long dcId, boolean onlyCountAllocated){
return _vnetAllocDao.countZoneVlans(dcId, onlyCountAllocated); return _vnetAllocDao.countZoneVlans(dcId, onlyCountAllocated);
} }
@Override @Override
public void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId) { public void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId) {
_ipAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); _ipAllocDao.releaseIpAddress(ipAddress, dcId, instanceId);
} }
@Override @Override
public void releasePrivateIpAddress(long nicId, String reservationId) { public void releasePrivateIpAddress(long nicId, String reservationId) {
_ipAllocDao.releaseIpAddress(nicId, reservationId); _ipAllocDao.releaseIpAddress(nicId, reservationId);
} }
@Override @Override
public void releaseLinkLocalIpAddress(long nicId, String reservationId) { public void releaseLinkLocalIpAddress(long nicId, String reservationId) {
_LinkLocalIpAllocDao.releaseIpAddress(nicId, reservationId); _LinkLocalIpAllocDao.releaseIpAddress(nicId, reservationId);
} }
@Override @Override
public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) { public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) {
_LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId); _LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId);
} }
@Override @Override
public boolean deletePrivateIpAddressByPod(long podId) { public boolean deletePrivateIpAddressByPod(long podId) {
return _ipAllocDao.deleteIpAddressByPod(podId); return _ipAllocDao.deleteIpAddressByPod(podId);
} }
@Override @Override
public boolean deleteLinkLocalIpAddressByPod(long podId) { public boolean deleteLinkLocalIpAddressByPod(long podId) {
return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId); return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId);
} }
@Override @Override
@ -196,7 +196,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
return vo.getVnet(); return vo.getVnet();
} }
@Override @Override
public String allocatePodVlan(long podId, long accountId) { public String allocatePodVlan(long podId, long accountId) {
PodVlanVO vo = _podVlanAllocDao.take(podId, accountId); PodVlanVO vo = _podVlanAllocDao.take(podId, accountId);
@ -214,7 +214,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
@Override @Override
public String[] getNextAvailableMacAddressPair(long id, long mask) { public String[] getNextAvailableMacAddressPair(long id, long mask) {
SequenceFetcher fetch = SequenceFetcher.getInstance(); SequenceFetcher fetch = SequenceFetcher.getInstance();
long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id); long seq = fetch.getNextSequence(Long.class, _tgMacAddress, id);
seq = seq | _prefix | ((id & 0x7f) << 32); seq = seq | _prefix | ((id & 0x7f) << 32);
seq |= mask; seq |= mask;
@ -234,43 +234,44 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
return new Pair<String, Long>(vo.getIpAddress(), vo.getMacAddress()); return new Pair<String, Long>(vo.getIpAddress(), vo.getMacAddress());
} }
@Override
public DataCenterIpAddressVO allocatePrivateIpAddress(long dcId, String reservationId) { public DataCenterIpAddressVO allocatePrivateIpAddress(long dcId, String reservationId) {
DataCenterIpAddressVO vo = _ipAllocDao.takeDataCenterIpAddress(dcId, reservationId); DataCenterIpAddressVO vo = _ipAllocDao.takeDataCenterIpAddress(dcId, reservationId);
return vo; return vo;
} }
@Override @Override
public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) { public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) {
DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId); DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId);
if (vo == null) { if (vo == null) {
return null; return null;
} }
return vo.getIpAddress(); return vo.getIpAddress();
} }
@Override @Override
public void addVnet(long dcId, long physicalNetworkId, int start, int end) { public void addVnet(long dcId, long physicalNetworkId, int start, int end) {
_vnetAllocDao.add(dcId, physicalNetworkId, start, end); _vnetAllocDao.add(dcId, physicalNetworkId, start, end);
} }
@Override @Override
public void deleteVnet(long physicalNetworkId) { public void deleteVnet(long physicalNetworkId) {
_vnetAllocDao.delete(physicalNetworkId); _vnetAllocDao.delete(physicalNetworkId);
} }
@Override @Override
public List<DataCenterVnetVO> listAllocatedVnets(long physicalNetworkId) { public List<DataCenterVnetVO> listAllocatedVnets(long physicalNetworkId) {
return _vnetAllocDao.listAllocatedVnets(physicalNetworkId); return _vnetAllocDao.listAllocatedVnets(physicalNetworkId);
} }
@Override @Override
public void addPrivateIpAddress(long dcId,long podId, String start, String end) { public void addPrivateIpAddress(long dcId,long podId, String start, String end) {
_ipAllocDao.addIpRange(dcId, podId, start, end); _ipAllocDao.addIpRange(dcId, podId, start, end);
} }
@Override @Override
public void addLinkLocalIpAddress(long dcId,long podId, String start, String end) { public void addLinkLocalIpAddress(long dcId,long podId, String start, String end) {
_LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end); _LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end);
} }
@Override @Override
@ -278,7 +279,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
if (!super.configure(name, params)) { if (!super.configure(name, params)) {
return false; return false;
} }
String value = (String)params.get("mac.address.prefix"); String value = (String)params.get("mac.address.prefix");
_prefix = (long)NumbersUtil.parseInt(value, 06) << 40; _prefix = (long)NumbersUtil.parseInt(value, 06) << 40;
@ -291,33 +292,33 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
} }
return true; return true;
} }
protected DataCenterDaoImpl() { protected DataCenterDaoImpl() {
super(); super();
NameSearch = createSearchBuilder(); NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
NameSearch.done(); NameSearch.done();
ListZonesByDomainIdSearch = createSearchBuilder(); ListZonesByDomainIdSearch = createSearchBuilder();
ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ); ListZonesByDomainIdSearch.and("domainId", ListZonesByDomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
ListZonesByDomainIdSearch.done(); ListZonesByDomainIdSearch.done();
PublicZonesSearch = createSearchBuilder(); PublicZonesSearch = createSearchBuilder();
PublicZonesSearch.and("domainId", PublicZonesSearch.entity().getDomainId(), SearchCriteria.Op.NULL); PublicZonesSearch.and("domainId", PublicZonesSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
PublicZonesSearch.done(); PublicZonesSearch.done();
ChildZonesSearch = createSearchBuilder(); ChildZonesSearch = createSearchBuilder();
ChildZonesSearch.and("domainid", ChildZonesSearch.entity().getDomainId(), SearchCriteria.Op.IN); ChildZonesSearch.and("domainid", ChildZonesSearch.entity().getDomainId(), SearchCriteria.Op.IN);
ChildZonesSearch.done(); ChildZonesSearch.done();
DisabledZonesSearch = createSearchBuilder(); DisabledZonesSearch = createSearchBuilder();
DisabledZonesSearch.and("allocationState", DisabledZonesSearch.entity().getAllocationState(), SearchCriteria.Op.EQ); DisabledZonesSearch.and("allocationState", DisabledZonesSearch.entity().getAllocationState(), SearchCriteria.Op.EQ);
DisabledZonesSearch.done(); DisabledZonesSearch.done();
TokenSearch = createSearchBuilder(); TokenSearch = createSearchBuilder();
TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ); TokenSearch.and("zoneToken", TokenSearch.entity().getZoneToken(), SearchCriteria.Op.EQ);
TokenSearch.done(); TokenSearch.done();
_tgMacAddress = _tgs.get("macAddress"); _tgMacAddress = _tgs.get("macAddress");
assert _tgMacAddress != null : "Couldn't get mac address table generator"; assert _tgMacAddress != null : "Couldn't get mac address table generator";
} }
@ -334,7 +335,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
txn.commit(); txn.commit();
return persisted; return persisted;
} }
@Override @Override
public void loadDetails(DataCenterVO zone) { public void loadDetails(DataCenterVO zone) {
Map<String, String> details =_detailsDao.findDetails(zone.getId()); Map<String, String> details =_detailsDao.findDetails(zone.getId());
@ -349,25 +350,25 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
} }
_detailsDao.persist(zone.getId(), details); _detailsDao.persist(zone.getId(), details);
} }
@Override @Override
public List<DataCenterVO> listDisabledZones(){ public List<DataCenterVO> listDisabledZones(){
SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create(); SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create();
sc.setParameters("allocationState", Grouping.AllocationState.Disabled); sc.setParameters("allocationState", Grouping.AllocationState.Disabled);
List<DataCenterVO> dcs = listBy(sc); List<DataCenterVO> dcs = listBy(sc);
return dcs; return dcs;
} }
@Override @Override
public List<DataCenterVO> listEnabledZones(){ public List<DataCenterVO> listEnabledZones(){
SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create(); SearchCriteria<DataCenterVO> sc = DisabledZonesSearch.create();
sc.setParameters("allocationState", Grouping.AllocationState.Enabled); sc.setParameters("allocationState", Grouping.AllocationState.Enabled);
List<DataCenterVO> dcs = listBy(sc); List<DataCenterVO> dcs = listBy(sc);
return dcs; return dcs;
} }
@Override @Override
@ -380,20 +381,20 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
Long dcId = Long.parseLong(tokenOrIdOrName); Long dcId = Long.parseLong(tokenOrIdOrName);
return findById(dcId); return findById(dcId);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
} }
} }
} }
return result; return result;
} }
@Override @Override
public boolean remove(Long id) { public boolean remove(Long id) {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
txn.start(); txn.start();
DataCenterVO zone = createForUpdate(); DataCenterVO zone = createForUpdate();
zone.setName(null); zone.setName(null);
update(id, zone); update(id, zone);
boolean result = super.remove(id); boolean result = super.remove(id);

View File

@ -37,7 +37,6 @@ import javax.persistence.Transient;
import com.cloud.api.Identity; import com.cloud.api.Identity;
import com.cloud.network.dao.FirewallRulesCidrsDaoImpl; import com.cloud.network.dao.FirewallRulesCidrsDaoImpl;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDao;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
@ -46,68 +45,68 @@ import com.cloud.utils.net.NetUtils;
@Inheritance(strategy=InheritanceType.JOINED) @Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="purpose", discriminatorType=DiscriminatorType.STRING, length=32) @DiscriminatorColumn(name="purpose", discriminatorType=DiscriminatorType.STRING, length=32)
public class FirewallRuleVO implements Identity, FirewallRule { public class FirewallRuleVO implements Identity, FirewallRule {
@Inject protected final FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao; @Inject protected final FirewallRulesCidrsDaoImpl _firewallRulesCidrsDao = null;
@Id @Id
@GeneratedValue(strategy=GenerationType.IDENTITY) @GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id") @Column(name="id")
long id; long id;
@GeneratedValue(strategy=GenerationType.AUTO) @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name=GenericDao.XID_COLUMN) @Column(name=GenericDao.XID_COLUMN)
String xId; String xId;
@Column(name="domain_id", updatable=false) @Column(name="domain_id", updatable=false)
long domainId; long domainId;
@Column(name="account_id", updatable=false) @Column(name="account_id", updatable=false)
long accountId; long accountId;
@Column(name="ip_address_id", updatable=false) @Column(name="ip_address_id", updatable=false)
Long sourceIpAddressId; Long sourceIpAddressId;
@Column(name="start_port", updatable=false) @Column(name="start_port", updatable=false)
Integer sourcePortStart; Integer sourcePortStart;
@Column(name="end_port", updatable=false) @Column(name="end_port", updatable=false)
Integer sourcePortEnd; Integer sourcePortEnd;
@Column(name="protocol", updatable=false) @Column(name="protocol", updatable=false)
String protocol = NetUtils.TCP_PROTO; String protocol = NetUtils.TCP_PROTO;
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
@Column(name="purpose") @Column(name="purpose")
Purpose purpose; Purpose purpose;
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
@Column(name="state") @Column(name="state")
State state; State state;
@Column(name=GenericDao.CREATED_COLUMN) @Column(name=GenericDao.CREATED_COLUMN)
Date created; Date created;
@Column(name="network_id") @Column(name="network_id")
long networkId; long networkId;
@Column(name="icmp_code") @Column(name="icmp_code")
Integer icmpCode; Integer icmpCode;
@Column(name="icmp_type") @Column(name="icmp_type")
Integer icmpType; Integer icmpType;
@Column(name="related") @Column(name="related")
Long related; Long related;
@Column(name="type") @Column(name="type")
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
FirewallRuleType type; FirewallRuleType type;
@Column(name="traffic_type") @Column(name="traffic_type")
@Enumerated(value=EnumType.STRING) @Enumerated(value=EnumType.STRING)
TrafficType trafficType; TrafficType trafficType;
// This is a delayed load value. If the value is null, // This is a delayed load value. If the value is null,
// then this field has not been loaded yet. // then this field has not been loaded yet.
// Call firewallrules dao to load it. // Call firewallrules dao to load it.
@ -168,7 +167,7 @@ public class FirewallRuleVO implements Identity, FirewallRule {
public String getProtocol() { public String getProtocol() {
return protocol; return protocol;
} }
public void setState(State state) { public void setState(State state) {
this.state = state; this.state = state;
} }
@ -177,29 +176,29 @@ public class FirewallRuleVO implements Identity, FirewallRule {
public Purpose getPurpose() { public Purpose getPurpose() {
return purpose; return purpose;
} }
@Override @Override
public State getState() { public State getState() {
return state; return state;
} }
@Override @Override
public long getNetworkId() { public long getNetworkId() {
return networkId; return networkId;
} }
@Override @Override
public FirewallRuleType getType() { public FirewallRuleType getType() {
return type; return type;
} }
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
protected FirewallRuleVO() { protected FirewallRuleVO() {
this.uuid = UUID.randomUUID().toString(); this.uuid = UUID.randomUUID().toString();
} }
public FirewallRuleVO(String xId, Long ipAddressId, Integer portStart, Integer portEnd, String protocol, public FirewallRuleVO(String xId, Long ipAddressId, Integer portStart, Integer portEnd, String protocol,
long networkId, long accountId, long domainId, Purpose purpose, List<String> sourceCidrs, Integer icmpCode, long networkId, long accountId, long domainId, Purpose purpose, List<String> sourceCidrs, Integer icmpCode,
Integer icmpType, Long related, TrafficType trafficType) { Integer icmpType, Long related, TrafficType trafficType) {
@ -209,11 +208,11 @@ public class FirewallRuleVO implements Identity, FirewallRule {
} }
this.accountId = accountId; this.accountId = accountId;
this.domainId = domainId; this.domainId = domainId;
if (ipAddressId == null) { if (ipAddressId == null) {
assert (purpose == Purpose.NetworkACL) : "ipAddressId can be null for " + Purpose.NetworkACL + " only"; assert (purpose == Purpose.NetworkACL) : "ipAddressId can be null for " + Purpose.NetworkACL + " only";
} }
this.sourceIpAddressId = ipAddressId; this.sourceIpAddressId = ipAddressId;
this.sourcePortStart = portStart; this.sourcePortStart = portStart;
this.sourcePortEnd = portEnd; this.sourcePortEnd = portEnd;
@ -224,28 +223,28 @@ public class FirewallRuleVO implements Identity, FirewallRule {
this.icmpCode = icmpCode; this.icmpCode = icmpCode;
this.icmpType = icmpType; this.icmpType = icmpType;
this.sourceCidrs = sourceCidrs; this.sourceCidrs = sourceCidrs;
if (related != null) { if (related != null) {
assert (purpose == Purpose.Firewall) : "related field can be set for rule of purpose " + Purpose.Firewall + " only"; assert (purpose == Purpose.Firewall) : "related field can be set for rule of purpose " + Purpose.Firewall + " only";
} }
this.related = related; this.related = related;
this.uuid = UUID.randomUUID().toString(); this.uuid = UUID.randomUUID().toString();
this.type = FirewallRuleType.User; this.type = FirewallRuleType.User;
this.trafficType = trafficType; this.trafficType = trafficType;
} }
public FirewallRuleVO(String xId, long ipAddressId, int port, String protocol, long networkId, long accountId, public FirewallRuleVO(String xId, long ipAddressId, int port, String protocol, long networkId, long accountId,
long domainId, Purpose purpose, List<String> sourceCidrs, Integer icmpCode, Integer icmpType, Long related) { long domainId, Purpose purpose, List<String> sourceCidrs, Integer icmpCode, Integer icmpType, Long related) {
this(xId, ipAddressId, port, port, protocol, networkId, accountId, domainId, purpose, sourceCidrs, icmpCode, icmpType, related, null); this(xId, ipAddressId, port, port, protocol, networkId, accountId, domainId, purpose, sourceCidrs, icmpCode, icmpType, related, null);
} }
@Override @Override
public String toString() { public String toString() {
return new StringBuilder("Rule[").append(id).append("-").append(purpose).append("-").append(state).append("]").toString(); return new StringBuilder("Rule[").append(id).append("-").append(purpose).append("-").append(state).append("]").toString();
} }
@Override @Override
public Integer getIcmpCode() { public Integer getIcmpCode() {
return icmpCode; return icmpCode;
@ -260,18 +259,18 @@ public class FirewallRuleVO implements Identity, FirewallRule {
public Long getRelated() { public Long getRelated() {
return related; return related;
} }
@Override @Override
public String getUuid() { public String getUuid() {
return this.uuid; return this.uuid;
} }
public void setUuid(String uuid) { public void setUuid(String uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
public void setType(FirewallRuleType type) { public void setType(FirewallRuleType type) {
this.type = type; this.type = type;
} }
@Override @Override