Skip to content
Snippets Groups Projects
Commit 9a78569d authored by gwen-soleil's avatar gwen-soleil
Browse files

get attribute config from attribute, that was not correctly set when starting a new attribute.

parent b089e8b0
No related branches found
No related merge requests found
......@@ -7,6 +7,8 @@ import fr.soleil.tango.archiving.infra.tango.ArchivingConfig;
import fr.soleil.tango.archiving.infra.tango.ArchivingConfigs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tango.archiving.collector.data.TangoAttributeConfigCache;
import org.tango.archiving.collector.data.TangoAttributeConfigFetcher;
import org.tango.archiving.collector.infra.ArchivingInfra;
import org.tango.utils.DevFailedUtils;
......@@ -142,7 +144,12 @@ public class TangoCollectorService {
modes.setDifference(false);
modes.setRelative(false);
}
if (updateConfigurationInDb) {
// attribute config may not be set correctly from client, get it from attribute
config.setArchiver(archiverName);
TangoAttributeConfigFetcher attributeConfigFetcher = TangoAttributeConfigCache.getAttributeFetcher(config.getAttributeConfig().getFullName());
config.setAttributeConfig(attributeConfigFetcher.getConfig());
}
if (isDBInsertion) {
startAttribute(config);
} else {
......
/*
* Copyright (c) 2024.
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* gwenaelle.abeille@synchrotron-soleil.fr
*
* This software is a computer program whose purpose is to provide TANGO archived data through a GraphQL API.
*
* This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software.
* You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and
* INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users
* are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive
* licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to
* manipulate, and that also therefore means that it is reserved for developers and experienced professionals having
* in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and
* operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its
* terms.
*/
package org.tango.archiving.collector.data;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import fr.esrf.Tango.DevFailed;
import fr.esrf.TangoApi.ApiUtil;
import java.util.concurrent.TimeUnit;
public class TangoAttributeConfigCache {
private static final int MAXIMUM_CACHE_SIZE = 1000000;
private static final Cache<String, TangoAttributeConfigFetcher> ATTR_CACHE = Caffeine.newBuilder().maximumSize(MAXIMUM_CACHE_SIZE).expireAfterWrite(1, TimeUnit.HOURS).build();
public static TangoAttributeConfigFetcher getAttributeFetcher(String attributeName) {
return ATTR_CACHE.get(attributeName.toLowerCase(), k -> new TangoAttributeConfigFetcher(attributeName));
}
public static String getFullDeviceName(final String deviceName) {
String fullArchiverDeviceName;
if (!deviceName.matches(".*:.*/.*/.*/.*") && !deviceName.matches("tango://.*:.*/.*/.*/.*")) {
try {
fullArchiverDeviceName = "tango://" + ApiUtil.get_db_obj().get_tango_host() + "/" + deviceName;
} catch (DevFailed e) {
throw new RuntimeException(e);
}
} else {
fullArchiverDeviceName = deviceName;
}
return fullArchiverDeviceName;
}
}
/*
* Copyright (c) 2024.
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* gwenaelle.abeille@synchrotron-soleil.fr
*
* This software is a computer program whose purpose is to provide TANGO archived data through a GraphQL API.
*
* This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software.
* You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and
* INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users
* are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive
* licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to
* manipulate, and that also therefore means that it is reserved for developers and experienced professionals having
* in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and
* operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its
* terms.
*/
package org.tango.archiving.collector.data;
import fr.esrf.Tango.DevFailed;
import fr.esrf.TangoApi.ApiUtil;
import fr.esrf.TangoApi.AttributeInfoEx;
import fr.soleil.tango.archiving.config.AttributeConfig;
import fr.soleil.tango.archiving.config.AttributeParameters;
import fr.soleil.tango.archiving.exception.TangoTimeseriesException;
import fr.soleil.tango.archiving.infra.tango.ITangoAttributeFetcher;
import fr.soleil.tango.clientapi.TangoAttribute;
import org.tango.utils.TangoUtil;
import java.sql.Timestamp;
import java.time.Instant;
public class TangoAttributeConfigFetcher implements ITangoAttributeFetcher {
private final AttributeConfig config = new AttributeConfig();
private final AttributeParameters parameters = new AttributeParameters();
public TangoAttributeConfigFetcher(String attributeName) {
try {
TangoAttribute tangoAttribute = new TangoAttribute(attributeName);
config.setFullName(tangoAttribute.getName());
config.setFormat(tangoAttribute.getAttributeProxy().get_info().data_format.value());
config.setType(tangoAttribute.getDataType());
config.setWriteType(tangoAttribute.getWriteType().value());
// TODO: tango host at SOLEIL is always "tangodb:20xxx", should be different
config.setCsName(ApiUtil.get_db_obj().get_tango_host());
String fullAttributeName = TangoUtil.getfullAttributeNameForAttribute(tangoAttribute.getName());
String[] split = fullAttributeName.split("/");
config.setDomain(split[0]);
config.setFamily(split[1]);
config.setMember(split[2]);
config.setName(split[3]);
AttributeInfoEx info = tangoAttribute.getAttributeProxy().get_info_ex();
parameters.setDescription(info.description);
parameters.setArchivePeriod(info.events.arch_event.period);
parameters.setArchiveRelChange(info.events.arch_event.rel_change);
parameters.setArchiveAbsChange(info.events.arch_event.abs_change);
parameters.setLabel(info.label);
parameters.setUnit(info.unit);
parameters.setDescription(info.description);
parameters.setRecvTime(Timestamp.from(Instant.now()));
parameters.setStandardUnit(info.standard_unit);
parameters.setDisplayUnit(info.display_unit);
parameters.setFormat(info.format);
} catch (DevFailed devFailed) {
throw new TangoTimeseriesException(devFailed);
}
}
@Override
public AttributeConfig getConfig() {
return config;
}
@Override
public AttributeParameters getParameters() {
return parameters;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment