Search in sources :

Example 1 with RandomStringUtils.randomAlphabetic

use of org.apache.commons.lang3.RandomStringUtils.randomAlphabetic in project pulsar-io-cloud-storage by streamnative.

the class BytesFormatTest method testStringWriter.

@Test
public void testStringWriter() throws Exception {
    TopicName topic = TopicName.get("test-string" + RandomStringUtils.randomAlphabetic(5));
    PulsarAdmin pulsarAdmin = PulsarAdmin.builder().serviceHttpUrl(getAdminUrl()).build();
    pulsarAdmin.topics().createPartitionedTopic(topic.toString(), 1);
    pulsarAdmin.topics().createSubscription(topic.toString(), "test", MessageId.earliest);
    pulsarAdmin.close();
    List<String> testRecords = Arrays.asList("key1", "key2");
    sendTypedMessages(topic.toString(), SchemaType.STRING, testRecords, Optional.empty(), String.class);
    Consumer<Message<GenericRecord>> handle = msg -> {
        try {
            initSchema((Schema<GenericRecord>) msg.getReaderSchema().get());
            getFormatGeneratedRecord(topic, msg);
        } catch (Exception e) {
            LOGGER.error("formatter handle message is fail", e);
            Assert.fail();
        }
    };
    consumerMessages(topic.toString(), Schema.AUTO_CONSUME(), handle, testRecords.size(), 2000);
}
Also used : Arrays(java.util.Arrays) TopicName(org.apache.pulsar.common.naming.TopicName) BlobStoreAbstractConfig(org.apache.pulsar.io.jcloud.BlobStoreAbstractConfig) LoggerFactory(org.slf4j.LoggerFactory) ArrayUtils(org.apache.commons.lang3.ArrayUtils) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Message(org.apache.pulsar.client.api.Message) SchemaType(org.apache.pulsar.common.schema.SchemaType) ArrayList(java.util.ArrayList) AvroRecordUtil(org.apache.pulsar.io.jcloud.util.AvroRecordUtil) Record(org.apache.pulsar.functions.api.Record) Logger(org.slf4j.Logger) ByteSource(org.apache.pulsar.jcloud.shade.com.google.common.io.ByteSource) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Schema(org.apache.pulsar.client.api.Schema) Consumer(java.util.function.Consumer) GenericRecord(org.apache.pulsar.client.api.schema.GenericRecord) List(java.util.List) MessageId(org.apache.pulsar.client.api.MessageId) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) HexStringUtils(org.apache.pulsar.io.jcloud.util.HexStringUtils) Assert(org.junit.Assert) Mockito.mock(org.mockito.Mockito.mock) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Message(org.apache.pulsar.client.api.Message) Schema(org.apache.pulsar.client.api.Schema) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.junit.Test)

Example 2 with RandomStringUtils.randomAlphabetic

use of org.apache.commons.lang3.RandomStringUtils.randomAlphabetic in project openvidu by OpenVidu.

the class KurentoSessionManager method publishIpcam.

@Override
public /* Protected by Session.closingLock.readLock */
Participant publishIpcam(Session session, MediaOptions mediaOptions, ConnectionProperties connectionProperties) throws Exception {
    final String sessionId = session.getSessionId();
    final KurentoMediaOptions kMediaOptions = (KurentoMediaOptions) mediaOptions;
    // Generate the location for the IpCam
    GeoLocation location = null;
    URL url = null;
    InetAddress ipAddress = null;
    String protocol = null;
    try {
        Pattern pattern = Pattern.compile("^(file|rtsp|rtsps)://");
        Matcher matcher = pattern.matcher(kMediaOptions.rtspUri);
        if (matcher.find()) {
            protocol = matcher.group(0).replaceAll("://$", "");
        } else {
            throw new MalformedURLException();
        }
        String parsedUrl = kMediaOptions.rtspUri.replaceAll("^.*?://", "http://");
        url = new URL(parsedUrl);
    } catch (Exception e) {
        throw new MalformedURLException();
    }
    try {
        ipAddress = InetAddress.getByName(url.getHost());
        location = this.geoLocationByIp.getLocationByIp(ipAddress);
    } catch (IOException e) {
        e.printStackTrace();
        location = new GeoLocation(ipAddress != null ? ipAddress.getHostAddress() : null);
    } catch (Exception e) {
        log.warn("Error getting address location: {}", e.getMessage());
        location = new GeoLocation(ipAddress != null ? ipAddress.getHostAddress() : null);
    }
    String rtspConnectionId = kMediaOptions.getTypeOfVideo() + "_" + protocol + "_" + RandomStringUtils.randomAlphanumeric(4).toUpperCase() + "_" + url.getHost() + (url.getPort() != -1 ? (":" + url.getPort()) : "") + url.getPath();
    rtspConnectionId = rtspConnectionId.replace("/", "_").replace("-", "").replace(".", "_").replace(":", "_");
    rtspConnectionId = IdentifierPrefixes.IPCAM_ID + rtspConnectionId;
    // Store a "fake" participant for the IpCam connection
    this.newInsecureParticipant(rtspConnectionId);
    String token = IdentifierPrefixes.TOKEN_ID + RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(15);
    this.newTokenForInsecureUser(session, token, connectionProperties);
    final Token tokenObj = session.consumeToken(token);
    Participant ipcamParticipant = this.newIpcamParticipant(session, rtspConnectionId, tokenObj, location, mediaOptions.getTypeOfVideo());
    // Store a "fake" final user for the IpCam connection
    final String finalUserId = rtspConnectionId;
    this.sessionidFinalUsers.get(sessionId).computeIfAbsent(finalUserId, k -> {
        return new FinalUser(finalUserId, sessionId, ipcamParticipant);
    }).addConnectionIfAbsent(ipcamParticipant);
    // Join the participant to the session
    this.joinRoom(ipcamParticipant, sessionId, null);
    // Publish the IpCam stream into the session
    KurentoParticipant kParticipant = (KurentoParticipant) this.getParticipant(rtspConnectionId);
    kParticipant.deleteIpcamProperties();
    this.publishVideo(kParticipant, mediaOptions, null);
    return kParticipant;
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) KurentoOptions(io.openvidu.java.client.KurentoOptions) RecordingMode(io.openvidu.java.client.RecordingMode) JsonUtils(io.openvidu.server.utils.JsonUtils) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RpcHandler(io.openvidu.server.rpc.RpcHandler) OpenViduException(io.openvidu.client.OpenViduException) ProtocolElements(io.openvidu.client.internal.ProtocolElements) InetAddress(java.net.InetAddress) PreDestroy(javax.annotation.PreDestroy) CallDetailRecord(io.openvidu.server.cdr.CallDetailRecord) Matcher(java.util.regex.Matcher) FinalUser(io.openvidu.server.core.FinalUser) RecordingUtils(io.openvidu.server.utils.RecordingUtils) KurentoFilter(io.openvidu.server.kurento.endpoint.KurentoFilter) WebrtcDebugEvent(io.openvidu.server.cdr.WebrtcDebugEvent) EndReason(io.openvidu.server.core.EndReason) SDPMunging(io.openvidu.server.utils.SDPMunging) GenericMediaEvent(org.kurento.client.GenericMediaEvent) Code(io.openvidu.client.OpenViduException.Code) Timestamp(java.sql.Timestamp) Set(java.util.Set) MediaServer(io.openvidu.server.core.MediaServer) GeoLocation(io.openvidu.server.utils.GeoLocation) Kms(io.openvidu.server.kurento.kms.Kms) WebrtcDebugEventType(io.openvidu.server.cdr.WebrtcDebugEvent.WebrtcDebugEventType) IceCandidate(org.kurento.client.IceCandidate) GenericMediaElement(org.kurento.client.GenericMediaElement) VideoCodec(io.openvidu.java.client.VideoCodec) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ConnectionProperties(io.openvidu.java.client.ConnectionProperties) Pattern(java.util.regex.Pattern) WebrtcDebugEventIssuer(io.openvidu.server.cdr.WebrtcDebugEvent.WebrtcDebugEventIssuer) Participant(io.openvidu.server.core.Participant) Props(org.kurento.jsonrpc.Props) SessionProperties(io.openvidu.java.client.SessionProperties) IdentifierPrefixes(io.openvidu.server.core.IdentifierPrefixes) HashSet(java.util.HashSet) JsonElement(com.google.gson.JsonElement) ListenerSubscription(org.kurento.client.ListenerSubscription) KmsManager(io.openvidu.server.kurento.kms.KmsManager) NoSuchElementException(java.util.NoSuchElementException) Token(io.openvidu.server.core.Token) Logger(org.slf4j.Logger) RecordingProperties(io.openvidu.java.client.RecordingProperties) SessionManager(io.openvidu.server.core.SessionManager) Session(io.openvidu.server.core.Session) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) PassThrough(org.kurento.client.PassThrough) MediaMode(io.openvidu.java.client.MediaMode) MediaOptions(io.openvidu.server.core.MediaOptions) TimeUnit(java.util.concurrent.TimeUnit) Request(org.kurento.jsonrpc.message.Request) PublisherEndpoint(io.openvidu.server.kurento.endpoint.PublisherEndpoint) WebrtcDebugEventOperation(io.openvidu.server.cdr.WebrtcDebugEvent.WebrtcDebugEventOperation) Recording(io.openvidu.java.client.Recording) Collections(java.util.Collections) Pattern(java.util.regex.Pattern) MalformedURLException(java.net.MalformedURLException) Matcher(java.util.regex.Matcher) Token(io.openvidu.server.core.Token) IOException(java.io.IOException) URL(java.net.URL) OpenViduException(io.openvidu.client.OpenViduException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Participant(io.openvidu.server.core.Participant) GeoLocation(io.openvidu.server.utils.GeoLocation) InetAddress(java.net.InetAddress) FinalUser(io.openvidu.server.core.FinalUser)

Example 3 with RandomStringUtils.randomAlphabetic

use of org.apache.commons.lang3.RandomStringUtils.randomAlphabetic in project oap by oaplatform.

the class TreePerformance method fill.

@SneakyThrows
private void fill(ArrayList<Dimension> dimensions, ArrayList<Tree.ValueData<String>> data, int count) {
    val map = new HashMap<String, ArrayList<String>>();
    val mapSize = new HashMap<String, Integer>();
    val enums = new HashMap<String, ArrayList<Enum<?>>>();
    for (int i = 0; i < count; i++) {
        val selection = new ArrayList<Object>();
        for (Dimension dimension : dimensions) {
            if (dimension.name.startsWith("string")) {
                val list = map.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    for (int r = 0; r < 100; r++) {
                        list.add(RandomStringUtils.randomAlphabetic(10) + i);
                    }
                }
                selection.add(Lists.random(list).get());
            } else if (dimension.name.startsWith("long")) {
                selection.add(RandomUtils.nextLong(0, 1000000));
            } else if (dimension.name.startsWith("boolean")) {
                selection.add(RandomUtils.nextBoolean());
            } else if (dimension.name.startsWith("arrayString")) {
                val size = mapSize.computeIfAbsent(dimension.name, ss -> {
                    final Matcher matcher = ARRAY_STRING_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    return Integer.parseInt(matcher.group(1));
                });
                val list = map.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    for (int r = 0; r < 100; r++) {
                        list.add(RandomStringUtils.randomAlphabetic(10) + i);
                    }
                }
                val array = new ArrayList<String>();
                for (int s = 0; s < size; s++) {
                    array.add(Lists.random(list).get());
                }
                selection.add(new Tree.Array(array, true));
            } else if (dimension.name.startsWith("arrayEnum")) {
                val size = mapSize.computeIfAbsent(dimension.name, ss1 -> {
                    final Matcher matcher = ARRAY_ENUM_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    return Integer.parseInt(matcher.group(1));
                });
                val list = enums.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    final Matcher matcher = ARRAY_ENUM_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    final Class<Enum<?>> clazz = (Class<Enum<?>>) Class.forName(matcher.group(2));
                    final Enum<?>[] enumConstants = clazz.getEnumConstants();
                    list.addAll(asList(enumConstants));
                }
                val array = new ArrayList<Enum<?>>();
                for (int s = 0; s < size; s++) {
                    array.add(Lists.random(list).get());
                }
                selection.add(new Tree.Array(array, true));
            } else if (dimension.name.startsWith("arrayLong")) {
                val array = new ArrayList<Long>();
                val size = mapSize.computeIfAbsent(dimension.name, ss1 -> {
                    final Matcher matcher = ARRAY_LONG_PATTERN.matcher(dimension.name);
                    matcher.find();
                    return Integer.parseInt(matcher.group(1));
                });
                for (int s = 0; s < size; s++) {
                    array.add(RandomUtils.nextLong(0, size));
                }
                selection.add(new Tree.Array(array, true));
            } else if (dimension.name.startsWith("enum")) {
                val list = enums.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
                if (list.isEmpty()) {
                    final Matcher matcher = ENUM_PATTERN.matcher(dimension.name);
                    assert matcher.find();
                    final Class<Enum<?>> clazz = (Class<Enum<?>>) Class.forName(matcher.group(1));
                    final Enum<?>[] enumConstants = clazz.getEnumConstants();
                    list.addAll(asList(enumConstants));
                }
                selection.add(Lists.random(list).get());
            } else {
                throw new IllegalStateException("Unknown dimension type " + dimension.name);
            }
        }
        data.add(new Tree.ValueData<>(selection, "data" + i));
    }
}
Also used : lombok.val(lombok.val) RandomUtils(org.apache.commons.lang3.RandomUtils) SneakyThrows(lombok.SneakyThrows) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) STRING(oap.tree.Dimension.STRING) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Lists(oap.util.Lists) Arrays.asList(java.util.Arrays.asList) Assertions(org.assertj.core.api.Assertions) LONG(oap.tree.Dimension.LONG) ENUM(oap.tree.Dimension.ENUM) BOOLEAN(oap.tree.Dimension.BOOLEAN) lombok.val(lombok.val) Set(java.util.Set) NOT_CONTAINS(oap.tree.Dimension.OperationType.NOT_CONTAINS) AbstractPerformance(oap.testng.AbstractPerformance) List(java.util.List) ARRAY_LONG(oap.tree.Dimension.ARRAY_LONG) ARRAY_STRING(oap.tree.Dimension.ARRAY_STRING) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ARRAY_ENUM(oap.tree.Dimension.ARRAY_ENUM) Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) SneakyThrows(lombok.SneakyThrows)

Example 4 with RandomStringUtils.randomAlphabetic

use of org.apache.commons.lang3.RandomStringUtils.randomAlphabetic in project ozone by apache.

the class TestSecureContainerServer method createDispatcher.

private static HddsDispatcher createDispatcher(DatanodeDetails dd, UUID scmId, OzoneConfiguration conf) throws IOException {
    ContainerSet containerSet = new ContainerSet();
    conf.set(HDDS_DATANODE_DIR_KEY, Paths.get(TEST_DIR, "dfs", "data", "hdds", RandomStringUtils.randomAlphabetic(4)).toString());
    conf.set(OZONE_METADATA_DIRS, TEST_DIR);
    VolumeSet volumeSet = new MutableVolumeSet(dd.getUuidString(), conf, null, StorageVolume.VolumeType.DATA_VOLUME, null);
    DatanodeStateMachine stateMachine = Mockito.mock(DatanodeStateMachine.class);
    StateContext context = Mockito.mock(StateContext.class);
    Mockito.when(stateMachine.getDatanodeDetails()).thenReturn(dd);
    Mockito.when(context.getParent()).thenReturn(stateMachine);
    ContainerMetrics metrics = ContainerMetrics.create(conf);
    Map<ContainerProtos.ContainerType, Handler> handlers = Maps.newHashMap();
    for (ContainerProtos.ContainerType containerType : ContainerProtos.ContainerType.values()) {
        handlers.put(containerType, Handler.getHandlerForContainerType(containerType, conf, dd.getUuid().toString(), containerSet, volumeSet, metrics, c -> {
        }));
    }
    HddsDispatcher hddsDispatcher = new HddsDispatcher(conf, containerSet, volumeSet, handlers, context, metrics, TokenVerifier.create(new SecurityConfig((conf)), caClient));
    hddsDispatcher.setClusterId(scmId.toString());
    return hddsDispatcher;
}
Also used : MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) XceiverServerSpi(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerSpi) ContainerTestHelper.newGetBlockRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newGetBlockRequestBuilder) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerProtocolCalls(org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) DefaultMetricsSystem(org.apache.hadoop.metrics2.lib.DefaultMetricsSystem) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) Map(java.util.Map) After(org.junit.After) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) HddsConfigKeys(org.apache.hadoop.hdds.HddsConfigKeys) CheckedBiConsumer(org.apache.ratis.util.function.CheckedBiConsumer) XceiverServerRatis(org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis) EnumSet(java.util.EnumSet) OZONE_METADATA_DIRS(org.apache.hadoop.hdds.HddsConfigKeys.OZONE_METADATA_DIRS) CertificateClientTestImpl(org.apache.hadoop.ozone.client.CertificateClientTestImpl) AfterClass(org.junit.AfterClass) SecurityConfig(org.apache.hadoop.hdds.security.x509.SecurityConfig) TokenVerifier(org.apache.hadoop.hdds.security.token.TokenVerifier) ContainerTestHelper.getCreateContainerRequest(org.apache.hadoop.ozone.container.ContainerTestHelper.getCreateContainerRequest) OZONE_SECURITY_ENABLED_KEY(org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SECURITY_ENABLED_KEY) UUID(java.util.UUID) XceiverServerGrpc(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerGrpc) List(java.util.List) OzoneBlockTokenSecretManager(org.apache.hadoop.ozone.security.OzoneBlockTokenSecretManager) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) HDDS_BLOCK_TOKEN_ENABLED(org.apache.hadoop.hdds.HddsConfigKeys.HDDS_BLOCK_TOKEN_ENABLED) OzoneConfigKeys(org.apache.hadoop.ozone.OzoneConfigKeys) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) ContainerTestHelper.getTestBlockID(org.apache.hadoop.ozone.container.ContainerTestHelper.getTestBlockID) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) RandomUtils(org.apache.commons.lang3.RandomUtils) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) RatisTestHelper(org.apache.hadoop.ozone.RatisTestHelper) BlockID(org.apache.hadoop.hdds.client.BlockID) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) BeforeClass(org.junit.BeforeClass) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) ContainerTestHelper.newReadChunkRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newReadChunkRequestBuilder) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) ArrayList(java.util.ArrayList) XceiverClientRatis(org.apache.hadoop.hdds.scm.XceiverClientRatis) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) ContainerTestHelper.getTestContainerID(org.apache.hadoop.ozone.container.ContainerTestHelper.getTestContainerID) ContainerDispatcher(org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) ContainerTestHelper.newGetCommittedBlockLengthBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newGetCommittedBlockLengthBuilder) HddsUtils.isReadOnly(org.apache.hadoop.hdds.HddsUtils.isReadOnly) AccessModeProto(org.apache.hadoop.hdds.protocol.proto.HddsProtos.BlockTokenSecretProto.AccessModeProto) Assert.assertNotNull(org.junit.Assert.assertNotNull) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Token(org.apache.hadoop.security.token.Token) Maps(com.google.common.collect.Maps) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) ContainerTokenSecretManager(org.apache.hadoop.hdds.security.token.ContainerTokenSecretManager) ContainerTestHelper.newPutBlockRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newPutBlockRequestBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) OzoneBlockTokenIdentifier(org.apache.hadoop.hdds.security.token.OzoneBlockTokenIdentifier) StorageVolume(org.apache.hadoop.ozone.container.common.volume.StorageVolume) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet) Paths(java.nio.file.Paths) HDDS_DATANODE_DIR_KEY(org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_KEY) ContainerTestHelper.newWriteChunkRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newWriteChunkRequestBuilder) RpcType(org.apache.ratis.rpc.RpcType) ExitUtils(org.apache.ratis.util.ExitUtils) GRPC(org.apache.ratis.rpc.SupportedRpcType.GRPC) Assert(org.junit.Assert) SUCCESS(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.SUCCESS) Assert.assertEquals(org.junit.Assert.assertEquals) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) SecurityConfig(org.apache.hadoop.hdds.security.x509.SecurityConfig) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet)

Example 5 with RandomStringUtils.randomAlphabetic

use of org.apache.commons.lang3.RandomStringUtils.randomAlphabetic in project meveo by meveo-org.

the class CustomScriptService method addMavenLibrariesToClassPath.

/**
 * Add the given maven libraries to class path
 *
 * @param mavenDependenciesList Denpendencies definitions
 */
public List<ScriptInstanceError> addMavenLibrariesToClassPath(Collection<MavenDependency> mavenDependenciesList) {
    List<ScriptInstanceError> result = new ArrayList<>();
    MavenClassLoader mavenClassLoader = MavenClassLoader.getInstance();
    var dependenciesToResolve = mavenDependenciesList.stream().filter(Predicate.not(mavenClassLoader::isLibraryLoaded)).collect(Collectors.toList());
    if (dependenciesToResolve == null || dependenciesToResolve.isEmpty()) {
        log.debug("All maven depencencies are already loaded");
        return result;
    }
    String m2FolderPath = mavenConfigurationService.getM2FolderPath();
    if (StringUtils.isBlank(m2FolderPath)) {
        String errorStr = "No maven .m2 path defined in maven configuration";
        log.error(errorStr);
        ScriptInstanceError error = new ScriptInstanceError();
        error.setMessage(errorStr);
        result.add(error);
        return result;
    }
    List<String> repos = mavenConfigurationService.getMavenRepositories();
    String repoId = RandomStringUtils.randomAlphabetic(5);
    List<RemoteRepository> remoteRepositories = repos.stream().map(e -> new RemoteRepository.Builder(repoId, "default", e).build()).collect(Collectors.toList());
    log.debug("Found {} repositories", remoteRepositories.size());
    Map<MavenDependency, Set<String>> resolvedDependencies = new HashMap<>();
    for (MavenDependency mavenDependency : dependenciesToResolve) {
        Set<String> resolvedDependency = getMavenDependencies(mavenDependency, remoteRepositories);
        if (resolvedDependency != null) {
            resolvedDependencies.put(mavenDependency, resolvedDependency);
        } else {
            String errorStr = "Cannot find or load maven dependency " + mavenDependency.toString() + ", .m2 path: " + mavenDependency.toLocalM2Path(m2FolderPath);
            log.error(errorStr);
            ScriptInstanceError error = new ScriptInstanceError();
            error.setMessage(errorStr);
            result.add(error);
        }
    }
    synchronized (CLASSPATH_REFERENCE) {
        resolvedDependencies.forEach((lib, locations) -> {
            locations.forEach(location -> {
                if (!StringUtils.isBlank(location) && !CLASSPATH_REFERENCE.get().contains(location)) {
                    CLASSPATH_REFERENCE.set(CLASSPATH_REFERENCE.get() + File.pathSeparator + location);
                }
            });
            mavenClassLoader.addLibrary(lib, locations);
        });
    }
    return result;
}
Also used : JAVA(org.meveo.model.scripts.ScriptSourceTypeEnum.JAVA) Arrays(java.util.Arrays) DependencyFilterUtils(org.eclipse.aether.util.filter.DependencyFilterUtils) NoResultException(javax.persistence.NoResultException) MeveoRepository(org.meveo.service.git.MeveoRepository) StringUtils(org.meveo.commons.utils.StringUtils) MeveoModuleService(org.meveo.service.admin.impl.MeveoModuleService) ScriptInstance(org.meveo.model.scripts.ScriptInstance) CustomEntity(org.meveo.model.CustomEntity) Matcher(java.util.regex.Matcher) TransactionAttributeType(javax.ejb.TransactionAttributeType) CustomEntityTemplateCompiler(org.meveo.service.custom.CustomEntityTemplateCompiler) MavenClassLoader(org.meveo.service.script.maven.MavenClassLoader) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) Map(java.util.Map) ModuleInstallationContext(org.meveo.service.admin.impl.ModuleInstallationContext) InvalidScriptException(org.meveo.admin.exception.InvalidScriptException) CustomEntityInstance(org.meveo.model.customEntities.CustomEntityInstance) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaFileObject(javax.tools.JavaFileObject) GitRepository(org.meveo.model.git.GitRepository) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) MavenDependency(org.meveo.model.scripts.MavenDependency) MeveoModuleItem(org.meveo.model.module.MeveoModuleItem) Dependency(org.eclipse.aether.graph.Dependency) Accessor(org.meveo.model.scripts.Accessor) JavaScopes(org.eclipse.aether.util.artifact.JavaScopes) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) JacksonUtil(org.meveo.model.persistence.JacksonUtil) ExpectedOutput(org.meveo.model.scripts.test.ExpectedOutput) CEIUtils(org.meveo.model.persistence.CEIUtils) CommitEvent(org.meveo.event.qualifier.git.CommitEvent) IOException(java.io.IOException) File(java.io.File) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) CurrentUser(org.meveo.security.CurrentUser) ES5ScriptEngine(org.meveo.service.script.engines.ES5ScriptEngine) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) LoggerFactory(org.slf4j.LoggerFactory) MavenConfigurationService(org.meveo.service.config.impl.MavenConfigurationService) ReflectionUtils(org.meveo.commons.utils.ReflectionUtils) ImportDeclaration(com.github.javaparser.ast.ImportDeclaration) Locale(java.util.Locale) Diagnostic(javax.tools.Diagnostic) CommitReceived(org.meveo.event.qualifier.git.CommitReceived) FunctionIO(org.meveo.model.scripts.FunctionIO) Observes(javax.enterprise.event.Observes) MeveoUser(org.meveo.security.MeveoUser) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Method(java.lang.reflect.Method) DiagnosticCollector(javax.tools.DiagnosticCollector) FileUtils(org.meveo.commons.utils.FileUtils) CustomScript(org.meveo.model.scripts.CustomScript) ElementNotFoundException(org.meveo.admin.exception.ElementNotFoundException) ResourceBundle(org.meveo.admin.util.ResourceBundle) Predicate(java.util.function.Predicate) MeveoModule(org.meveo.model.module.MeveoModule) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) BusinessException(org.meveo.admin.exception.BusinessException) Objects(java.util.Objects) List(java.util.List) Query(javax.persistence.Query) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) Pattern(java.util.regex.Pattern) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) DependencyResult(org.eclipse.aether.resolution.DependencyResult) RepositorySystem(org.eclipse.aether.RepositorySystem) CustomEntityTemplateService(org.meveo.service.custom.CustomEntityTemplateService) ScriptSourceTypeEnum(org.meveo.model.scripts.ScriptSourceTypeEnum) MeveoBeanManager(org.meveo.service.script.weld.MeveoBeanManager) HashMap(java.util.HashMap) FlushModeType(javax.persistence.FlushModeType) AtomicReference(java.util.concurrent.atomic.AtomicReference) CacheKeyStr(org.meveo.cache.CacheKeyStr) MeveoFileUtils(org.meveo.commons.utils.MeveoFileUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Removed(org.meveo.event.qualifier.Removed) CollectionUtils(org.apache.commons.collections.CollectionUtils) TransactionAttribute(javax.ejb.TransactionAttribute) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) PythonScriptEngine(org.meveo.service.script.engines.PythonScriptEngine) ScriptInstanceError(org.meveo.model.scripts.ScriptInstanceError) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest) Logger(org.slf4j.Logger) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) GitHelper(org.meveo.service.git.GitHelper) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) GitClient(org.meveo.service.git.GitClient) Collections(java.util.Collections) JavaParser(com.github.javaparser.JavaParser) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ScriptInstanceError(org.meveo.model.scripts.ScriptInstanceError) MavenClassLoader(org.meveo.service.script.maven.MavenClassLoader) MavenDependency(org.meveo.model.scripts.MavenDependency)

Aggregations

RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)5 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 List (java.util.List)3 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 RandomUtils (org.apache.commons.lang3.RandomUtils)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)1 JavaParser (com.github.javaparser.JavaParser)1 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 ImportDeclaration (com.github.javaparser.ast.ImportDeclaration)1