/**
*
* 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.airavata.registry.core.experiment.catalog.resources;
import org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils;
import org.apache.airavata.registry.core.experiment.catalog.ExperimentCatResource;
import org.apache.airavata.registry.core.experiment.catalog.ResourceType;
import org.apache.airavata.registry.core.experiment.catalog.model.ProcessResourceSchedule;
import org.apache.airavata.registry.cpi.RegistryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import java.util.List;
public class ProcessResourceScheduleResource extends AbstractExpCatResource {
private static final Logger logger = LoggerFactory.getLogger(ProcessResourceScheduleResource.class);
private String processId;
private String resourceHostId;
private Integer totalCpuCount;
private Integer nodeCount;
private Integer numberOfThreads;
private String queueName;
private Integer wallTimeLimit;
private Integer totalPhysicalMemory;
private String staticWorkingDir;
private String overrideLoginUserName;
private String overrideScratchLocation;
private String overrideAllocationProjectNumber;
public String getProcessId() {
return processId;
}
public void setProcessId(String processId) {
this.processId = processId;
}
public String getResourceHostId() {
return resourceHostId;
}
public void setResourceHostId(String resourceHostId) {
this.resourceHostId = resourceHostId;
}
public Integer getTotalCpuCount() {
return totalCpuCount;
}
public void setTotalCpuCount(Integer totalCpuCount) {
this.totalCpuCount = totalCpuCount;
}
public Integer getNodeCount() {
return nodeCount;
}
public void setNodeCount(Integer nodeCount) {
this.nodeCount = nodeCount;
}
public Integer getNumberOfThreads() {
return numberOfThreads;
}
public void setNumberOfThreads(Integer numberOfThreads) {
this.numberOfThreads = numberOfThreads;
}
public String getQueueName() {
return queueName;
}
public void setQueueName(String queueName) {
this.queueName = queueName;
}
public Integer getWallTimeLimit() {
return wallTimeLimit;
}
public void setWallTimeLimit(Integer wallTimeLimit) {
this.wallTimeLimit = wallTimeLimit;
}
public Integer getTotalPhysicalMemory() {
return totalPhysicalMemory;
}
public void setTotalPhysicalMemory(Integer totalPhysicalMemory) {
this.totalPhysicalMemory = totalPhysicalMemory;
}
public String getStaticWorkingDir() {
return staticWorkingDir;
}
public void setStaticWorkingDir(String staticWorkingDir) {
this.staticWorkingDir = staticWorkingDir;
}
public String getOverrideLoginUserName() {
return overrideLoginUserName;
}
public void setOverrideLoginUserName(String overrideLoginUserName) {
this.overrideLoginUserName = overrideLoginUserName;
}
public String getOverrideScratchLocation() {
return overrideScratchLocation;
}
public void setOverrideScratchLocation(String overrideScratchLocation) {
this.overrideScratchLocation = overrideScratchLocation;
}
public String getOverrideAllocationProjectNumber() {
return overrideAllocationProjectNumber;
}
public void setOverrideAllocationProjectNumber(String overrideAllocationProjectNumber) {
this.overrideAllocationProjectNumber = overrideAllocationProjectNumber;
}
public ExperimentCatResource create(ResourceType type) throws RegistryException {
logger.error("Unsupported resource type for process resource scheduling data resource.", new UnsupportedOperationException());
throw new UnsupportedOperationException();
}
public void remove(ResourceType type, Object name) throws RegistryException {
logger.error("Unsupported resource type for process resource scheduling data resource.", new UnsupportedOperationException());
throw new UnsupportedOperationException();
}
public ExperimentCatResource get(ResourceType type, Object name) throws RegistryException{
logger.error("Unsupported resource type for process resource scheduling data resource.", new UnsupportedOperationException());
throw new UnsupportedOperationException();
}
public List<ExperimentCatResource> get(ResourceType type) throws RegistryException{
logger.error("Unsupported resource type for process resource scheduling data resource.", new UnsupportedOperationException());
throw new UnsupportedOperationException();
}
public void save() throws RegistryException{
EntityManager em = null;
try {
if(processId == null){
throw new RegistryException("Does not have the process id");
}
em = ExpCatResourceUtils.getEntityManager();
ProcessResourceSchedule processResourceSchedule;
ProcessResourceSchedule existingSchedule = em.find(ProcessResourceSchedule.class, processId);
if (em.isOpen()) {
if (em.getTransaction().isActive()){
em.getTransaction().rollback();
}
em.close();
}
em = ExpCatResourceUtils.getEntityManager();
em.getTransaction().begin();
if(existingSchedule == null){
processResourceSchedule = new ProcessResourceSchedule();
}else {
processResourceSchedule = existingSchedule;
}
processResourceSchedule.setProcessId(processId);
processResourceSchedule.setResourceHostId(resourceHostId);
processResourceSchedule.setTotalCpuCount(totalCpuCount);
processResourceSchedule.setNodeCount(nodeCount);
processResourceSchedule.setNumberOfThreads(numberOfThreads);
processResourceSchedule.setQueueName(queueName);
processResourceSchedule.setWallTimeLimit(wallTimeLimit);
processResourceSchedule.setTotalPhysicalMemory(totalPhysicalMemory);
processResourceSchedule.setStaticWorkingDir(staticWorkingDir);
processResourceSchedule.setOverrideLoginUserName(overrideLoginUserName);
processResourceSchedule.setOverrideScratchLocation(overrideScratchLocation);
processResourceSchedule.setOverrideAllocationProjectNumber(overrideAllocationProjectNumber);
if (existingSchedule == null){
em.persist(processResourceSchedule);
}else {
em.merge(processResourceSchedule);
}
em.getTransaction().commit();
if (em.isOpen()) {
if (em.getTransaction().isActive()){
em.getTransaction().rollback();
}
em.close();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RegistryException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()){
em.getTransaction().rollback();
}
em.close();
}
}
}
}