Commit 8b15acaf authored by Robert Butora's avatar Robert Butora
Browse files

availability: adds check that datasets are mounted (try to read number of...

availability: adds check that datasets are mounted (try to read number of entries in the /srv/datasets dir)
parent fb52031a
Loading
Loading
Loading
Loading
+128 −92
Original line number Diff line number Diff line
@@ -28,22 +28,58 @@ import static java.nio.file.StandardCopyOption.*;
public class VlkbServletFile
    extends javax.servlet.http.HttpServlet
{
    // for logs and debug
   String className = this.getClass().getSimpleName();
	private static final SearchSettings settings = Settings.getInstance();
	private boolean available;

// VOSI
// String accessURL = null; // FIXME now read from MERGEURL later introduce own param
// String funcName = "vlkb_cutout"; // FIXME read from config file
	private String checkDatasets(String dirName)
	{
		Path dir = Paths.get(dirName);
      String note;
      try
      {
         int count = 0;
         try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir))
         {
            for (Path entry: stream) count++;
            note = dir.toString() + " has " + String.valueOf(count) + " entries";
				this.available = true;
         }
         catch (DirectoryIteratorException ex)
         {
            // I/O error during the iteration, the cause is an IOException
            throw ex.getCause();
         }
      }
      catch(Exception ex)
      {
         note = "error: " + ex.toString();
			this.available = false;
      }

	private static final String availStr = 
		return note;
	}

	private String availString()
	{
		String dirName = settings.fitsPaths.surveys();
		String datasetsAvail = checkDatasets(dirName);

		String availStr = 
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
			+ "<vosi:availability xmlns:vosi=\"http://www.ivoa.net/xml/VOSIAvailability/v1.0\">"
		+ " <vosi:available>true</vosi:available>"
			+ "<vosi:available> " +  ((this.available)?"true":"false") + " </vosi:available>"
			+ "<vosi:note> VLKB-SODA " + Version.asString + " is accepting queries </vosi:note>"
			+ "<vosi:note> " + datasetsAvail + " </vosi:note>"
			+ "</vosi:availability>";

	private String capsStr = null;

		return availStr;
	}



	private String capsStr = null;

	protected void SetCapsStr(String URL, String funcName)
	{
@@ -138,7 +174,7 @@ public class VlkbServletFile
			}
			else if(-1 != requestURL.lastIndexOf("/availability"))
			{
			writer.println(availStr);	
				writer.println(availString());	
			}
			// error FIXME what to do if none of above given ? e.g. misconfigured web.xml