Architecting, installing and maintaining your SAS environment

Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Hi, 

 

This was originally posted here

 

In SAS Open Metadata reference (page 126), it says: The UpdateMetadata method enables you to update the properties of existing metadata objects. It returns an error if the metadata object to be updated does not exist, unless the OMI_IGNORE_NOTFOUND (134217728) flag is set.

Here is my problem, if I specify the flag or I don't specify the flag, I still get the same error: ("SASLibrary : A5X8AHW1.B40000SQ cannot be found in the wlibrary container in the Foundation repository.")

Here is a snippet that reproduces the error:

 

import com.sas.meta.SASOMI.IOMI;
import com.sas.metadata.MetadataUtil;
import org.omg.CORBA.StringHolder;

IOMI iOMI = ... // an instance of IOMI connection

StringHolder outputMeta = new StringHolder();

String request = ""
        + "<UpdateMetadata>"
        + "   <Metadata>"
        + "     <SASLibrary Id=\"A5X8AHW1.B40000SQ\"/>"
        + "   </Metadata>"
        + "   <NS>SAS</NS>"
        + "   <Flags>" + (MetadataUtil.OMI_IGNORE_NOTFOUND | MetadataUtil.OMI_TRUSTED_CLIENT | MetadataUtil.OMI_RETURN_LIST) + "</Flags>"
        + "   <Options/>"
        + "</UpdateMetadata>"
        ;

iOMI.DoRequest(request, outputMeta);

Any ideas what is going wrong? 

 

Regards,

Vasilij

=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk

Accepted Solutions
Solution
‎07-12-2017 01:50 AM
Trusted Advisor
Posts: 1,301

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Posted in reply to VasilijNevlev

OMI_IGNORE_NOTFOUND with the UpdateMetadata method only ignores objects notfound within the bounds of a remove function.

 

 

proc metadata
in='<UpdateMetadata>
      <Metadata>
        <Index Id="A5UL0H0J.BR000001" Name="foobaridx" Desc="A Index Description">
          <Columns Function="Remove">
            <Column Id="A5UL0H0J.BG0001ND" Name="Sex"/><!-- exists -->
            <Column Id="A5UL0H0J.B0000001" Name="Foo"/><!-- not exists -->
          </Columns>
        </Index>
      </Metadata>
      <NS>SAS</NS>
      <!-- OMI_TRUSTED_CLIENT -->
      <Flags>268435456</Flags>
      <Options/>
    </UpdateMetadata>';
run;
ERROR: Subelement Column : A5UL0H0J.B0000001 cannot be removed from Index : A5UL0H0J.BR000001.
NOTE: PROCEDURE METADATA used (Total process time):
real time 0.07 seconds
cpu time 0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
proc metadata
in='<UpdateMetadata>
      <Metadata>
        <Index Id="A5UL0H0J.BR000001" Name="foobaridx" Desc="A Index Description">
          <Columns Function="Remove">
            <Column Id="A5UL0H0J.BG0001ND" Name="Sex"/><!-- exists -->
            <Column Id="A5UL0H0J.B0000001" Name="Foo"/><!-- not exists -->
          </Columns>
        </Index>
      </Metadata>
      <NS>SAS</NS>
      <!-- OMI_TRUSTED_CLIENT + OMI_IGNORE_NOTFOUND -->
      <Flags>402653184</Flags>
      <Options/>
    </UpdateMetadata>';
run;
NOTE: Response XML:

<UpdateMetadata><Metadata><Index Id="A5UL0H0J.BR000001" Name="foobaridx" Desc="A Index Description"><Columns 
Function="Remove"><Column Id="A5UL0H0J.BG0001NG" Name="Sex"/><Column Id="A5UL0H0J.B0000001" 
Name="Foo"/></Columns></Index></Metadata><NS>SAS</NS><Flags>402653184</Flags><Options/></UpdateMetadata>


NOTE: PROCEDURE METADATA used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

 

 

 

View solution in original post


All Replies
SAS Super FREQ
Posts: 299

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Posted in reply to VasilijNevlev

Hi,

 

does the metadata object "A5X8AHW1.B40000SQ" exist? You can use the following code to find out the

correct ID:

 

proc metadata
     in='<GetMetadataObjects>
      <Reposid>$METAREPOSITORY</Reposid>
         <Type>SASLibrary</Type>
         <Ns>SAS</Ns>
         <Flags>1</Flags>
         <Options/>
         </GetMetadataObjects>';
run;

 

Thanks

Anja

Contributor
Posts: 39

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Hello Anja, 

 

Thank you for the comment. The object ID is correct. It existed, but was deleted. This is just a test code to validate why there is error about an object not found with the flag OMI_IGNORE_NOTFOUND present. 

 

Regards,

Vasilij

=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk
Solution
‎07-12-2017 01:50 AM
Trusted Advisor
Posts: 1,301

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Posted in reply to VasilijNevlev

OMI_IGNORE_NOTFOUND with the UpdateMetadata method only ignores objects notfound within the bounds of a remove function.

 

 

proc metadata
in='<UpdateMetadata>
      <Metadata>
        <Index Id="A5UL0H0J.BR000001" Name="foobaridx" Desc="A Index Description">
          <Columns Function="Remove">
            <Column Id="A5UL0H0J.BG0001ND" Name="Sex"/><!-- exists -->
            <Column Id="A5UL0H0J.B0000001" Name="Foo"/><!-- not exists -->
          </Columns>
        </Index>
      </Metadata>
      <NS>SAS</NS>
      <!-- OMI_TRUSTED_CLIENT -->
      <Flags>268435456</Flags>
      <Options/>
    </UpdateMetadata>';
run;
ERROR: Subelement Column : A5UL0H0J.B0000001 cannot be removed from Index : A5UL0H0J.BR000001.
NOTE: PROCEDURE METADATA used (Total process time):
real time 0.07 seconds
cpu time 0.00 seconds

NOTE: The SAS System stopped processing this step because of errors.
proc metadata
in='<UpdateMetadata>
      <Metadata>
        <Index Id="A5UL0H0J.BR000001" Name="foobaridx" Desc="A Index Description">
          <Columns Function="Remove">
            <Column Id="A5UL0H0J.BG0001ND" Name="Sex"/><!-- exists -->
            <Column Id="A5UL0H0J.B0000001" Name="Foo"/><!-- not exists -->
          </Columns>
        </Index>
      </Metadata>
      <NS>SAS</NS>
      <!-- OMI_TRUSTED_CLIENT + OMI_IGNORE_NOTFOUND -->
      <Flags>402653184</Flags>
      <Options/>
    </UpdateMetadata>';
run;
NOTE: Response XML:

<UpdateMetadata><Metadata><Index Id="A5UL0H0J.BR000001" Name="foobaridx" Desc="A Index Description"><Columns 
Function="Remove"><Column Id="A5UL0H0J.BG0001NG" Name="Sex"/><Column Id="A5UL0H0J.B0000001" 
Name="Foo"/></Columns></Index></Metadata><NS>SAS</NS><Flags>402653184</Flags><Options/></UpdateMetadata>


NOTE: PROCEDURE METADATA used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

 

 

 

Contributor
Posts: 39

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

FriedEgg,

Thank you, it seems the documentation is not very clear on the scope of the flag.

Regards,
Vasilij
=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk
Trusted Advisor
Posts: 1,301

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

Posted in reply to VasilijNevlev

Since the OP was about the java version of the interface, and I don't get to use it much lately, here is a full example of a class to test the update vs delete metadata requests with OMI_IGNORE_NOTFOUND

 

import com.sas.metadata.remote.*;
import org.apache.log4j.Logger;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.util.Properties;

import static org.apache.log4j.Logger.*;

public class MdExample {

    final static Logger logger = getLogger(MdExample.class);

    private MdFactory _factory = null;
    private String serverName = null;
    private String serverPort = null;
    private String serverUser = null;
    private String serverPass = null;
    private  boolean serverLog = false;

    public MdExample() {
        getProperties();
        initializeFactory();
    }

    private void getProperties() {
        Properties prop = new Properties();
        InputStream input = null;

        try {
            input = new FileInputStream("config.properties");

            prop.load(input);

            serverName = prop.getProperty("serverName", "localhost");
            serverPort = prop.getProperty("serverPort", "8561");
            serverUser = prop.getProperty("serverUser");
            serverPass = prop.getProperty("serverPass");
            serverLog = Boolean.parseBoolean(prop.getProperty("serverLog", "false"));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private void initializeFactory() {
        try
        {
            _factory = new MdFactoryImpl(false);
            boolean debug = false;
            if (logger.isDebugEnabled()) {
                debug = true;
            }

            _factory.setDebug(debug);
            _factory.setLoggingEnabled(serverLog);
            _factory.getUtil().setOutputStream(System.out);
            _factory.getUtil().setLogStream(System.out);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public boolean connectToServer() {
        try
        {
            MdOMRConnection connection = _factory.getConnection();

            connection.makeOMRConnection(
                    serverName,
                    serverPort,
                    serverUser,
                    serverPass
            );
        } catch (MdException e) {
            Throwable t = e.getCause();
            if (t != null)
            {
                String ErrorType = e.getSASMessageSeverity();
                String ErrorMsg = e.getSASMessage();
                if (ErrorType != null)
                {
                    System.out.println(ErrorType + ": " + ErrorMsg);
                }
                if (t instanceof org.omg.CORBA.COMM_FAILURE)
                {
                    System.out.println(e.getLocalizedMessage());
                }
            }
            else
            {
                System.out.println(e.getLocalizedMessage());
            }
            e.printStackTrace();;
            return false;
        } catch (RemoteException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public String getFoundationRepository() {
        try
        {
            MdOMIUtil omiUtil = _factory.getOMIUtil();
            return omiUtil.getFoundationReposID();
        } catch (MdException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return null;
    }

    public boolean doesObjectExist(String reposID, String type, String xmlSelect) {
        try
        {
            MdOMIUtil omiUtil = _factory.getOMIUtil();
            int mdObjectCount = omiUtil.doesObjectExist(reposID,type,xmlSelect);
            logger.debug("Sent to Metadata Server:\n"
                    + "<GetMetadataObjects>\n"
                    + "  <ReposId>" + reposID + "</ReposId>\n"
                    + "  <Type>" + type + "</Type>\n"
                    + "  <Objects/>\n"
                    + "  <NS>SAS</NS>\n"
                    + "  <!-- OMI_XMLSELECT -->\n"
                    + "  <Flags>" + MdOMIUtil.OMI_XMLSELECT + "</Flags>\n"
                    + "  <Options>\n"
                    + "    " + xmlSelect + "\n"
                    + "  </Options>\n"
                    + "</GetMetadataObjects>");
            logger.debug("Response: " + mdObjectCount);
            return mdObjectCount > 0;
        } catch (MdException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return false;
    }

    public void DoRequest(String xml) {
        try
        {
            MdOMIUtil omiUtil = _factory.getOMIUtil();
            omiUtil.DoRequestNoReturn(xml,true);
        } catch (MdException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        MdExample util = new MdExample();

        boolean connected = util.connectToServer();

        if (connected) {
            System.out.println("Connected...");
        }
        else
        {
            System.out.println("Error Connecting...");
            return;
        }

        String foundationFQID = util.getFoundationRepository();

        String id = foundationFQID.split("\\.")[1] + ".Z0000001";
        boolean idExists = util.doesObjectExist(foundationFQID,"SASLibrary","<XMLSELECT search=\"SASLibrary[@Id='" + id + "']\"/>");

        int flags = (MdOMIUtil.OMI_TRUSTED_CLIENT | MdOMIUtil.OMI_IGNORE_NOTFOUND);

        String request = ""
                + "<UpdateMetadata>"
                + "  <Metadata>"
                + "    <SASLibrary Id='" + id + "' Name='Foobar'/>"
                + "  </Metadata>"
                + "  <NS>SAS</NS>"
                + "  <Flags>" + flags + "</Flags>"
                + "  <Options/>"
                + "</UpdateMetadata>"
                ;

        System.out.println("UpdateMetadata will produce a GenericError Exception");
        util.DoRequest(request);

        System.out.println("DeleteMetadata will not produce a Exception");
        util.DoRequest(request.replace("Update","Delete"));
    }
}

 

 

 

Connected...
[main][DEBUG MdExample] - Sent to Metadata Server:
<GetMetadataObjects>
  <ReposId>A0000001.A5UL0H0J</ReposId>
  <Type>SASLibrary</Type>
  <Objects/>
  <NS>SAS</NS>
  <!-- OMI_XMLSELECT -->
  <Flags>128</Flags>
  <Options>
    <XMLSELECT search="SASLibrary[@Id='A5UL0H0J.Z0000001']"/>
  </Options>
</GetMetadataObjects>
[main][DEBUG MdExample] - Response: 0
UpdateMetadata will produce a GenericError Exception
com.sas.iom.SASIOMDefs.GenericError: SASLibrary : A5UL0H0J.Z0000001 cannot be found in the wlibrary container in the REPOSMGR repository.
	at com.sas.iom.SASIOMDefs.GenericErrorHelper.read(GenericErrorHelper.java:22)
	at com.sas.iom.SASIOMDefs.GenericErrorHelper.extract(GenericErrorHelper.java:47)
	at com.sas.meta.SASOMI._portable_stub_IOMI.DoRequest(_portable_stub_IOMI.java:581)
	at com.sas.metadata.remote.MdOMIWrapperImpl.DoRequest(MdOMIWrapperImpl.java:742)
	at com.sas.metadata.remote.MdOMIUtilImpl.DoRequestNoReturn(MdOMIUtilImpl.java:2639)
	at MdExample.DoRequest(MdExample.java:157)
	at MdExample.main(MdExample.java:198)
        ...
DeleteMetadata will not produce a Exception

Process finished with exit code 0

 

 

Contributor
Posts: 39

Re: Use of OMI_IGNORE_NOTFOUND flag in SAS OpenMetadata interface (SAS 9.4)

That's great, thank you!
=======================================
For more information about {An}alytium, visit https://www.analytium.co.uk
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 281 views
  • 2 likes
  • 3 in conversation