/******************************************************************************* * Copyright (c) 2011 The Board of Trustees of the Leland Stanford Junior University * as Operator of the SLAC National Accelerator Laboratory. * Copyright (c) 2011 Brookhaven National Laboratory. * EPICS archiver appliance is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. *******************************************************************************/ package org.epics.archiverappliance.etl.bpl; import java.io.IOException; import java.io.PrintWriter; import java.sql.Timestamp; import java.util.HashMap; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.epics.archiverappliance.common.BPLAction; import org.epics.archiverappliance.common.TimeUtils; import org.epics.archiverappliance.config.ConfigService; import org.epics.archiverappliance.config.PVTypeInfo; import org.epics.archiverappliance.config.StoragePluginURLParser; import org.epics.archiverappliance.etl.ETLContext; import org.epics.archiverappliance.etl.ETLInfo; import org.epics.archiverappliance.etl.ETLSource; import org.epics.archiverappliance.utils.ui.MimeTypeConstants; import org.json.simple.JSONValue; /** * consolidate PB files for one pv before one storage * @author Luofeng Li * */ public class DeletePV implements BPLAction { private static final Logger logger = Logger.getLogger(DeletePV.class); @Override public void execute(HttpServletRequest req, HttpServletResponse resp, ConfigService configService) throws IOException { String pvName = req.getParameter("pv"); if(pvName == null || pvName.equals("")) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } boolean deleteData = false; String deleteDataStr=req.getParameter("deleteData"); if(deleteDataStr!=null && !deleteDataStr.equals("")) { deleteData = Boolean.parseBoolean(deleteDataStr); } PVTypeInfo typeInfo = configService.getTypeInfoForPV(pvName); if(typeInfo == null) { logger.debug("Unable to find typeinfo for PV..."); resp.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } HashMap<String, Object> infoValues = new HashMap<String, Object>(); resp.setContentType(MimeTypeConstants.APPLICATION_JSON); try (PrintWriter out = resp.getWriter()) { // Remove any ETL jobs from the runtime state. configService.getETLLookup().deleteETLJobs(pvName); if(deleteData) { try(ETLContext context = new ETLContext()) { Timestamp tenYearsLaterTimeStamp = TimeUtils.convertFromEpochSeconds(TimeUtils.getCurrentEpochSeconds()+10*365*24*60*60, 0); for(String dataSource : typeInfo.getDataStores()) { try { ETLSource etlSource = StoragePluginURLParser.parseETLSource(dataSource, configService); if(etlSource == null) continue; List<ETLInfo> infos = etlSource.getETLStreams(pvName, tenYearsLaterTimeStamp, context); if(infos == null) continue; for(ETLInfo info : infos) { logger.debug("Marking src " + info.getKey() + " for deletion when stopping archiving pv " + pvName); etlSource.markForDeletion(info, context); } } catch(Exception ex) { logger.debug("Exception deleting data for PV " + pvName, ex); } } } } infoValues.put("status", "ok"); infoValues.put("desc", "Successfully removed PV " + pvName + " from the cluster"); out.println(JSONValue.toJSONString(infoValues)); return; } } }