Search in sources :

Example 1 with com.viaversion.viaversion.protocols.protocol1_9to1_8.storage

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage in project airavata-mft by apache.

the class FileBasedResourceBackend method getLocalStorage.

@Override
public Optional<LocalStorage> getLocalStorage(LocalStorageGetRequest request) throws Exception {
    JSONParser jsonParser = new JSONParser();
    InputStream inputStream = FileBasedResourceBackend.class.getClassLoader().getResourceAsStream(storageFile);
    try (InputStreamReader reader = new InputStreamReader(inputStream)) {
        Object obj = jsonParser.parse(reader);
        JSONArray storageList = (JSONArray) obj;
        List<LocalStorage> localStorages = (List<LocalStorage>) storageList.stream().filter(storage -> "LOCAL".equals(((JSONObject) storage).get("type").toString())).map(storage -> {
            JSONObject s = (JSONObject) storage;
            LocalStorage st = LocalStorage.newBuilder().setStorageId(s.get("storageId").toString()).setAgentId(s.get("agentId").toString()).build();
            return st;
        }).collect(Collectors.toList());
        return localStorages.stream().filter(s -> request.getStorageId().equals(s.getStorageId())).findFirst();
    }
}
Also used : ResourceBackend(org.apache.airavata.mft.resource.server.backend.ResourceBackend) Logger(org.slf4j.Logger) org.apache.airavata.mft.resource.stubs.azure.storage(org.apache.airavata.mft.resource.stubs.azure.storage) JSONParser(org.json.simple.parser.JSONParser) org.apache.airavata.mft.resource.stubs.common(org.apache.airavata.mft.resource.stubs.common) org.apache.airavata.mft.resource.stubs.box.storage(org.apache.airavata.mft.resource.stubs.box.storage) org.apache.airavata.mft.resource.stubs.scp.storage(org.apache.airavata.mft.resource.stubs.scp.storage) org.apache.airavata.mft.resource.stubs.ftp.storage(org.apache.airavata.mft.resource.stubs.ftp.storage) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) org.apache.airavata.mft.resource.stubs.gcs.storage(org.apache.airavata.mft.resource.stubs.gcs.storage) JSONArray(org.json.simple.JSONArray) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) List(java.util.List) org.apache.airavata.mft.storage.stubs.storagesecret(org.apache.airavata.mft.storage.stubs.storagesecret) JSONObject(org.json.simple.JSONObject) org.apache.airavata.mft.resource.stubs.s3.storage(org.apache.airavata.mft.resource.stubs.s3.storage) org.apache.airavata.mft.resource.stubs.dropbox.storage(org.apache.airavata.mft.resource.stubs.dropbox.storage) org.apache.airavata.mft.resource.stubs.local.storage(org.apache.airavata.mft.resource.stubs.local.storage) Optional(java.util.Optional) InputStream(java.io.InputStream) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.simple.JSONObject) InputStream(java.io.InputStream) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) List(java.util.List)

Example 2 with com.viaversion.viaversion.protocols.protocol1_9to1_8.storage

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage in project airavata-mft by apache.

the class FileBasedResourceBackend method getSCPStorage.

@Override
public Optional<SCPStorage> getSCPStorage(SCPStorageGetRequest request) throws Exception {
    InputStream inputStream = FileBasedResourceBackend.class.getClassLoader().getResourceAsStream(storageFile);
    JSONParser jsonParser = new JSONParser();
    try (InputStreamReader reader = new InputStreamReader(inputStream)) {
        Object obj = jsonParser.parse(reader);
        JSONArray resourceList = (JSONArray) obj;
        List<SCPStorage> scpStorages = (List<SCPStorage>) resourceList.stream().filter(resource -> "SCP".equals(((JSONObject) resource).get("type").toString())).map(st -> {
            JSONObject s = (JSONObject) st;
            SCPStorage storage = SCPStorage.newBuilder().setStorageId(s.get("storageId").toString()).setHost(s.get("host").toString()).setPort(Integer.parseInt(s.get("port").toString())).build();
            return storage;
        }).collect(Collectors.toList());
        return scpStorages.stream().filter(s -> request.getStorageId().equals(s.getStorageId())).findFirst();
    }
}
Also used : ResourceBackend(org.apache.airavata.mft.resource.server.backend.ResourceBackend) Logger(org.slf4j.Logger) org.apache.airavata.mft.resource.stubs.azure.storage(org.apache.airavata.mft.resource.stubs.azure.storage) JSONParser(org.json.simple.parser.JSONParser) org.apache.airavata.mft.resource.stubs.common(org.apache.airavata.mft.resource.stubs.common) org.apache.airavata.mft.resource.stubs.box.storage(org.apache.airavata.mft.resource.stubs.box.storage) org.apache.airavata.mft.resource.stubs.scp.storage(org.apache.airavata.mft.resource.stubs.scp.storage) org.apache.airavata.mft.resource.stubs.ftp.storage(org.apache.airavata.mft.resource.stubs.ftp.storage) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) org.apache.airavata.mft.resource.stubs.gcs.storage(org.apache.airavata.mft.resource.stubs.gcs.storage) JSONArray(org.json.simple.JSONArray) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) List(java.util.List) org.apache.airavata.mft.storage.stubs.storagesecret(org.apache.airavata.mft.storage.stubs.storagesecret) JSONObject(org.json.simple.JSONObject) org.apache.airavata.mft.resource.stubs.s3.storage(org.apache.airavata.mft.resource.stubs.s3.storage) org.apache.airavata.mft.resource.stubs.dropbox.storage(org.apache.airavata.mft.resource.stubs.dropbox.storage) org.apache.airavata.mft.resource.stubs.local.storage(org.apache.airavata.mft.resource.stubs.local.storage) Optional(java.util.Optional) InputStream(java.io.InputStream) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.simple.JSONObject) InputStream(java.io.InputStream) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) List(java.util.List)

Example 3 with com.viaversion.viaversion.protocols.protocol1_9to1_8.storage

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage in project airavata-mft by apache.

the class FileBasedResourceBackend method getDropboxStorage.

@Override
public Optional<DropboxStorage> getDropboxStorage(DropboxStorageGetRequest request) throws Exception {
    JSONParser jsonParser = new JSONParser();
    InputStream inputStream = FileBasedResourceBackend.class.getClassLoader().getResourceAsStream(resourceFile);
    try (InputStreamReader reader = new InputStreamReader(inputStream)) {
        Object obj = jsonParser.parse(reader);
        JSONArray storageList = (JSONArray) obj;
        List<DropboxStorage> dropboxStorages = (List<DropboxStorage>) storageList.stream().filter(resource -> "DROPBOX".equals(((JSONObject) resource).get("type").toString())).map(resource -> {
            JSONObject r = (JSONObject) resource;
            String resourcePath = r.get("resourcePath").toString();
            resourcePath = resourcePath.startsWith("/") ? resourcePath : "/" + resourcePath;
            DropboxStorage storage = DropboxStorage.newBuilder().setStorageId(((JSONObject) r.get("dropboxStorage")).get("storageId").toString()).build();
            return storage;
        }).collect(Collectors.toList());
        return dropboxStorages.stream().filter(s -> request.getStorageId().equals(s.getStorageId())).findFirst();
    }
}
Also used : ResourceBackend(org.apache.airavata.mft.resource.server.backend.ResourceBackend) Logger(org.slf4j.Logger) org.apache.airavata.mft.resource.stubs.azure.storage(org.apache.airavata.mft.resource.stubs.azure.storage) JSONParser(org.json.simple.parser.JSONParser) org.apache.airavata.mft.resource.stubs.common(org.apache.airavata.mft.resource.stubs.common) org.apache.airavata.mft.resource.stubs.box.storage(org.apache.airavata.mft.resource.stubs.box.storage) org.apache.airavata.mft.resource.stubs.scp.storage(org.apache.airavata.mft.resource.stubs.scp.storage) org.apache.airavata.mft.resource.stubs.ftp.storage(org.apache.airavata.mft.resource.stubs.ftp.storage) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) org.apache.airavata.mft.resource.stubs.gcs.storage(org.apache.airavata.mft.resource.stubs.gcs.storage) JSONArray(org.json.simple.JSONArray) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) List(java.util.List) org.apache.airavata.mft.storage.stubs.storagesecret(org.apache.airavata.mft.storage.stubs.storagesecret) JSONObject(org.json.simple.JSONObject) org.apache.airavata.mft.resource.stubs.s3.storage(org.apache.airavata.mft.resource.stubs.s3.storage) org.apache.airavata.mft.resource.stubs.dropbox.storage(org.apache.airavata.mft.resource.stubs.dropbox.storage) org.apache.airavata.mft.resource.stubs.local.storage(org.apache.airavata.mft.resource.stubs.local.storage) Optional(java.util.Optional) InputStream(java.io.InputStream) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.simple.JSONObject) InputStream(java.io.InputStream) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) List(java.util.List)

Example 4 with com.viaversion.viaversion.protocols.protocol1_9to1_8.storage

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage in project ViaVersion by ViaVersion.

the class BungeeServerHandler method checkServerChange.

public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
    if (user == null)
        return;
    // Handle server/version change
    if (user.has(BungeeStorage.class)) {
        BungeeStorage storage = user.get(BungeeStorage.class);
        ProxiedPlayer player = storage.getPlayer();
        if (e.getServer() != null) {
            if (!e.getServer().getInfo().getName().equals(storage.getCurrentServer())) {
                // Clear auto-team
                EntityTracker1_9 oldEntityTracker = user.getEntityTracker(Protocol1_9To1_8.class);
                if (oldEntityTracker != null) {
                    if (oldEntityTracker.isAutoTeam() && oldEntityTracker.isTeamExists()) {
                        oldEntityTracker.sendTeamPacket(false, true);
                    }
                }
                String serverName = e.getServer().getInfo().getName();
                storage.setCurrentServer(serverName);
                int protocolId = ProtocolDetectorService.getProtocolId(serverName);
                if (protocolId <= ProtocolVersion.v1_8.getVersion()) {
                    // 1.8 doesn't have BossBar packet
                    if (storage.getBossbar() != null) {
                        // This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
                        if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
                            for (UUID uuid : storage.getBossbar()) {
                                PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.BOSSBAR, null, user);
                                wrapper.write(Type.UUID, uuid);
                                // remove
                                wrapper.write(Type.VAR_INT, 1);
                                wrapper.send(Protocol1_9To1_8.class);
                            }
                        }
                        storage.getBossbar().clear();
                    }
                }
                ProtocolInfo info = user.getProtocolInfo();
                int previousServerProtocol = info.getServerProtocolVersion();
                // Refresh the pipes
                List<ProtocolPathEntry> protocolPath = Via.getManager().getProtocolManager().getProtocolPath(info.getProtocolVersion(), protocolId);
                ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
                user.clearStoredObjects();
                pipeline.cleanPipes();
                if (protocolPath == null) {
                    // TODO Check Bungee Supported Protocols? *shrugs*
                    protocolId = info.getProtocolVersion();
                } else {
                    List<Protocol> protocols = new ArrayList<>(protocolPath.size());
                    for (ProtocolPathEntry entry : protocolPath) {
                        protocols.add(entry.protocol());
                    }
                    pipeline.add(protocols);
                }
                info.setServerProtocolVersion(protocolId);
                // Add version-specific base Protocol
                pipeline.add(Via.getManager().getProtocolManager().getBaseProtocol(protocolId));
                // Workaround 1.13 server change
                int id1_13 = ProtocolVersion.v1_13.getVersion();
                boolean toNewId = previousServerProtocol < id1_13 && protocolId >= id1_13;
                boolean toOldId = previousServerProtocol >= id1_13 && protocolId < id1_13;
                if (previousServerProtocol != -1 && (toNewId || toOldId)) {
                    Collection<String> registeredChannels = (Collection<String>) getRegisteredChannels.invoke(e.getPlayer().getPendingConnection());
                    if (!registeredChannels.isEmpty()) {
                        Collection<String> newChannels = new HashSet<>();
                        for (Iterator<String> iterator = registeredChannels.iterator(); iterator.hasNext(); ) {
                            String channel = iterator.next();
                            String oldChannel = channel;
                            if (toNewId) {
                                channel = InventoryPackets.getNewPluginChannelId(channel);
                            } else {
                                channel = InventoryPackets.getOldPluginChannelId(channel);
                            }
                            if (channel == null) {
                                iterator.remove();
                                continue;
                            }
                            if (!oldChannel.equals(channel)) {
                                iterator.remove();
                                newChannels.add(channel);
                            }
                        }
                        registeredChannels.addAll(newChannels);
                    }
                    PluginMessage brandMessage = (PluginMessage) getBrandMessage.invoke(e.getPlayer().getPendingConnection());
                    if (brandMessage != null) {
                        String channel = brandMessage.getTag();
                        if (toNewId) {
                            channel = InventoryPackets.getNewPluginChannelId(channel);
                        } else {
                            channel = InventoryPackets.getOldPluginChannelId(channel);
                        }
                        if (channel != null) {
                            brandMessage.setTag(channel);
                        }
                    }
                }
                user.put(storage);
                user.setActive(protocolPath != null);
                // Init all protocols TODO check if this can get moved up to the previous for loop, and doesn't require the pipeline to already exist.
                for (Protocol protocol : pipeline.pipes()) {
                    protocol.init(user);
                }
                EntityTracker1_9 newTracker = user.getEntityTracker(Protocol1_9To1_8.class);
                if (newTracker != null) {
                    if (Via.getConfig().isAutoTeam()) {
                        String currentTeam = null;
                        for (Team team : player.getScoreboard().getTeams()) {
                            if (team.getPlayers().contains(info.getUsername())) {
                                currentTeam = team.getName();
                            }
                        }
                        // Reinitialize auto-team
                        newTracker.setAutoTeam(true);
                        if (currentTeam == null) {
                            // Send auto-team as it was cleared above
                            newTracker.sendTeamPacket(true, true);
                            newTracker.setCurrentTeam("viaversion");
                        } else {
                            // Auto-team will be sent when bungee send remove packet
                            newTracker.setAutoTeam(Via.getConfig().isAutoTeam());
                            newTracker.setCurrentTeam(currentTeam);
                        }
                    }
                }
                Object wrapper = channelWrapper.get(player);
                setVersion.invoke(wrapper, protocolId);
                Object entityMap = getEntityMap.invoke(null, protocolId);
                entityRewrite.set(player, entityMap);
            }
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ProtocolPathEntry(com.viaversion.viaversion.api.protocol.ProtocolPathEntry) EntityTracker1_9(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9) BungeeStorage(com.viaversion.viaversion.bungee.storage.BungeeStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ProtocolPipeline(com.viaversion.viaversion.api.protocol.ProtocolPipeline) PluginMessage(net.md_5.bungee.protocol.packet.PluginMessage) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) Team(net.md_5.bungee.api.score.Team) StorableObject(com.viaversion.viaversion.api.connection.StorableObject) Protocol(com.viaversion.viaversion.api.protocol.Protocol)

Example 5 with com.viaversion.viaversion.protocols.protocol1_9to1_8.storage

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage in project iaf by ibissource.

the class TibetView method initBean.

/**
 * @see nl.nn.testtool.echo2.Echo2Application#initBean()
 */
@Override
public void initBean(BeanParent beanParent) {
    super.initBean(beanParent);
    Storage storage = (Storage) getStorage();
    try {
        storage.configure();
    } catch (ConfigurationException e) {
        System.out.println("Could not configure storage: (" + ClassUtils.nameOf(e) + ")" + e.getMessage());
    }
    storage.setSecurityContext(getEcho2Application());
}
Also used : Storage(nl.nn.ibistesttool.tibet2.Storage) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

Optional (java.util.Optional)9 ResourceBackend (org.apache.airavata.mft.resource.server.backend.ResourceBackend)9 org.apache.airavata.mft.resource.stubs.azure.storage (org.apache.airavata.mft.resource.stubs.azure.storage)9 org.apache.airavata.mft.resource.stubs.box.storage (org.apache.airavata.mft.resource.stubs.box.storage)9 org.apache.airavata.mft.resource.stubs.common (org.apache.airavata.mft.resource.stubs.common)9 org.apache.airavata.mft.resource.stubs.dropbox.storage (org.apache.airavata.mft.resource.stubs.dropbox.storage)9 org.apache.airavata.mft.resource.stubs.ftp.storage (org.apache.airavata.mft.resource.stubs.ftp.storage)9 org.apache.airavata.mft.resource.stubs.gcs.storage (org.apache.airavata.mft.resource.stubs.gcs.storage)9 org.apache.airavata.mft.resource.stubs.local.storage (org.apache.airavata.mft.resource.stubs.local.storage)9 org.apache.airavata.mft.resource.stubs.s3.storage (org.apache.airavata.mft.resource.stubs.s3.storage)9 org.apache.airavata.mft.resource.stubs.scp.storage (org.apache.airavata.mft.resource.stubs.scp.storage)9 org.apache.airavata.mft.storage.stubs.storagesecret (org.apache.airavata.mft.storage.stubs.storagesecret)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 InputStreamReader (java.io.InputStreamReader)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 JSONArray (org.json.simple.JSONArray)8