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);
}
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;
}
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));
}
}
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;
}
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;
}
Aggregations