Search in sources :

Example 6 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project cas by apereo.

the class InternalGroovyScriptDao method getAttributesForUser.

@Override
public Map<String, Object> getAttributesForUser(final String uid) {
    final Map<String, Object> finalAttributes = new HashedMap();
    casProperties.getAuthn().getAttributeRepository().getGroovy().forEach(groovy -> {
        final ClassLoader parent = getClass().getClassLoader();
        try (GroovyClassLoader loader = new GroovyClassLoader(parent)) {
            if (groovy.getConfig().getLocation() != null) {
                final File groovyFile = groovy.getConfig().getLocation().getFile();
                if (groovyFile.exists()) {
                    final Class<?> groovyClass = loader.parseClass(groovyFile);
                    LOGGER.debug("Loaded groovy class [{}] from script [{}]", groovyClass.getSimpleName(), groovyFile.getCanonicalPath());
                    final GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance();
                    LOGGER.debug("Created groovy object instance from class [{}]", groovyFile.getCanonicalPath());
                    final Object[] args = { uid, LOGGER, casProperties, applicationContext };
                    LOGGER.debug("Executing groovy script's run method, with parameters [{}]", args);
                    final Map<String, Object> personAttributesMap = (Map<String, Object>) groovyObject.invokeMethod("run", args);
                    LOGGER.debug("Creating person attributes with the username [{}] and attributes [{}]", uid, personAttributesMap);
                    finalAttributes.putAll(personAttributesMap);
                }
            }
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    });
    return finalAttributes;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GroovyClassLoader(groovy.lang.GroovyClassLoader) GroovyObject(groovy.lang.GroovyObject) HashedMap(org.apache.commons.collections.map.HashedMap) File(java.io.File) HashMap(java.util.HashMap) HashedMap(org.apache.commons.collections.map.HashedMap) Map(java.util.Map) GroovyObject(groovy.lang.GroovyObject)

Example 7 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project gocd by gocd.

the class AuthorizationMessageConverterV1 method getAuthConfigs.

private List<Map<String, Object>> getAuthConfigs(List<SecurityAuthConfig> authConfigs) {
    List<Map<String, Object>> configs = new ArrayList<>();
    if (authConfigs == null) {
        return configs;
    }
    for (SecurityAuthConfig securityAuthConfig : authConfigs) {
        Map<String, Object> authConfig = new HashedMap();
        authConfig.put("id", securityAuthConfig.getId());
        authConfig.put("configuration", securityAuthConfig.getConfigurationAsMap(true));
        configs.add(authConfig);
    }
    return configs;
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HashedMap(org.apache.commons.collections.map.HashedMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 8 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project flink by apache.

the class HeapKeyedStateBackend method snapshot.

@Override
@SuppressWarnings("unchecked")
public RunnableFuture<KeyGroupsStateHandle> snapshot(final long checkpointId, final long timestamp, final CheckpointStreamFactory streamFactory, CheckpointOptions checkpointOptions) throws Exception {
    if (!hasRegisteredState()) {
        return DoneFuture.nullValue();
    }
    long syncStartTime = System.currentTimeMillis();
    Preconditions.checkState(stateTables.size() <= Short.MAX_VALUE, "Too many KV-States: " + stateTables.size() + ". Currently at most " + Short.MAX_VALUE + " states are supported");
    List<KeyedBackendSerializationProxy.StateMetaInfo<?, ?>> metaInfoProxyList = new ArrayList<>(stateTables.size());
    final Map<String, Integer> kVStateToId = new HashMap<>(stateTables.size());
    final Map<StateTable<K, ?, ?>, StateTableSnapshot> cowStateStableSnapshots = new HashedMap(stateTables.size());
    for (Map.Entry<String, StateTable<K, ?, ?>> kvState : stateTables.entrySet()) {
        RegisteredBackendStateMetaInfo<?, ?> metaInfo = kvState.getValue().getMetaInfo();
        KeyedBackendSerializationProxy.StateMetaInfo<?, ?> metaInfoProxy = new KeyedBackendSerializationProxy.StateMetaInfo(metaInfo.getStateType(), metaInfo.getName(), metaInfo.getNamespaceSerializer(), metaInfo.getStateSerializer());
        metaInfoProxyList.add(metaInfoProxy);
        kVStateToId.put(kvState.getKey(), kVStateToId.size());
        StateTable<K, ?, ?> stateTable = kvState.getValue();
        if (null != stateTable) {
            cowStateStableSnapshots.put(stateTable, stateTable.createSnapshot());
        }
    }
    final KeyedBackendSerializationProxy serializationProxy = new KeyedBackendSerializationProxy(keySerializer, metaInfoProxyList);
    //--------------------------------------------------- this becomes the end of sync part
    // implementation of the async IO operation, based on FutureTask
    final AbstractAsyncIOCallable<KeyGroupsStateHandle, CheckpointStreamFactory.CheckpointStateOutputStream> ioCallable = new AbstractAsyncIOCallable<KeyGroupsStateHandle, CheckpointStreamFactory.CheckpointStateOutputStream>() {

        AtomicBoolean open = new AtomicBoolean(false);

        @Override
        public CheckpointStreamFactory.CheckpointStateOutputStream openIOHandle() throws Exception {
            if (open.compareAndSet(false, true)) {
                CheckpointStreamFactory.CheckpointStateOutputStream stream = streamFactory.createCheckpointStateOutputStream(checkpointId, timestamp);
                try {
                    cancelStreamRegistry.registerClosable(stream);
                    return stream;
                } catch (Exception ex) {
                    open.set(false);
                    throw ex;
                }
            } else {
                throw new IOException("Operation already opened.");
            }
        }

        @Override
        public KeyGroupsStateHandle performOperation() throws Exception {
            long asyncStartTime = System.currentTimeMillis();
            CheckpointStreamFactory.CheckpointStateOutputStream stream = getIoHandle();
            DataOutputViewStreamWrapper outView = new DataOutputViewStreamWrapper(stream);
            serializationProxy.write(outView);
            long[] keyGroupRangeOffsets = new long[keyGroupRange.getNumberOfKeyGroups()];
            for (int keyGroupPos = 0; keyGroupPos < keyGroupRange.getNumberOfKeyGroups(); ++keyGroupPos) {
                int keyGroupId = keyGroupRange.getKeyGroupId(keyGroupPos);
                keyGroupRangeOffsets[keyGroupPos] = stream.getPos();
                outView.writeInt(keyGroupId);
                for (Map.Entry<String, StateTable<K, ?, ?>> kvState : stateTables.entrySet()) {
                    outView.writeShort(kVStateToId.get(kvState.getKey()));
                    cowStateStableSnapshots.get(kvState.getValue()).writeMappingsInKeyGroup(outView, keyGroupId);
                }
            }
            if (open.compareAndSet(true, false)) {
                StreamStateHandle streamStateHandle = stream.closeAndGetHandle();
                KeyGroupRangeOffsets offsets = new KeyGroupRangeOffsets(keyGroupRange, keyGroupRangeOffsets);
                final KeyGroupsStateHandle keyGroupsStateHandle = new KeyGroupsStateHandle(offsets, streamStateHandle);
                if (asynchronousSnapshots) {
                    LOG.info("Heap backend snapshot ({}, asynchronous part) in thread {} took {} ms.", streamFactory, Thread.currentThread(), (System.currentTimeMillis() - asyncStartTime));
                }
                return keyGroupsStateHandle;
            } else {
                throw new IOException("Checkpoint stream already closed.");
            }
        }

        @Override
        public void done(boolean canceled) {
            if (open.compareAndSet(true, false)) {
                CheckpointStreamFactory.CheckpointStateOutputStream stream = getIoHandle();
                if (null != stream) {
                    cancelStreamRegistry.unregisterClosable(stream);
                    IOUtils.closeQuietly(stream);
                }
            }
            for (StateTableSnapshot snapshot : cowStateStableSnapshots.values()) {
                snapshot.release();
            }
        }
    };
    AsyncStoppableTaskWithCallback<KeyGroupsStateHandle> task = AsyncStoppableTaskWithCallback.from(ioCallable);
    if (!asynchronousSnapshots) {
        task.run();
    }
    LOG.info("Heap backend snapshot (" + streamFactory + ", synchronous part) in thread " + Thread.currentThread() + " took " + (System.currentTimeMillis() - syncStartTime) + " ms.");
    return task;
}
Also used : RegisteredBackendStateMetaInfo(org.apache.flink.runtime.state.RegisteredBackendStateMetaInfo) HashMap(java.util.HashMap) KeyGroupRangeOffsets(org.apache.flink.runtime.state.KeyGroupRangeOffsets) ArrayList(java.util.ArrayList) KeyedBackendSerializationProxy(org.apache.flink.runtime.state.KeyedBackendSerializationProxy) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) IOException(java.io.IOException) AbstractAsyncIOCallable(org.apache.flink.runtime.io.async.AbstractAsyncIOCallable) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) HashedMap(org.apache.commons.collections.map.HashedMap) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) HashMap(java.util.HashMap)

Example 9 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project atlas by alibaba.

the class DataBindingRenameTask method createAwbPackages.

/**
     * 生成so的目录
     */
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
    AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
    if (null == androidDependencyTree) {
        return;
    }
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    List<Runnable> runnables = new ArrayList<>();
    for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
        runnables.add(new Runnable() {

            @Override
            public void run() {
                try {
                    File dataBindingClazzFolder = appVariantOutputContext.getVariantContext().getJAwbavaOutputDir(awbBundle);
                    String packageName = ManifestFileUtils.getPackage(awbBundle.getOrgManifestFile());
                    String appName = appVariantContext.getVariantConfiguration().getOriginalApplicationId();
                    //删除那些已经存在的类
                    File dataMapperClazz = new File(dataBindingClazzFolder, "android/databinding/DataBinderMapper.class");
                    if (!dataMapperClazz.exists()) {
                        throw new GradleException("missing datamapper class");
                    }
                    FileInputStream fileInputStream = new FileInputStream(dataMapperClazz);
                    ClassReader in1 = new ClassReader(fileInputStream);
                    ClassWriter cw = new ClassWriter(0);
                    Map<String, String> reMapping = new HashedMap();
                    reMapping.put(appName.replace(".", "/") + "/BR", packageName.replace(".", "/") + "/BR");
                    RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(cw, new SimpleRemapper(reMapping));
                    in1.accept(remappingClassAdapter, 8);
                    ClassReader in2 = new ClassReader(cw.toByteArray());
                    ClassWriter cw2 = new ClassWriter(0);
                    Set<String> renames = new HashSet<String>();
                    renames.add("android/databinding/DataBinderMapper");
                    in2.accept(new ClassRenamer(cw2, renames, packageName.replace(".", "/") + "/DataBinderMapper"), 8);
                    File destClass = new File(dataBindingClazzFolder, packageName.replace(".", "/") + "/DataBinderMapper.class");
                    destClass.getParentFile().mkdirs();
                    FileOutputStream fileOutputStream = new FileOutputStream(destClass);
                    fileOutputStream.write(cw2.toByteArray());
                    IOUtils.closeQuietly(fileOutputStream);
                    IOUtils.closeQuietly(fileInputStream);
                    FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "android/databinding"));
                    FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "com/android/databinding"));
                    File appDir = new File(dataBindingClazzFolder, appName.replace(".", "/"));
                    if (appDir.exists()) {
                        File[] files = appDir.listFiles(new FileFilter() {

                            @Override
                            public boolean accept(File pathname) {
                                return pathname.isFile() && !pathname.isDirectory();
                            }
                        });
                        for (File tmp : files) {
                            FileUtils.forceDelete(tmp);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    throw new GradleException("package awb failed");
                }
            }
        });
    }
    executorServicesHelper.execute(runnables);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) AndroidDependencyTree(com.taobao.android.builder.dependency.AndroidDependencyTree) FileInputStream(java.io.FileInputStream) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) SimpleRemapper(org.objectweb.asm.commons.SimpleRemapper) RemappingClassAdapter(org.objectweb.asm.commons.RemappingClassAdapter) GradleException(org.gradle.api.GradleException) FileOutputStream(java.io.FileOutputStream) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) HashedMap(org.apache.commons.collections.map.HashedMap) FileFilter(java.io.FileFilter) File(java.io.File) Map(java.util.Map) HashedMap(org.apache.commons.collections.map.HashedMap) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 10 with HashedMap

use of org.apache.commons.collections.map.HashedMap in project cloudstack by apache.

the class HostResponseTest method testSetDetailsWithoutRootCredentials.

@Test
public void testSetDetailsWithoutRootCredentials() {
    final HostResponse hostResponse = new HostResponse();
    final Map details = new HashMap<>();
    details.put(VALID_KEY, VALID_VALUE);
    final Map expectedDetails = new HashedMap();
    expectedDetails.put(VALID_KEY, VALID_VALUE);
    hostResponse.setDetails(details);
    final Map actualDetails = hostResponse.getDetails();
    assertTrue(details != actualDetails);
    assertEquals(expectedDetails, actualDetails);
}
Also used : HashMap(java.util.HashMap) HashedMap(org.apache.commons.collections.map.HashedMap) Map(java.util.Map) HashMap(java.util.HashMap) HashedMap(org.apache.commons.collections.map.HashedMap) Test(org.junit.Test)

Aggregations

HashedMap (org.apache.commons.collections.map.HashedMap)12 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Test (org.junit.Test)6 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)1 ExecutorServicesHelper (com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper)1 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)1 CatalogFramework (ddf.catalog.CatalogFramework)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 CreateResponse (ddf.catalog.operation.CreateResponse)1 DeleteRequest (ddf.catalog.operation.DeleteRequest)1 DeleteResponse (ddf.catalog.operation.DeleteResponse)1 UpdateResponse (ddf.catalog.operation.UpdateResponse)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1