Add Region APIs

This commit is contained in:
kishan 2012-07-03 13:06:21 -07:00
parent 6a1b0f3ecf
commit b5563e832e
7 changed files with 396 additions and 0 deletions

View File

@ -0,0 +1,40 @@
// 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 com.cloud.region;
import java.util.Date;
/**
*
*/
public interface Region {
public static enum State {
Up, Down
};
public long getId();
public String getName();
public void setName(String name);
public Region.State getStatus();
public Date getRemoved();
public String getEndPoint();
}

View File

@ -0,0 +1,30 @@
// 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 com.cloud.region;
import java.util.List;
import com.cloud.api.commands.ListRegionsCmd;
import com.cloud.user.Account;
public interface RegionService {
public Region addRegion(long id, String name, String endPoint);
public Region updateRegion(long id, String name, String endPoint);
public boolean removeRegion(long id);
public List<? extends Region> listRegions(ListRegionsCmd cmd);
}

View File

@ -0,0 +1,30 @@
// 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 com.cloud.region;
public interface RegionManager {
public boolean propogateAddResource();
public boolean propogateUpdateResource();
public boolean propogateDeleteResource();
public boolean addResource();
public boolean updateResource();
public boolean deleteResource();
public long getId();
public void setId(long id);
}

View File

@ -0,0 +1,149 @@
// 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 com.cloud.region;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.api.commands.ListRegionsCmd;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.region.dao.RegionDao;
import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
@Local(value = { RegionManager.class, RegionService.class })
public class RegionManagerImpl implements RegionManager, RegionService, Manager{
public static final Logger s_logger = Logger.getLogger(RegionManagerImpl.class);
@Inject
private RegionDao _regionDao;
private String _name;
private long _id = 1; //ToDo, get this from config
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_name = name;
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public boolean propogateAddResource() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean propogateUpdateResource() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean propogateDeleteResource() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean addResource() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean updateResource() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean deleteResource() {
// TODO Auto-generated method stub
return false;
}
@Override
public Region addRegion(long id, String name, String endPoint) {
RegionVO region = new RegionVO(id, name, endPoint);
return _regionDao.persist(region);
}
@Override
public Region updateRegion(long id, String name, String endPoint) {
RegionVO region = _regionDao.findById(id);
if(name != null){
region.setName(name);
}
if(endPoint != null){
region.setEndPoint(endPoint);
}
return region;
}
@Override
public boolean removeRegion(long id) {
RegionVO region = _regionDao.findById(id);
if(region != null){
return _regionDao.remove(id);
} else {
throw new InvalidParameterValueException("Failed to delete Region: " + id + ", Region not found");
}
}
public long getId() {
return _id;
}
public void setId(long _id) {
this._id = _id;
}
@Override
public List<RegionVO> listRegions(ListRegionsCmd cmd) {
if(cmd.getId() != null){
List<RegionVO> regions = new ArrayList<RegionVO>();
regions.add(_regionDao.findById(cmd.getId()));
return regions;
}
return _regionDao.listAll();
}
}

View File

@ -0,0 +1,95 @@
// 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 com.cloud.region;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.region.Region;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="region")
public class RegionVO implements Region{
@Id
@Column(name="id")
long id;
@Column(name="name")
String name;
@Column(name="end_point")
String endPoint;
@Column(name="status")
@Enumerated(value=EnumType.STRING)
Region.State status;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
public RegionVO() {
}
public RegionVO(long id, String name, String endPoint) {
this.id = id;
this.name = name;
this.endPoint = endPoint;
this.status = Region.State.Down;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Region.State getStatus() {
return status;
}
public void setStatus(Region.State status) {
this.status = status;
}
public Date getRemoved() {
return removed;
}
public String getEndPoint() {
return endPoint;
}
public void setEndPoint(String endPoint) {
this.endPoint = endPoint;
}
}

View File

@ -0,0 +1,19 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.region.dao;
import com.cloud.region.RegionVO;
import com.cloud.utils.db.GenericDao;
public interface RegionDao extends GenericDao<RegionVO, Long> {
}

View File

@ -0,0 +1,33 @@
// 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 com.cloud.region.dao;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.region.RegionVO;
import com.cloud.utils.db.GenericDaoBase;
@Local(value={RegionDao.class})
public class RegionDaoImpl extends GenericDaoBase<RegionVO, Long> implements RegionDao {
private static final Logger s_logger = Logger.getLogger(RegionDaoImpl.class);
public RegionDaoImpl(){
}
}