Search in sources :

Example 1 with TicketAdminService

use of org.irods.jargon.ticket.TicketAdminService in project metalnx-web by irods-contrib.

the class TicketServiceImpl method modify.

@Override
public DataGridTicket modify(DataGridTicket t) throws DataGridConnectionRefusedException, DataGridTicketException {
    logger.info("Modify ticket");
    if (t == null) {
        logger.error("Null ticket provided.");
        throw new DataGridTicketException("Null ticket instance");
    }
    if (t.getTicketString().isEmpty()) {
        logger.error("Ticket with empty string provided.");
        throw new DataGridTicketException("Ticket string missing");
    }
    String ticketString = t.getTicketString();
    DataGridTicket dgTicket;
    try {
        updateHostRestrictions(t);
        updateUserRestrictions(t);
        updateGroupRestrictions(t);
        TicketAdminService tas = irodsServices.getTicketAdminService();
        Ticket ticketUpdated = tas.compareGivenTicketToActualAndUpdateAsNeeded(convertDataGridTicketToTicket(t));
        dgTicket = convertTicketToDataGridTicket(ticketUpdated);
        dgTicket.setHosts(tas.listAllHostRestrictionsForSpecifiedTicket(ticketString, OFFSET));
        dgTicket.setUsers(tas.listAllUserRestrictionsForSpecifiedTicket(ticketString, OFFSET));
        dgTicket.setGroups(tas.listAllGroupRestrictionsForSpecifiedTicket(ticketString, OFFSET));
    } catch (JargonException e) {
        logger.error("Could not modify ticket");
        throw new DataGridTicketException(e.getMessage());
    }
    return dgTicket;
}
Also used : DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) Ticket(org.irods.jargon.ticket.Ticket) JargonException(org.irods.jargon.core.exception.JargonException) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) DataGridTicketException(com.emc.metalnx.core.domain.exceptions.DataGridTicketException) TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Example 2 with TicketAdminService

use of org.irods.jargon.ticket.TicketAdminService in project metalnx-web by irods-contrib.

the class TicketServiceImpl method updateGroupRestrictions.

private void updateGroupRestrictions(DataGridTicket t) throws JargonException, DataGridConnectionRefusedException {
    logger.info("Update group restrictions for ticket {}", t.getTicketString());
    String ticketString = t.getTicketString();
    TicketAdminService tas = irodsServices.getTicketAdminService();
    List<String> currGroups = tas.listAllGroupRestrictionsForSpecifiedTicket(ticketString, OFFSET);
    for (String group : t.getGroups()) {
        if (!group.isEmpty() && !currGroups.contains(group)) {
            tas.addTicketGroupRestriction(ticketString, group);
        }
    }
    for (String group : currGroups) {
        if (!t.getGroups().contains(group))
            tas.removeTicketGroupRestriction(ticketString, group);
    }
}
Also used : TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Example 3 with TicketAdminService

use of org.irods.jargon.ticket.TicketAdminService in project metalnx-web by irods-contrib.

the class TicketServiceImpl method updateHostRestrictions.

private void updateHostRestrictions(DataGridTicket t) throws JargonException, DataGridConnectionRefusedException {
    logger.info("Update host restrictions for ticket {}", t.getTicketString());
    String ticketString = t.getTicketString();
    TicketAdminService tas = irodsServices.getTicketAdminService();
    List<String> currHosts = tas.listAllHostRestrictionsForSpecifiedTicket(ticketString, OFFSET);
    for (String host : t.getHosts()) {
        if (!host.isEmpty() && !currHosts.contains(host)) {
            tas.addTicketHostRestriction(ticketString, host);
        }
    }
    for (String host : currHosts) {
        if (!t.getHosts().contains(host))
            tas.removeTicketHostRestriction(ticketString, host);
    }
}
Also used : TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Example 4 with TicketAdminService

use of org.irods.jargon.ticket.TicketAdminService in project metalnx-web by irods-contrib.

the class TicketServiceImpl method find.

@Override
public DataGridTicket find(String ticketId) throws DataGridConnectionRefusedException, DataGridTicketNotFoundException {
    logger.info("Find ticket {}", ticketId);
    DataGridTicket dgTicket = null;
    TicketAdminService tas = irodsServices.getTicketAdminService();
    try {
        Ticket t = tas.getTicketForSpecifiedTicketString(ticketId);
        dgTicket = convertTicketToDataGridTicket(t);
        dgTicket.setHosts(tas.listAllHostRestrictionsForSpecifiedTicket(ticketId, OFFSET));
        dgTicket.setUsers(tas.listAllUserRestrictionsForSpecifiedTicket(ticketId, OFFSET));
        dgTicket.setGroups(tas.listAllGroupRestrictionsForSpecifiedTicket(ticketId, OFFSET));
    } catch (DataNotFoundException e) {
        throw new DataGridTicketNotFoundException("Ticket does not exist");
    } catch (JargonException e) {
        logger.error("Could not find ticket with string: {}", ticketId);
    }
    return dgTicket;
}
Also used : DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) Ticket(org.irods.jargon.ticket.Ticket) DataNotFoundException(org.irods.jargon.core.exception.DataNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridTicket(com.emc.metalnx.core.domain.entity.DataGridTicket) DataGridTicketNotFoundException(com.emc.metalnx.core.domain.exceptions.DataGridTicketNotFoundException) TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Example 5 with TicketAdminService

use of org.irods.jargon.ticket.TicketAdminService in project metalnx-web by irods-contrib.

the class TicketServiceImpl method create.

@Override
public String create(DataGridTicket dgTicket) throws DataGridConnectionRefusedException, DataGridTicketException {
    logger.info("Create ticket");
    if (dgTicket == null) {
        logger.info("Could not create ticket: Null ticket provided.");
        throw new DataGridTicketException("Could not create ticket: null ticket provided.");
    }
    if (dgTicket.getPath().isEmpty()) {
        logger.info("Could not create ticket: Ticket with no path.");
        throw new DataGridTicketException("Could not create ticket: path is empty");
    }
    TicketCreateModeEnum ticketType = TicketCreateModeEnum.UNKNOWN;
    if (dgTicket.getType() == DataGridTicket.TicketType.READ)
        ticketType = TicketCreateModeEnum.READ;
    if (dgTicket.getType() == DataGridTicket.TicketType.WRITE)
        ticketType = TicketCreateModeEnum.WRITE;
    String path = dgTicket.getPath();
    int idxOfSeparator = path.lastIndexOf(GRID_FILE_SEPARATOR);
    String parentPath = path.substring(0, idxOfSeparator);
    String item = path.substring(idxOfSeparator + 1, path.length());
    String ticketString = "";
    try {
        IRODSFile irodsFile = irodsServices.getIRODSFileFactory().instanceIRODSFile(parentPath, item);
        TicketAdminService tas = irodsServices.getTicketAdminService();
        ticketString = tas.createTicket(ticketType, irodsFile, dgTicket.getTicketString());
        // set ticket string created by the grid
        dgTicket.setTicketString(ticketString);
        modify(dgTicket);
    } catch (JargonException e) {
        logger.error("Could not create a ticket: {}", e);
        throw new DataGridTicketException(e.getMessage());
    }
    return ticketString;
}
Also used : TicketCreateModeEnum(org.irods.jargon.ticket.packinstr.TicketCreateModeEnum) JargonException(org.irods.jargon.core.exception.JargonException) DataGridTicketException(com.emc.metalnx.core.domain.exceptions.DataGridTicketException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) TicketAdminService(org.irods.jargon.ticket.TicketAdminService)

Aggregations

TicketAdminService (org.irods.jargon.ticket.TicketAdminService)9 JargonException (org.irods.jargon.core.exception.JargonException)6 DataGridTicket (com.emc.metalnx.core.domain.entity.DataGridTicket)3 Ticket (org.irods.jargon.ticket.Ticket)3 DataGridTicketException (com.emc.metalnx.core.domain.exceptions.DataGridTicketException)2 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridTicketNotFoundException (com.emc.metalnx.core.domain.exceptions.DataGridTicketNotFoundException)1 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 DataNotFoundException (org.irods.jargon.core.exception.DataNotFoundException)1 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)1 TicketServiceFactory (org.irods.jargon.ticket.TicketServiceFactory)1 TicketServiceFactoryImpl (org.irods.jargon.ticket.TicketServiceFactoryImpl)1 TicketCreateModeEnum (org.irods.jargon.ticket.packinstr.TicketCreateModeEnum)1