Search in sources :

Example 1 with Properties

use of org.apache.pulsar.broker.admin.v1.Properties in project extension-s3 by lucee.

the class S3Function method toS3Properties.

protected static S3Properties toS3Properties(PageContext pc, String accessKeyId, String secretAccessKey) throws PageException, RuntimeException {
    // directly
    if (!Util.isEmpty(accessKeyId, true) && !Util.isEmpty(secretAccessKey, true)) {
        S3Properties props = new S3Properties();
        props.setSecretAccessKey(secretAccessKey);
        props.setAccessKeyId(accessKeyId);
        props.setCustomCredentials(true);
        return props;
    }
    // application context
    ApplicationContext ac = pc.getApplicationContext();
    if (ac != null) {
        Properties props = ac.getS3();
        if (props != null) {
            accessKeyId = props.getAccessKeyId();
            secretAccessKey = props.getSecretAccessKey();
            if (!Util.isEmpty(accessKeyId, true) && !Util.isEmpty(secretAccessKey, true)) {
                S3Properties s3props = new S3Properties();
                s3props.setSecretAccessKey(secretAccessKey);
                s3props.setAccessKeyId(accessKeyId);
                s3props.setCustomCredentials(false);
                if (props.getHost() != null)
                    s3props.setHost(props.getHost());
                return s3props;
            }
        }
    }
    if (Util.isEmpty(secretAccessKey, true))
        secretAccessKey = S3Util.getSystemPropOrEnvVar("lucee.s3.secretaccesskey", null);
    if (Util.isEmpty(secretAccessKey, true))
        secretAccessKey = S3Util.getSystemPropOrEnvVar("lucee.s3.secretkey", null);
    if (Util.isEmpty(accessKeyId, true))
        accessKeyId = S3Util.getSystemPropOrEnvVar("lucee.s3.accesskeyid", null);
    if (Util.isEmpty(accessKeyId, true))
        accessKeyId = S3Util.getSystemPropOrEnvVar("lucee.s3.accesskey", null);
    if (Util.isEmpty(secretAccessKey, true) || Util.isEmpty(accessKeyId, true))
        throw CFMLEngineFactory.getInstance().getExceptionUtil().createApplicationException("missing S3 credentials", "you can define the credentials as argument for the function [accessKeyId, secretAccessKey], in the application.cfc [this.s3.accessKeyId, this.s3.secretAccessKey] or in the system properties/environment variables [lucee.s3.secretaccesskey,lucee.s3.accesskeyid]");
    S3Properties props = new S3Properties();
    props.setSecretAccessKey(secretAccessKey);
    props.setAccessKeyId(accessKeyId);
    props.setCustomCredentials(false);
    return props;
}
Also used : ApplicationContext(lucee.runtime.listener.ApplicationContext) S3Properties(org.lucee.extension.resource.s3.S3Properties) Properties(lucee.runtime.net.s3.Properties) S3Properties(org.lucee.extension.resource.s3.S3Properties)

Example 2 with Properties

use of org.apache.pulsar.broker.admin.v1.Properties in project pulsar by yahoo.

the class AdminTest method properties.

@Test
public void properties() throws Throwable {
    Object response = asyncRequests(ctx -> properties.getTenants(ctx));
    assertEquals(response, Lists.newArrayList());
    verify(properties, times(1)).validateSuperUserAccessAsync();
    // create local cluster
    asyncRequests(ctx -> clusters.createCluster(ctx, configClusterName, ClusterDataImpl.builder().build()));
    Set<String> allowedClusters = Sets.newHashSet();
    allowedClusters.add(configClusterName);
    TenantInfoImpl tenantInfo = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "role2")).allowedClusters(allowedClusters).build();
    response = asyncRequests(ctx -> properties.createTenant(ctx, "test-property", tenantInfo));
    verify(properties, times(2)).validateSuperUserAccessAsync();
    response = asyncRequests(ctx -> properties.getTenants(ctx));
    assertEquals(response, Lists.newArrayList("test-property"));
    verify(properties, times(3)).validateSuperUserAccessAsync();
    response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "test-property"));
    assertEquals(response, tenantInfo);
    verify(properties, times(4)).validateSuperUserAccessAsync();
    final TenantInfoImpl newPropertyAdmin = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "other-role")).allowedClusters(allowedClusters).build();
    response = asyncRequests(ctx -> properties.updateTenant(ctx, "test-property", newPropertyAdmin));
    verify(properties, times(5)).validateSuperUserAccessAsync();
    // Wait for updateTenant to take effect
    Thread.sleep(100);
    response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "test-property"));
    assertEquals(response, newPropertyAdmin);
    response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "test-property"));
    assertNotSame(response, tenantInfo);
    verify(properties, times(7)).validateSuperUserAccessAsync();
    // Check creating existing property
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "test-property", tenantInfo));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.CONFLICT.getStatusCode());
    }
    // Check non-existing property
    try {
        response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "non-existing"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    try {
        response = asyncRequests(ctx -> properties.updateTenant(ctx, "xxx-non-existing", newPropertyAdmin));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    // Check deleting non-existing property
    try {
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "non-existing", false));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.NOT_FOUND.getStatusCode());
    }
    // clear caches to load data from metadata-store again
    MetadataCacheImpl<TenantInfo> cache = (MetadataCacheImpl<TenantInfo>) pulsar.getPulsarResources().getTenantResources().getCache();
    AbstractMetadataStore store = (AbstractMetadataStore) cache.getStore();
    cache.invalidateAll();
    store.invalidateAll();
    // Test zk failures
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies");
    });
    try {
        response = asyncRequests(ctx -> properties.getTenants(ctx));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/policies/my-tenant");
    });
    try {
        response = asyncRequests(ctx -> properties.getTenantAdmin(ctx, "my-tenant"));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET && path.equals("/admin/policies/my-tenant");
    });
    try {
        response = asyncRequests(ctx -> properties.updateTenant(ctx, "my-tenant", newPropertyAdmin));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.CREATE && path.equals("/admin/policies/test");
    });
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "test", tenantInfo));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.GET_CHILDREN && path.equals("/admin/policies/test-property");
    });
    try {
        cache.invalidateAll();
        store.invalidateAll();
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "test-property", false));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    response = asyncRequests(ctx -> properties.createTenant(ctx, "error-property", tenantInfo));
    mockZooKeeperGlobal.failConditional(Code.SESSIONEXPIRED, (op, path) -> {
        return op == MockZooKeeper.Op.DELETE && path.equals("/admin/policies/error-property");
    });
    try {
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "error-property", false));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
    response = asyncRequests(ctx -> properties.deleteTenant(ctx, "test-property", false));
    response = asyncRequests(ctx -> properties.deleteTenant(ctx, "error-property", false));
    response = Lists.newArrayList();
    response = asyncRequests(ctx -> properties.getTenants(ctx));
    assertEquals(response, Lists.newArrayList());
    // Create a namespace to test deleting a non-empty property
    TenantInfoImpl newPropertyAdmin2 = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "other-role")).allowedClusters(Sets.newHashSet("use")).build();
    response = asyncRequests(ctx -> properties.createTenant(ctx, "my-tenant", newPropertyAdmin2));
    response = asyncRequests(ctx -> namespaces.createNamespace(ctx, "my-tenant", "use", "my-namespace", BundlesData.builder().build()));
    try {
        response = asyncRequests(ctx -> properties.deleteTenant(ctx, "my-tenant", false));
        fail("should have failed");
    } catch (RestException e) {
    // Ok
    }
    // Check name validation
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "test&", tenantInfo));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check tenantInfo is null
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "tenant-config-is-null", null));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check tenantInfo with empty cluster
    String blankCluster = "";
    Set<String> blankClusters = Sets.newHashSet(blankCluster);
    TenantInfoImpl tenantWithEmptyCluster = TenantInfoImpl.builder().adminRoles(Sets.newHashSet("role1", "role2")).allowedClusters(blankClusters).build();
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "tenant-config-is-empty", tenantWithEmptyCluster));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    // Check tenantInfo contains empty cluster
    Set<String> containBlankClusters = Sets.newHashSet(blankCluster);
    containBlankClusters.add(configClusterName);
    TenantInfoImpl tenantContainEmptyCluster = TenantInfoImpl.builder().adminRoles(Sets.newHashSet()).allowedClusters(containBlankClusters).build();
    try {
        response = asyncRequests(ctx -> properties.createTenant(ctx, "tenant-config-contain-empty", tenantContainEmptyCluster));
        fail("should have failed");
    } catch (RestException e) {
        assertEquals(e.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
    }
    AsyncResponse response2 = mock(AsyncResponse.class);
    namespaces.deleteNamespace(response2, "my-tenant", "use", "my-namespace", false, false);
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    verify(response2, timeout(5000).times(1)).resume(captor.capture());
    assertEquals(captor.getValue().getStatus(), Status.NO_CONTENT.getStatusCode());
    response = asyncRequests(ctx -> properties.deleteTenant(ctx, "my-tenant", false));
}
Also used : ClusterDataImpl(org.apache.pulsar.common.policies.data.ClusterDataImpl) Metrics(org.apache.pulsar.common.stats.Metrics) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) Test(org.testng.annotations.Test) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) BrokerStats(org.apache.pulsar.broker.admin.v1.BrokerStats) AfterMethod(org.testng.annotations.AfterMethod) Namespaces(org.apache.pulsar.broker.admin.v1.Namespaces) AuthenticationDataHttps(org.apache.pulsar.broker.authentication.AuthenticationDataHttps) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) URI(java.net.URI) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) Brokers(org.apache.pulsar.broker.admin.v1.Brokers) PendingBookieOpsStats(org.apache.bookkeeper.mledger.proto.PendingBookieOpsStats) Collection(java.util.Collection) AsyncResponse(javax.ws.rs.container.AsyncResponse) BrokerInfo(org.apache.pulsar.common.policies.data.BrokerInfo) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) PersistentTopics(org.apache.pulsar.broker.admin.v1.PersistentTopics) StreamingOutput(javax.ws.rs.core.StreamingOutput) MockZooKeeper(org.apache.zookeeper.MockZooKeeper) Mockito.doNothing(org.mockito.Mockito.doNothing) Assert.assertNotNull(org.testng.Assert.assertNotNull) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) Sets(com.google.common.collect.Sets) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest) List(java.util.List) SchemasResource(org.apache.pulsar.broker.admin.v2.SchemasResource) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) LeaderBroker(org.apache.pulsar.broker.loadbalance.LeaderBroker) Awaitility(org.awaitility.Awaitility) Mockito.mock(org.mockito.Mockito.mock) Code(org.apache.zookeeper.KeeperException.Code) TopicName(org.apache.pulsar.common.naming.TopicName) NamespaceIsolationDataImpl(org.apache.pulsar.common.policies.data.NamespaceIsolationDataImpl) Properties(org.apache.pulsar.broker.admin.v1.Properties) CommandGetTopicsOfNamespace(org.apache.pulsar.common.api.proto.CommandGetTopicsOfNamespace) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) NamespaceService(org.apache.pulsar.broker.namespace.NamespaceService) Mockito.spy(org.mockito.Mockito.spy) Mockito.timeout(org.mockito.Mockito.timeout) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) Assert.assertNotSame(org.testng.Assert.assertNotSame) Assert(org.testng.Assert) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) Clusters(org.apache.pulsar.broker.admin.v1.Clusters) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) Status(javax.ws.rs.core.Response.Status) AllocatorStats(org.apache.pulsar.common.stats.AllocatorStats) ResourceQuota(org.apache.pulsar.common.policies.data.ResourceQuota) PulsarWebResource(org.apache.pulsar.broker.web.PulsarWebResource) AutoFailoverPolicyType(org.apache.pulsar.common.policies.data.AutoFailoverPolicyType) ErrorData(org.apache.pulsar.common.policies.data.ErrorData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) LocalBrokerData(org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData) Assert.fail(org.testng.Assert.fail) Mockito.times(org.mockito.Mockito.times) Field(java.lang.reflect.Field) ResourceQuotas(org.apache.pulsar.broker.admin.v1.ResourceQuotas) Mockito.verify(org.mockito.Mockito.verify) Policies(org.apache.pulsar.common.policies.data.Policies) Mockito.never(org.mockito.Mockito.never) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) InternalConfigurationData(org.apache.pulsar.common.conf.InternalConfigurationData) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) AutoFailoverPolicyData(org.apache.pulsar.common.policies.data.AutoFailoverPolicyData) AbstractMetadataStore(org.apache.pulsar.metadata.impl.AbstractMetadataStore) RestException(org.apache.pulsar.broker.web.RestException) TenantInfo(org.apache.pulsar.common.policies.data.TenantInfo) MetadataCacheImpl(org.apache.pulsar.metadata.cache.impl.MetadataCacheImpl) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 3 with Properties

use of org.apache.pulsar.broker.admin.v1.Properties in project Lucee by lucee.

the class GetApplicationSettings method call.

public static Struct call(PageContext pc, boolean suppressFunctions) {
    ApplicationContext ac = pc.getApplicationContext();
    Component cfc = null;
    if (ac instanceof ModernApplicationContext)
        cfc = ((ModernApplicationContext) ac).getComponent();
    Struct sct = new StructImpl();
    sct.setEL("applicationTimeout", ac.getApplicationTimeout());
    sct.setEL("clientManagement", Caster.toBoolean(ac.isSetClientManagement()));
    sct.setEL("clientStorage", ac.getClientstorage());
    sct.setEL("sessionStorage", ac.getSessionstorage());
    sct.setEL("customTagPaths", toArray(ac.getCustomTagMappings()));
    sct.setEL("loginStorage", AppListenerUtil.translateLoginStorage(ac.getLoginStorage()));
    sct.setEL(KeyConstants._mappings, toStruct(ac.getMappings()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("scriptProtect", AppListenerUtil.translateScriptProtect(ac.getScriptProtect()));
    sct.setEL("secureJson", Caster.toBoolean(ac.getSecureJson()));
    sct.setEL("typeChecking", Caster.toBoolean(ac.getTypeChecking()));
    sct.setEL("secureJsonPrefix", ac.getSecureJsonPrefix());
    sct.setEL("sessionManagement", Caster.toBoolean(ac.isSetSessionManagement()));
    sct.setEL("sessionTimeout", ac.getSessionTimeout());
    sct.setEL("clientTimeout", ac.getClientTimeout());
    sct.setEL("setClientCookies", Caster.toBoolean(ac.isSetClientCookies()));
    sct.setEL("setDomainCookies", Caster.toBoolean(ac.isSetDomainCookies()));
    sct.setEL(KeyConstants._name, ac.getName());
    sct.setEL("localMode", ac.getLocalMode() == Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS ? Boolean.TRUE : Boolean.FALSE);
    sct.setEL(KeyConstants._locale, LocaleFactory.toString(pc.getLocale()));
    sct.setEL(KeyConstants._timezone, TimeZoneUtil.toString(pc.getTimeZone()));
    // scope cascading
    sct.setEL("scopeCascading", ConfigWebUtil.toScopeCascading(ac.getScopeCascading(), null));
    if (ac.getScopeCascading() != Config.SCOPE_SMALL) {
        sct.setEL("searchImplicitScopes", ac.getScopeCascading() == Config.SCOPE_STANDARD);
    }
    Struct cs = new StructImpl();
    cs.setEL("web", pc.getWebCharset().name());
    cs.setEL("resource", ((PageContextImpl) pc).getResourceCharset().name());
    sct.setEL("charset", cs);
    sct.setEL("sessionType", AppListenerUtil.toSessionType(((PageContextImpl) pc).getSessionType(), "application"));
    // TODO impl
    sct.setEL("serverSideFormValidation", Boolean.FALSE);
    sct.setEL("clientCluster", Caster.toBoolean(ac.getClientCluster()));
    sct.setEL("sessionCluster", Caster.toBoolean(ac.getSessionCluster()));
    sct.setEL("invokeImplicitAccessor", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("triggerDataMember", Caster.toBoolean(ac.getTriggerComponentDataMember()));
    sct.setEL("sameformfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_FORM)));
    sct.setEL("sameurlfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_URL)));
    Object ds = ac.getDefDataSource();
    if (ds instanceof DataSource)
        ds = _call((DataSource) ds);
    else
        ds = Caster.toString(ds, null);
    sct.setEL(KeyConstants._datasource, ds);
    sct.setEL("defaultDatasource", ds);
    Resource src = ac.getSource();
    if (src != null)
        sct.setEL(KeyConstants._source, src.getAbsolutePath());
    // orm
    if (ac.isORMEnabled()) {
        ORMConfiguration conf = ac.getORMConfiguration();
        if (conf != null)
            sct.setEL(KeyConstants._orm, conf.toStruct());
    }
    // s3
    Properties props = ac.getS3();
    if (props != null) {
        sct.setEL(KeyConstants._s3, props.toStruct());
    }
    // ws settings
    {
        Struct wssettings = new StructImpl();
        wssettings.put(KeyConstants._type, AppListenerUtil.toWSType(ac.getWSType(), "Axis1"));
        sct.setEL("wssettings", wssettings);
    }
    // datasources
    Struct _sources = new StructImpl();
    sct.setEL(KeyConstants._datasources, _sources);
    DataSource[] sources = ac.getDataSources();
    if (!ArrayUtil.isEmpty(sources)) {
        for (int i = 0; i < sources.length; i++) {
            _sources.setEL(KeyImpl.init(sources[i].getName()), _call(sources[i]));
        }
    }
    // logs
    Struct _logs = new StructImpl();
    sct.setEL("logs", _logs);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Iterator<Key> it = acs.getLogNames().iterator();
        Key name;
        while (it.hasNext()) {
            name = it.next();
            _logs.setEL(name, acs.getLogMetaData(name.getString()));
        }
    }
    // mails
    Array _mails = new ArrayImpl();
    sct.setEL("mails", _mails);
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Server[] servers = acs.getMailServers();
        Struct s;
        Server srv;
        if (servers != null) {
            for (int i = 0; i < servers.length; i++) {
                srv = servers[i];
                s = new StructImpl();
                _mails.appendEL(s);
                s.setEL(KeyConstants._host, srv.getHostName());
                s.setEL(KeyConstants._port, srv.getPort());
                if (!StringUtil.isEmpty(srv.getUsername()))
                    s.setEL(KeyConstants._username, srv.getUsername());
                if (!StringUtil.isEmpty(srv.getPassword()))
                    s.setEL(KeyConstants._password, srv.getPassword());
                s.setEL(KeyConstants._readonly, srv.isReadOnly());
                s.setEL("ssl", srv.isSSL());
                s.setEL("tls", srv.isTLS());
                if (srv instanceof ServerImpl) {
                    ServerImpl srvi = (ServerImpl) srv;
                    s.setEL("lifeTimespan", TimeSpanImpl.fromMillis(srvi.getLifeTimeSpan()));
                    s.setEL("idleTimespan", TimeSpanImpl.fromMillis(srvi.getIdleTimeSpan()));
                }
            }
        }
    }
    // tag
    Map<Key, Map<Collection.Key, Object>> tags = ac.getTagAttributeDefaultValues(pc);
    if (tags != null) {
        Struct tag = new StructImpl();
        Iterator<Entry<Key, Map<Collection.Key, Object>>> it = tags.entrySet().iterator();
        Entry<Collection.Key, Map<Collection.Key, Object>> e;
        Iterator<Entry<Collection.Key, Object>> iit;
        Entry<Collection.Key, Object> ee;
        Struct tmp;
        // TagLib lib = ((ConfigImpl)pc.getConfig()).getCoreTagLib();
        while (it.hasNext()) {
            e = it.next();
            iit = e.getValue().entrySet().iterator();
            tmp = new StructImpl();
            while (iit.hasNext()) {
                ee = iit.next();
                // lib.getTagByClassName(ee.getKey());
                tmp.setEL(ee.getKey(), ee.getValue());
            }
            tag.setEL(e.getKey(), tmp);
        }
        sct.setEL(KeyConstants._tag, tag);
    }
    // cache
    String fun = ac.getDefaultCacheName(Config.CACHE_TYPE_FUNCTION);
    String obj = ac.getDefaultCacheName(Config.CACHE_TYPE_OBJECT);
    String qry = ac.getDefaultCacheName(Config.CACHE_TYPE_QUERY);
    String res = ac.getDefaultCacheName(Config.CACHE_TYPE_RESOURCE);
    String tmp = ac.getDefaultCacheName(Config.CACHE_TYPE_TEMPLATE);
    String inc = ac.getDefaultCacheName(Config.CACHE_TYPE_INCLUDE);
    String htt = ac.getDefaultCacheName(Config.CACHE_TYPE_HTTP);
    String fil = ac.getDefaultCacheName(Config.CACHE_TYPE_FILE);
    String wse = ac.getDefaultCacheName(Config.CACHE_TYPE_WEBSERVICE);
    // cache connections
    Struct conns = new StructImpl();
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        Key[] names = acs.getCacheConnectionNames();
        for (Key name : names) {
            CacheConnection data = acs.getCacheConnection(name.getString(), null);
            Struct _sct = new StructImpl();
            conns.setEL(name, _sct);
            _sct.setEL(KeyConstants._custom, data.getCustom());
            _sct.setEL(KeyConstants._storage, data.isStorage());
            ClassDefinition cd = data.getClassDefinition();
            if (cd != null) {
                _sct.setEL(KeyConstants._class, cd.getClassName());
                if (!StringUtil.isEmpty(cd.getName()))
                    _sct.setEL(KeyConstants._bundleName, cd.getClassName());
                if (cd.getVersion() != null)
                    _sct.setEL(KeyConstants._bundleVersion, cd.getVersionAsString());
            }
        }
    }
    if (!conns.isEmpty() || fun != null || obj != null || qry != null || res != null || tmp != null || inc != null || htt != null || fil != null || wse != null) {
        Struct cache = new StructImpl();
        sct.setEL(KeyConstants._cache, cache);
        if (fun != null)
            cache.setEL(KeyConstants._function, fun);
        if (obj != null)
            cache.setEL(KeyConstants._object, obj);
        if (qry != null)
            cache.setEL(KeyConstants._query, qry);
        if (res != null)
            cache.setEL(KeyConstants._resource, res);
        if (tmp != null)
            cache.setEL(KeyConstants._template, tmp);
        if (inc != null)
            cache.setEL(KeyConstants._include, inc);
        if (htt != null)
            cache.setEL(KeyConstants._http, htt);
        if (fil != null)
            cache.setEL(KeyConstants._file, fil);
        if (wse != null)
            cache.setEL(KeyConstants._webservice, wse);
        if (conns != null)
            cache.setEL(KeyConstants._connections, conns);
    }
    // java settings
    JavaSettings js = ac.getJavaSettings();
    StructImpl jsSct = new StructImpl();
    jsSct.put("loadCFMLClassPath", js.loadCFMLClassPath());
    jsSct.put("reloadOnChange", js.reloadOnChange());
    jsSct.put("watchInterval", new Double(js.watchInterval()));
    jsSct.put("watchExtensions", ListUtil.arrayToList(js.watchedExtensions(), ","));
    Resource[] reses = js.getResources();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < reses.length; i++) {
        if (i > 0)
            sb.append(',');
        sb.append(reses[i].getAbsolutePath());
    }
    jsSct.put("loadCFMLClassPath", sb.toString());
    sct.put("javaSettings", jsSct);
    if (cfc != null) {
        sct.setEL(KeyConstants._component, cfc.getPageSource().getDisplayPath());
        try {
            ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, cfc);
            Iterator<Key> it = cw.keyIterator();
            Collection.Key key;
            Object value;
            while (it.hasNext()) {
                key = it.next();
                value = cw.get(key);
                if (suppressFunctions && value instanceof UDF)
                    continue;
                if (!sct.containsKey(key))
                    sct.setEL(key, value);
            }
        } catch (PageException e) {
            SystemOut.printDate(e);
        }
    }
    return sct;
}
Also used : Server(lucee.runtime.net.mail.Server) ArrayImpl(lucee.runtime.type.ArrayImpl) Properties(lucee.runtime.net.s3.Properties) ClassDefinition(lucee.runtime.db.ClassDefinition) Struct(lucee.runtime.type.Struct) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) ApplicationContext(lucee.runtime.listener.ApplicationContext) Entry(java.util.Map.Entry) ServerImpl(lucee.runtime.net.mail.ServerImpl) UDF(lucee.runtime.type.UDF) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) Component(lucee.runtime.Component) ORMConfiguration(lucee.runtime.orm.ORMConfiguration) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) PageException(lucee.runtime.exp.PageException) JavaSettings(lucee.runtime.listener.JavaSettings) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) DataSource(lucee.runtime.db.DataSource) Array(lucee.runtime.type.Array) Key(lucee.runtime.type.Collection.Key) StructImpl(lucee.runtime.type.StructImpl) Collection(lucee.runtime.type.Collection) ModernApplicationContext(lucee.runtime.listener.ModernApplicationContext) Map(java.util.Map) CacheConnection(lucee.runtime.cache.CacheConnection) Key(lucee.runtime.type.Collection.Key)

Example 4 with Properties

use of org.apache.pulsar.broker.admin.v1.Properties in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method getAtlasMappingStep.

public Step getAtlasMappingStep(StepDefinition mapping, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
    processPrecedingSteps(precedingSteps);
    processFolowingStep(followingStep);
    List<DataMapperStepDefinition> mappings = mapping.getDataMapperDefinition().get().getDataMapperStepDefinition();
    AtlasMapping atlasMapping = new AtlasMapping();
    atlasMapping.setMappings(new Mappings());
    for (DataSource s : processSources(precedingSteps)) {
        atlasMapping.getDataSource().add(s);
    }
    atlasMapping.setName("REST." + UUID.randomUUID().toString());
    atlasMapping.setLookupTables(new LookupTables());
    atlasMapping.setProperties(new Properties());
    atlasMapping.getDataSource().add(processTarget(followingStep));
    atlasMapping.getMappings().getMapping().addAll(generateBaseMappings(mappings, precedingSteps, followingStep));
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
    String mapperString = null;
    try {
        mapperString = mapper.writeValueAsString(atlasMapping);
        log.debug(mapperString);
    } catch (JsonProcessingException e) {
        log.error("error: {}" + e);
    }
    final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getConnectorDescriptor().get())).id(UUID.randomUUID().toString()).build();
    return mapperStep;
}
Also used : DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTables(io.atlasmap.v2.LookupTables) Step(io.syndesis.common.model.integration.Step) Properties(io.atlasmap.v2.Properties) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 5 with Properties

use of org.apache.pulsar.broker.admin.v1.Properties in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method detectFieldActionParameters.

protected Properties detectFieldActionParameters(String actionClassName) throws ClassNotFoundException {
    Class<?> actionClazz = Class.forName(actionClassName);
    Properties props = null;
    for (Method method : actionClazz.getMethods()) {
        // Find setters to avoid the get / is confusion
        if (method.getParameterCount() == 1 && method.getName().startsWith("set")) {
            // We have a parameter
            if (props == null) {
                props = new Properties();
            }
            Property prop = null;
            for (Parameter param : method.getParameters()) {
                prop = new Property();
                prop.setName(camelize(method.getName().substring("set".length())));
                prop.setFieldType(getConversionService().fieldTypeFromClass(param.getType()));
                props.getProperty().add(prop);
            }
        }
    }
    return props;
}
Also used : Parameter(java.lang.reflect.Parameter) Method(java.lang.reflect.Method) Properties(io.atlasmap.v2.Properties) Property(io.atlasmap.v2.Property)

Aggregations

Properties (io.atlasmap.v2.Properties)7 Property (io.atlasmap.v2.Property)5 Map (java.util.Map)4 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 Field (java.lang.reflect.Field)3 URI (java.net.URI)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 AsyncResponse (javax.ws.rs.container.AsyncResponse)3 Response (javax.ws.rs.core.Response)3 Status (javax.ws.rs.core.Response.Status)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)3 UriInfo (javax.ws.rs.core.UriInfo)3 Properties (lucee.runtime.net.s3.Properties)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)3 PendingBookieOpsStats (org.apache.bookkeeper.mledger.proto.PendingBookieOpsStats)3 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)3