Skip to content

Commit

Permalink
Changes from Wed 10/30/2019 15:36:14.36
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftek committed Oct 30, 2019
1 parent 5fb4ba2 commit 3b8c25a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2018 CS ROMANIA
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see http://www.gnu.org/licenses/
*/
package org.esa.sen2agri.commons;

import org.esa.sen2agri.entities.Site;
import org.esa.sen2agri.entities.enums.Satellite;
import ro.cs.tao.datasource.DataSourceTopic;
import ro.cs.tao.messaging.TaskProgress;

import java.util.Objects;

/**
* @author Cosmin Cara
*/
public class DownloadProgress extends TaskProgress {
private String siteName;
private int siteId;
private String satelliteName;

public DownloadProgress(String name) {
super(name, DataSourceTopic.PRODUCT_PROGRESS.getTag());
}

public DownloadProgress(String name, Site site, Satellite satellite, double progress) {
this(name);
if (site != null) {
this.siteName = site.getName();
this.siteId = site.getId();
}
if (satellite != null) {
this.satelliteName = satellite.name();
}
this.progress = progress;
}

public String getSiteName() { return siteName; }

public int getSiteId() { return siteId; }

public String getSatelliteName() { return satelliteName; }

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
DownloadProgress that = (DownloadProgress) o;
return siteId == that.siteId &&
siteName.equals(that.siteName) &&
satelliteName.equals(that.satelliteName);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), siteName, siteId, satelliteName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.esa.sen2agri.services;

import org.esa.sen2agri.commons.TaskProgress;
import org.esa.sen2agri.commons.DownloadProgress;
import org.esa.sen2agri.entities.DataSourceConfiguration;
import org.esa.sen2agri.web.beans.Query;
import ro.cs.tao.datasource.ProductStatusListener;
Expand Down Expand Up @@ -64,7 +64,7 @@ List<EOProduct> download(short siteId, List<EOProduct> products, Set<String> til
* If the <code>siteId</code> parameter value is 0, it returns information about all the downloads in progress.
* @param siteId The site identifier
*/
List<TaskProgress> getDownloadsInProgress(short siteId);
List<DownloadProgress> getDownloadsInProgress(short siteId);
/**
* Stops the downloads and marks the downloader disabled for the specific site.
* If the <code>siteId</code> parameter value is 0, it stops all the downloads and marks the downloader as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
@Service("downloadService")
public class DownloadServiceImpl extends Notifiable implements DownloadService {

private static final Map<String, TaskProgress> downloadsInProgress = Collections.synchronizedMap(new LinkedHashMap<>());
private static final Map<String, DownloadProgress> downloadsInProgress = Collections.synchronizedMap(new LinkedHashMap<>());
//private static final Map<String, Key<Site, Satellite>> infoCache = Collections.synchronizedMap(new HashMap<>());
private static final Map<Short, Long> estimatedProductCount = Collections.synchronizedMap(new HashMap<>());
private final Map<Tuple<Short, Satellite>, List<DataSourceComponent>> querySiteDataSources;
Expand Down Expand Up @@ -275,8 +275,8 @@ public List<EOProduct> download(short siteId, List<EOProduct> products, Set<Stri
}

@Override
public List<TaskProgress> getDownloadsInProgress(short siteId) {
List<TaskProgress> tasks = new ArrayList<>();
public List<DownloadProgress> getDownloadsInProgress(short siteId) {
List<DownloadProgress> tasks = new ArrayList<>();
if (siteId > 0) {
dwnSiteDataSources.entrySet().stream()
.filter(e -> siteId == e.getKey().getKeyOne())
Expand Down Expand Up @@ -485,7 +485,7 @@ protected void onMessageReceived(Message data) {
satellite = productInfo.getKeyTwo();
}
downloadsInProgress.put(taskName,
new TaskProgress(taskName, site, satellite, 0));
new DownloadProgress(taskName, site, satellite, 0));
} else if (data instanceof ActivityEndMessage) {
downloadsInProgress.remove(((ActivityEndMessage) data).getTaskName());
} else if (data instanceof SubActivityStartMessage) {
Expand All @@ -497,19 +497,19 @@ protected void onMessageReceived(Message data) {
satellite = productInfo.getKeyTwo();
}
downloadsInProgress.put(taskName,
new TaskProgress(taskName, site, satellite, mainProgress));
new DownloadProgress(taskName, site, satellite, mainProgress));
}
} else if (data instanceof SubActivityEndMessage) {
final String mainTask = ((SubActivityEndMessage) data).getTaskName();
final TaskProgress taskProgress = downloadsInProgress.get(mainTask);
if (taskProgress != null) {
double mainProgress = taskProgress.getProgress();
final DownloadProgress downloadProgress = downloadsInProgress.get(mainTask);
if (downloadProgress != null) {
double mainProgress = downloadProgress.getProgress();
if ((productInfo = getProductInfo(mainTask)) != null) {
site = productInfo.getKeyOne();
satellite = productInfo.getKeyTwo();
}
downloadsInProgress.put(mainTask,
new TaskProgress(mainTask, site, satellite, mainProgress));
new DownloadProgress(mainTask, site, satellite, mainProgress));
}
} else if (data instanceof SubActivityProgressMessage) {
SubActivityProgressMessage casted = (SubActivityProgressMessage) data;
Expand All @@ -518,15 +518,15 @@ protected void onMessageReceived(Message data) {
site = productInfo.getKeyOne();
satellite = productInfo.getKeyTwo();
}
downloadsInProgress.put(mainTask, new TaskProgress(mainTask, site, satellite, casted.getTaskProgress()));
downloadsInProgress.put(mainTask, new DownloadProgress(mainTask, site, satellite, casted.getTaskProgress()));
} else if (data instanceof ActivityProgressMessage) {
ActivityProgressMessage casted = (ActivityProgressMessage) data;
final String mainTask = casted.getTaskName();
if ((productInfo = getProductInfo(mainTask)) != null) {
site = productInfo.getKeyOne();
satellite = productInfo.getKeyTwo();
}
downloadsInProgress.put(mainTask, new TaskProgress(mainTask, site, satellite, casted.getProgress()));
downloadsInProgress.put(mainTask, new DownloadProgress(mainTask, site, satellite, casted.getProgress()));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.esa.sen2agri.web;

import org.esa.sen2agri.commons.TaskProgress;
import org.esa.sen2agri.commons.DownloadProgress;
import org.esa.sen2agri.entities.enums.Satellite;
import org.esa.sen2agri.services.DownloadService;
import org.esa.sen2agri.services.ScheduleManager;
Expand Down Expand Up @@ -52,8 +52,8 @@ public class DownloadController extends ControllerBase {
* Returns information about all the downloads in progress.
*/
@RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<List<TaskProgress>> getInProgress() {
List<TaskProgress> tasks = downloadService.getDownloadsInProgress((short) 0);
public ResponseEntity<List<DownloadProgress>> getInProgress() {
List<DownloadProgress> tasks = downloadService.getDownloadsInProgress((short) 0);
if (tasks == null || tasks.isEmpty()) {
return new ResponseEntity<>(HttpStatus.OK);
}
Expand All @@ -65,8 +65,8 @@ public ResponseEntity<List<TaskProgress>> getInProgress() {
* @param siteId The site identifier
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<List<TaskProgress>> getInProgress(@PathVariable("id") short siteId) {
List<TaskProgress> tasks = downloadService.getDownloadsInProgress(siteId);
public ResponseEntity<List<DownloadProgress>> getInProgress(@PathVariable("id") short siteId) {
List<DownloadProgress> tasks = downloadService.getDownloadsInProgress(siteId);
if (tasks == null || tasks.isEmpty()) {
return new ResponseEntity<>(HttpStatus.OK);
}
Expand Down

0 comments on commit 3b8c25a

Please sign in to comment.