Search in sources :

Example 1 with DelegatingMetaStore

use of org.pentaho.metastore.stores.delegate.DelegatingMetaStore in project pentaho-kettle by pentaho.

the class StarDomainMetaStoreUtilTest method testLoadStarDomain.

@Test
public void testLoadStarDomain() throws Exception {
    final String id = "id";
    final String msName = "MSName";
    when(metaStore.getName()).thenReturn(msName);
    final DelegatingMetaStore delegatingMetaStore = spy(new DelegatingMetaStore(metaStore));
    delegatingMetaStore.setActiveMetaStoreName(msName);
    doAnswer(new Answer<IMetaStoreElementType>() {

        @Override
        public IMetaStoreElementType answer(InvocationOnMock invocationOnMock) throws Throwable {
            return metaStore.getElementTypeByName((String) invocationOnMock.getArguments()[0], (String) invocationOnMock.getArguments()[1]);
        }
    }).when(delegatingMetaStore).getElementTypeByName(anyString(), anyString());
    assertNull(StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id));
    final IMetaStoreElement metaStoreElement = mock(IMetaStoreElement.class);
    final String name = "name";
    when(metaStoreElement.getName()).thenReturn(name);
    doReturn(metaStoreElement).when(delegatingMetaStore).getElement(anyString(), eq(metaStoreElementType), eq(id));
    final StarDomain starDomain = StarDomainMetaStoreUtil.loadStarDomain(delegatingMetaStore, id);
    assertEquals(id, starDomain.getObjectId().getId());
    assertEquals(name, starDomain.getName());
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) StarDomain(org.pentaho.di.starmodeler.StarDomain) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Matchers.anyString(org.mockito.Matchers.anyString) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) Test(org.junit.Test)

Example 2 with DelegatingMetaStore

use of org.pentaho.metastore.stores.delegate.DelegatingMetaStore in project pentaho-platform by pentaho.

the class DIServerConfigTest method testGetMetaStoreWithDefault.

@Test
public void testGetMetaStoreWithDefault() throws Exception {
    DIServerConfig diConfig = new DIServerConfig(logChannel, getConfigNode(), pluginRegistry);
    DelegatingMetaStore delegatingMetaStore = diConfig.getMetaStore();
    assertEquals(purMetaStore, delegatingMetaStore.getActiveMetaStore());
    verifyConnection();
}
Also used : DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) Test(org.junit.Test)

Example 3 with DelegatingMetaStore

use of org.pentaho.metastore.stores.delegate.DelegatingMetaStore in project pentaho-kettle by pentaho.

the class Kitchen method main.

public static void main(String[] a) throws Exception {
    final ExecutorService executor = ExecutorUtil.getExecutor();
    final RepositoryPluginType repositoryPluginType = RepositoryPluginType.getInstance();
    final Future<Map.Entry<KettlePluginException, Future<KettleException>>> repositoryRegisterFuture = executor.submit(new Callable<Map.Entry<KettlePluginException, Future<KettleException>>>() {

        @Override
        public Map.Entry<KettlePluginException, Future<KettleException>> call() throws Exception {
            PluginRegistry.addPluginType(repositoryPluginType);
            try {
                KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
                KettleClientEnvironment.init();
            } catch (KettlePluginException e) {
                return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(e, null);
            }
            Future<KettleException> kettleEnvironmentInitFuture = executor.submit(new Callable<KettleException>() {

                @Override
                public KettleException call() throws Exception {
                    try {
                        KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
                        KettleEnvironment.init();
                    } catch (KettleException e) {
                        return e;
                    }
                    return null;
                }
            });
            return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(null, kettleEnvironmentInitFuture);
        }
    });
    List<String> args = new ArrayList<String>();
    for (int i = 0; i < a.length; i++) {
        if (a[i].length() > 0) {
            args.add(a[i]);
        }
    }
    DelegatingMetaStore metaStore = new DelegatingMetaStore();
    metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
    metaStore.setActiveMetaStoreName(metaStore.getName());
    RepositoryMeta repositoryMeta = null;
    Job job = null;
    StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionJobname, optionDirname, initialDir;
    StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
    StringBuilder optionListjobs, optionListrep, optionNorep, optionVersion, optionListParam, optionExport;
    NamedParams optionParams = new NamedParamsDefault();
    NamedParams customOptions = new NamedParamsDefault();
    CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogLines"), new StringBuilder());
    CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogTimeout"), new StringBuilder());
    CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Kitchen.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("job", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepJobName"), optionJobname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Kitchen.CmdLine.XMLJob"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFileOld"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListDir"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listjobs", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListJobsDir"), optionListjobs = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListAvailableReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Kitchen.CmdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Kitchen.CmdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("param", BaseMessages.getString(PKG, "Kitchen.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Kitchen.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("export", BaseMessages.getString(PKG, "Kitchen.ComdLine.Export"), optionExport = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("custom", BaseMessages.getString(PKG, "Kitchen.ComdLine.Custom"), customOptions, false), maxLogLinesOption, maxLogTimeoutOption };
    if (args.size() == 2) {
        // 2 internal hidden argument (flag and value)
        CommandLineOption.printUsage(options);
        exitJVM(9);
    }
    LogChannelInterface log = new LogChannel(STRING_KITCHEN);
    CommandLineOption.parseArguments(args, options, log);
    configureLogging(maxLogLinesOption, maxLogTimeoutOption);
    String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
    String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
    String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
    if (!Utils.isEmpty(kettleRepname)) {
        optionRepname = new StringBuilder(kettleRepname);
    }
    if (!Utils.isEmpty(kettleUsername)) {
        optionUsername = new StringBuilder(kettleUsername);
    }
    if (!Utils.isEmpty(kettlePassword)) {
        optionPassword = new StringBuilder(kettlePassword);
    }
    if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
        // if the old style of logging name is filled in, and the new one is not
        // overwrite the new by the old
        optionLogfile = optionLogfileOld;
    }
    Map.Entry<KettlePluginException, Future<KettleException>> repositoryRegisterResults = repositoryRegisterFuture.get();
    // It's a singleton map with one key-value pair (a Pair collection)
    KettlePluginException repositoryRegisterException = repositoryRegisterResults.getKey();
    if (repositoryRegisterException != null) {
        throw repositoryRegisterException;
    }
    Future<KettleException> kettleInitFuture = repositoryRegisterResults.getValue();
    if (!Utils.isEmpty(optionLogfile)) {
        fileAppender = new FileLoggingEventListener(optionLogfile.toString(), true);
        KettleLogStore.getAppender().addLoggingEventListener(fileAppender);
    } else {
        fileAppender = null;
    }
    if (!Utils.isEmpty(optionLoglevel)) {
        log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
        log.logMinimal(BaseMessages.getString(PKG, "Kitchen.Log.LogLevel", log.getLogLevel().getDescription()));
    }
    // Start the action...
    // 
    int returnCode = CommandExecutorCodes.Kitchen.SUCCESS.getCode();
    try {
        if (getCommandExecutor() == null) {
            // init
            setCommandExecutor(new KitchenCommandExecutor(PKG, log, kettleInitFuture));
        }
        if (!Utils.isEmpty(optionVersion)) {
            getCommandExecutor().printVersion();
            if (a.length == 1) {
                exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
            }
        }
        returnCode = getCommandExecutor().execute(optionRepname.toString(), optionNorep.toString(), optionUsername.toString(), optionTrustUser.toString(), optionPassword.toString(), optionDirname.toString(), optionFilename.toString(), optionJobname.toString(), optionListjobs.toString(), optionListdir.toString(), optionExport.toString(), initialDir.toString(), optionListrep.toString(), optionListParam.toString(), optionParams, customOptions, args.toArray(new String[args.size()]));
    } catch (Throwable t) {
        t.printStackTrace();
        returnCode = CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode();
    } finally {
        if (fileAppender != null) {
            fileAppender.close();
            KettleLogStore.getAppender().removeLoggingEventListener(fileAppender);
        }
    }
    exitJVM(returnCode);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) NamedParams(org.pentaho.di.core.parameters.NamedParams) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) AbstractMap(java.util.AbstractMap) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) CommandLineOption(org.pentaho.di.pan.CommandLineOption) Job(org.pentaho.di.job.Job) NamedParamsDefault(org.pentaho.di.core.parameters.NamedParamsDefault) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) FileLoggingEventListener(org.pentaho.di.core.logging.FileLoggingEventListener) LogChannel(org.pentaho.di.core.logging.LogChannel) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) ExecutionException(java.util.concurrent.ExecutionException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 4 with DelegatingMetaStore

use of org.pentaho.metastore.stores.delegate.DelegatingMetaStore in project pentaho-kettle by pentaho.

the class AbstractBaseCommandExecutor method createDefaultMetastore.

public DelegatingMetaStore createDefaultMetastore() throws MetaStoreException {
    DelegatingMetaStore metaStore = new DelegatingMetaStore();
    metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
    metaStore.setActiveMetaStoreName(metaStore.getName());
    return metaStore;
}
Also used : DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore)

Example 5 with DelegatingMetaStore

use of org.pentaho.metastore.stores.delegate.DelegatingMetaStore in project pentaho-kettle by pentaho.

the class SpoonTest method prepareSetSaveTests.

private static void prepareSetSaveTests(Spoon spoon, LogChannelInterface log, SpoonPerspective spoonPerspective, AbstractMeta metaData, boolean repIsNull, boolean basicLevel, String perspectiveID, boolean saveToRepository, boolean saveXMLFile, String fileType, String filename, boolean objectIdIsNull, boolean canSave) throws Exception {
    TabMapEntry mockTabMapEntry = mock(TabMapEntry.class);
    TabItem mockTabItem = mock(TabItem.class);
    Repository mockRepository = mock(Repository.class);
    DelegatingMetaStore mockMetaStore = mock(DelegatingMetaStore.class);
    spoon.rep = repIsNull ? null : mockRepository;
    spoon.metaStore = mockMetaStore;
    spoon.delegates = mock(SpoonDelegates.class);
    spoon.delegates.tabs = mock(SpoonTabsDelegate.class);
    spoon.props = mock(PropsUI.class);
    doReturn(perspectiveID).when(spoonPerspective).getId();
    doReturn(basicLevel).when(log).isBasic();
    doReturn(basicLevel).when(log).isDetailed();
    doReturn(mockTabMapEntry).when(spoon.delegates.tabs).findTabMapEntry(any());
    doReturn(mockTabItem).when(mockTabMapEntry).getTabItem();
    doReturn(saveToRepository).when(spoon).saveToRepository(metaData, true);
    doReturn(saveXMLFile).when(spoon).saveXMLFile(metaData, false);
    if (objectIdIsNull) {
        doReturn(null).when(metaData).getObjectId();
    } else {
        doReturn(new ObjectId() {

            @Override
            public String getId() {
                return "objectId";
            }
        }).when(metaData).getObjectId();
    }
    // saveFile
    doReturn(filename).when(metaData).getFilename();
    doReturn(canSave).when(metaData).canSave();
    doReturn(false).when(spoon.props).useDBCache();
    doReturn(saveToRepository).when(spoon).saveToRepository(metaData);
    doReturn(saveXMLFile).when(spoon).save(metaData, filename, false);
    doReturn(fileType).when(metaData).getFileType();
}
Also used : TabItem(org.pentaho.xul.swt.tab.TabItem) Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) DelegatingMetaStore(org.pentaho.metastore.stores.delegate.DelegatingMetaStore) Matchers.anyString(org.mockito.Matchers.anyString) SpoonDelegates(org.pentaho.di.ui.spoon.delegates.SpoonDelegates) SpoonTabsDelegate(org.pentaho.di.ui.spoon.delegates.SpoonTabsDelegate) PropsUI(org.pentaho.di.ui.core.PropsUI)

Aggregations

DelegatingMetaStore (org.pentaho.metastore.stores.delegate.DelegatingMetaStore)7 Test (org.junit.Test)3 Repository (org.pentaho.di.repository.Repository)3 Matchers.anyString (org.mockito.Matchers.anyString)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)2 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)1 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)1 FileLoggingEventListener (org.pentaho.di.core.logging.FileLoggingEventListener)1 LogChannel (org.pentaho.di.core.logging.LogChannel)1 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)1