Search in sources :

Example 11 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-kettle by pentaho.

the class MetaStoreTestBase method testFunctionality.

public void testFunctionality(IMetaStore metaStore) throws MetaStoreException {
    if (!metaStore.namespaceExists(namespace)) {
        metaStore.createNamespace(namespace);
    }
    List<String> namespaces = metaStore.getNamespaces();
    assertEquals(1, namespaces.size());
    IMetaStoreElementType elementType = metaStore.newElementType(namespace);
    elementType.setName(SHARED_DIMENSION_NAME);
    elementType.setDescription(SHARED_DIMENSION_DESCRIPTION);
    metaStore.createElementType(namespace, elementType);
    assertNotNull(elementType.getId());
    List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(1, elementTypes.size());
    try {
        metaStore.createElementType(namespace, elementType);
        fail("Duplicate creation error expected!");
    } catch (MetaStoreElementTypeExistsException e) {
    // OK!
    } catch (MetaStoreException e) {
        e.printStackTrace();
        fail("Create exception needs to be MetaStoreDataTypesExistException");
    }
    // 
    try {
        metaStore.deleteNamespace(namespace);
        fail("Expected error while deleting namespace with content!");
    } catch (MetaStoreDependenciesExistsException e) {
        // OK!
        List<String> dependencies = e.getDependencies();
        assertNotNull(dependencies);
        assertEquals(1, dependencies.size());
        assertEquals(elementType.getId(), dependencies.get(0));
    }
    IMetaStoreElement customerDimension = generateCustomerDimensionElement(metaStore, elementType);
    IMetaStoreElementOwner elementOwner = customerDimension.getOwner();
    assertNotNull(elementOwner);
    assertEquals("joe", elementOwner.getName());
    assertEquals(MetaStoreElementOwnerType.USER, elementOwner.getOwnerType());
    metaStore.createElement(namespace, elementType, customerDimension);
    assertNotNull(customerDimension.getId());
    List<IMetaStoreElement> elements = metaStore.getElements(namespace, elementType);
    assertEquals(1, elements.size());
    assertNotNull(elements.get(0));
    assertEquals(CUSTOMER_DIMENSION_NAME, elements.get(0).getName());
    // 
    try {
        metaStore.deleteElementType(namespace, elementType);
        fail("Expected error while deleting data type with content!");
    } catch (MetaStoreDependenciesExistsException e) {
        // OK!
        List<String> dependencies = e.getDependencies();
        assertNotNull(dependencies);
        assertEquals(1, dependencies.size());
        assertEquals(customerDimension.getId(), dependencies.get(0));
    }
    // Some lookup-by-name tests...
    // 
    assertNotNull(metaStore.getElementTypeByName(namespace, SHARED_DIMENSION_NAME));
    assertNotNull(metaStore.getElementByName(namespace, elementType, CUSTOMER_DIMENSION_NAME));
    // Clean up shop!
    // 
    metaStore.deleteElement(namespace, elementType, customerDimension.getId());
    elements = metaStore.getElements(namespace, elementType);
    assertEquals(0, elements.size());
    metaStore.deleteElementType(namespace, elementType);
    elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(0, elementTypes.size());
    metaStore.deleteNamespace(namespace);
    namespaces = metaStore.getNamespaces();
    assertEquals(0, namespaces.size());
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) IMetaStoreElementOwner(org.pentaho.metastore.api.security.IMetaStoreElementOwner) List(java.util.List) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)

Example 12 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method updateElement.

@Override
public synchronized void updateElement(String namespace, IMetaStoreElementType elementType, String elementId, IMetaStoreElement element) throws MetaStoreException {
    // 
    if (elementType.getMetaStoreName() == null || !elementType.getName().equals(getName())) {
        String elementTypeName = elementType.getName();
        elementType = getElementTypeByName(namespace, elementTypeName);
        if (elementType == null) {
            throw new MetaStoreException("The element type '" + elementTypeName + "' could not be found in the meta store in which you are updating.");
        }
    }
    RepositoryFile existingFile = pur.getFileById(elementId);
    if (existingFile == null) {
        throw new MetaStoreException("The element to update with id " + elementId + " could not be found in the store");
    }
    DataNode elementDataNode = new DataNode(PurRepository.checkAndSanitize(element.getName()));
    elementToDataNode(element, elementDataNode);
    RepositoryFile updatedFile = pur.updateFile(existingFile, new NodeRepositoryFileData(elementDataNode), null);
    element.setId(updatedFile.getId().toString());
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 13 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceMetaStoreUtil method getDataServiceByStepName.

public DataServiceMeta getDataServiceByStepName(TransMeta transMeta, String stepName) {
    Set<Integer> cacheKeys = createCacheKeys(transMeta, stepName);
    for (Map.Entry<Integer, String> entry : stepCache.getAll(cacheKeys).entrySet()) {
        String serviceName = entry.getValue();
        if (serviceName.isEmpty()) {
            // Step is marked as not having a Data Service
            return null;
        }
        // Check if Data Service is still valid
        DataServiceMeta dataServiceMeta;
        try {
            dataServiceMeta = getDataService(serviceName, transMeta);
        } catch (MetaStoreException e) {
            dataServiceMeta = null;
        }
        if (dataServiceMeta != null && dataServiceMeta.getStepname().equals(stepName)) {
            return dataServiceMeta;
        } else {
            stepCache.remove(entry.getKey(), serviceName);
        }
    }
    // Look up from embedded metastore
    for (DataServiceMeta dataServiceMeta : getDataServices(transMeta)) {
        if (dataServiceMeta.getStepname().equalsIgnoreCase(stepName)) {
            return dataServiceMeta;
        }
    }
    // Data service not found on step, store negative result in the cache
    stepCache.putAll(Maps.asMap(cacheKeys, Functions.constant("")));
    return null;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 14 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceMetaStoreUtil method removeDataService.

public void removeDataService(DataServiceMeta dataService) {
    TransMeta transMeta = dataService.getServiceTrans();
    try {
        deleteDataServiceElementAndCleanCache(dataService, transMeta);
        transMeta.setChanged();
    } catch (MetaStoreException e) {
        getLogChannel().logBasic(e.getMessage());
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) TransMeta(org.pentaho.di.trans.TransMeta)

Example 15 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceDelegate method suggestEdit.

public void suggestEdit(DataServiceMeta dataServiceMeta, String title, String text) {
    TransMeta serviceTrans = dataServiceMeta.getServiceTrans();
    if (!serviceTrans.hasChanged()) {
        if (showPrompt(title, text)) {
            editDataService(dataServiceMeta);
            serviceTrans.setChanged();
        } else {
            // can not exist duplicate, delete dataService and save transformation (PDI-15584)
            try {
                deleteDataServiceElementAndCleanCache(dataServiceMeta, serviceTrans);
                serviceTrans.setChanged();
            } catch (MetaStoreException e) {
                getLogChannel().logBasic(e.getMessage());
            }
        }
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) TransMeta(org.pentaho.di.trans.TransMeta)

Aggregations

MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)43 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)18 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)18 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)17 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)17 LongObjectId (org.pentaho.di.repository.LongObjectId)12 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)11 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)9 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 StringObjectId (org.pentaho.di.repository.StringObjectId)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ObjectId (org.pentaho.di.repository.ObjectId)5 IMetaStore (org.pentaho.metastore.api.IMetaStore)5 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)4 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)4 List (java.util.List)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 NamedClusterOsgi (org.pentaho.di.core.osgi.api.NamedClusterOsgi)2